Versions in this module Expand all Collapse all v0 v0.6.2 Mar 27, 2026 Changes in this version + func AsContentType[T Content](content Content) (T, bool) + func AsMessagePart[T MessagePart](content MessagePart) (T, bool) + func AsToolResultOutputType[T ToolResultOutputContent](content ToolResultOutputContent) (T, bool) + func ErrorTitleForStatusCode(statusCode int) string + func IsNoObjectGeneratedError(err error) bool + func MarshalProviderType[T any](typeID string, data T) ([]byte, error) + func Opt[T any](v T) *T + func ParseOptions[T any](options map[string]any, m *T) error + func RegisterProviderType(typeID string, unmarshalFn UnmarshalFunc) + func UnmarshalProviderType[T any](data []byte, target *T) error + type Agent interface + Generate func(context.Context, AgentCall) (*AgentResult, error) + Stream func(context.Context, AgentStreamCall) (*AgentResult, error) + func NewAgent(model LanguageModel, opts ...AgentOption) Agent + type AgentCall struct + ActiveTools []string + Files []FilePart + FrequencyPenalty *float64 + MaxOutputTokens *int64 + MaxRetries *int + Messages []Message + OnRetry OnRetryCallback + PrepareStep PrepareStepFunction + PresencePenalty *float64 + Prompt string + ProviderOptions ProviderOptions + RepairToolCall RepairToolCallFunction + StopWhen []StopCondition + Temperature *float64 + TopK *int64 + TopP *float64 + type AgentOption = func(*agentSettings) + func WithFrequencyPenalty(penalty float64) AgentOption + func WithHeaders(headers map[string]string) AgentOption + func WithMaxOutputTokens(tokens int64) AgentOption + func WithMaxRetries(maxRetries int) AgentOption + func WithOnRetry(callback OnRetryCallback) AgentOption + func WithPrepareStep(fn PrepareStepFunction) AgentOption + func WithPresencePenalty(penalty float64) AgentOption + func WithProviderOptions(providerOptions ProviderOptions) AgentOption + func WithRepairToolCall(fn RepairToolCallFunction) AgentOption + func WithStopConditions(conditions ...StopCondition) AgentOption + func WithSystemPrompt(prompt string) AgentOption + func WithTemperature(temp float64) AgentOption + func WithTools(tools ...AgentTool) AgentOption + func WithTopK(topK int64) AgentOption + func WithTopP(topP float64) AgentOption + type AgentResult struct + Response Response + Steps []StepResult + TotalUsage Usage + type AgentStreamCall struct + ActiveTools []string + Files []FilePart + FrequencyPenalty *float64 + Headers map[string]string + MaxOutputTokens *int64 + MaxRetries *int + Messages []Message + OnAgentFinish OnAgentFinishFunc + OnAgentStart OnAgentStartFunc + OnChunk OnChunkFunc + OnError OnErrorFunc + OnFinish OnFinishFunc + OnReasoningDelta OnReasoningDeltaFunc + OnReasoningEnd OnReasoningEndFunc + OnReasoningStart OnReasoningStartFunc + OnRetry OnRetryCallback + OnSource OnSourceFunc + OnStepFinish OnStepFinishFunc + OnStepStart OnStepStartFunc + OnStreamFinish OnStreamFinishFunc + OnTextDelta OnTextDeltaFunc + OnTextEnd OnTextEndFunc + OnTextStart OnTextStartFunc + OnToolCall OnToolCallFunc + OnToolInputDelta OnToolInputDeltaFunc + OnToolInputEnd OnToolInputEndFunc + OnToolInputStart OnToolInputStartFunc + OnToolResult OnToolResultFunc + OnWarnings OnWarningsFunc + PrepareStep PrepareStepFunction + PresencePenalty *float64 + Prompt string + ProviderOptions ProviderOptions + RepairToolCall RepairToolCallFunction + StopWhen []StopCondition + Temperature *float64 + TopK *int64 + TopP *float64 + type AgentTool interface + Info func() ToolInfo + ProviderOptions func() ProviderOptions + Run func(ctx context.Context, params ToolCall) (ToolResponse, error) + SetProviderOptions func(opts ProviderOptions) + ToTool func() Tool + func NewAgentTool[TInput any](name string, description string, ...) AgentTool + func NewFileSearchTool(name string) AgentTool + func NewParallelAgentTool[TInput any](name string, description string, ...) AgentTool + type Call struct + FrequencyPenalty *float64 + MaxOutputTokens *int64 + PresencePenalty *float64 + Prompt Prompt + ProviderOptions ProviderOptions + Temperature *float64 + ToolChoice *ToolChoice + Tools []Tool + TopK *int64 + TopP *float64 + func (c *Call) UnmarshalJSON(data []byte) error + type CallWarning struct + Details string + Message string + Setting string + Tool Tool + Type CallWarningType + type CallWarningType string + const CallWarningTypeOther + const CallWarningTypeUnsupportedSetting + const CallWarningTypeUnsupportedTool + type Content interface + GetType func() ContentType + func UnmarshalContent(data []byte) (Content, error) + type ContentType string + const ContentTypeFile + const ContentTypeReasoning + const ContentTypeSource + const ContentTypeText + const ContentTypeToolCall + const ContentTypeToolResult + type Error struct + Cause error + Message string + Title string + func (err *Error) Error() string + func (err Error) Unwrap() error + type FileContent struct + Data []byte + MediaType string + ProviderMetadata ProviderMetadata + func (f *FileContent) UnmarshalJSON(data []byte) error + func (f FileContent) GetType() ContentType + func (f FileContent) MarshalJSON() ([]byte, error) + type FilePart struct + Data []byte + Filename string + MediaType string + ProviderOptions ProviderOptions + URI string + func (f *FilePart) UnmarshalJSON(data []byte) error + func (f FilePart) GetType() ContentType + func (f FilePart) MarshalJSON() ([]byte, error) + func (f FilePart) Options() ProviderOptions + type FileSearchAgentTool struct + func (t *FileSearchAgentTool) Info() ToolInfo + func (t *FileSearchAgentTool) ProviderOptions() ProviderOptions + func (t *FileSearchAgentTool) Run(ctx context.Context, params ToolCall) (ToolResponse, error) + func (t *FileSearchAgentTool) SetProviderOptions(opts ProviderOptions) + func (t *FileSearchAgentTool) ToTool() Tool + type FileSearchTool struct + Name string + func (f FileSearchTool) GetName() string + func (f FileSearchTool) GetType() ToolType + type FinishReason string + const FinishReasonContentFilter + const FinishReasonError + const FinishReasonLength + const FinishReasonOther + const FinishReasonStop + const FinishReasonToolCalls + const FinishReasonUnknown + type FunctionTool struct + Description string + InputSchema map[string]any + Name string + ProviderOptions ProviderOptions + func (f *FunctionTool) UnmarshalJSON(data []byte) error + func (f FunctionTool) GetName() string + func (f FunctionTool) GetType() ToolType + func (f FunctionTool) MarshalJSON() ([]byte, error) + type LanguageModel interface + Generate func(context.Context, Call) (*Response, error) + GenerateObject func(context.Context, ObjectCall) (*ObjectResponse, error) + Model func() string + Provider func() string + Stream func(context.Context, Call) (StreamResponse, error) + StreamObject func(context.Context, ObjectCall) (ObjectStreamResponse, error) + type Message struct + Content []MessagePart + ProviderOptions ProviderOptions + Role MessageRole + func NewSystemMessage(prompt ...string) Message + func NewUserMessage(prompt string, files ...FilePart) Message + func (m *Message) UnmarshalJSON(data []byte) error + type MessagePart interface + GetType func() ContentType + Options func() ProviderOptions + func UnmarshalMessagePart(data []byte) (MessagePart, error) + type MessageRole string + const MessageRoleAssistant + const MessageRoleSystem + const MessageRoleTool + const MessageRoleUser + type NoObjectGeneratedError struct + FinishReason FinishReason + ParseError error + RawText string + Usage Usage + ValidationError error + func (e *NoObjectGeneratedError) Error() string + type ObjectCall struct + FrequencyPenalty *float64 + MaxOutputTokens *int64 + PresencePenalty *float64 + Prompt Prompt + ProviderOptions ProviderOptions + RepairText schema.ObjectRepairFunc + Schema Schema + SchemaDescription string + SchemaName string + Temperature *float64 + TopK *int64 + TopP *float64 + type ObjectMode string + const ObjectModeAuto + const ObjectModeJSON + const ObjectModeText + const ObjectModeTool + type ObjectResponse struct + FinishReason FinishReason + Object any + ProviderMetadata ProviderMetadata + RawText string + Usage Usage + Warnings []CallWarning + type ObjectResult struct + FinishReason FinishReason + Object T + ProviderMetadata ProviderMetadata + RawText string + Usage Usage + Warnings []CallWarning + type ObjectStreamPart struct + Delta string + Error error + FinishReason FinishReason + Object any + ProviderMetadata ProviderMetadata + Type ObjectStreamPartType + Usage Usage + Warnings []CallWarning + type ObjectStreamPartType string + const ObjectStreamPartTypeError + const ObjectStreamPartTypeFinish + const ObjectStreamPartTypeObject + const ObjectStreamPartTypeTextDelta + type ObjectStreamResponse = iter.Seq[ObjectStreamPart] + type OnAgentFinishFunc func(result *AgentResult) error + type OnAgentStartFunc func() + type OnChunkFunc func(StreamPart) error + type OnErrorFunc func(error) + type OnFinishFunc func(result *AgentResult) + type OnReasoningDeltaFunc func(id, text string) error + type OnReasoningEndFunc func(id string, reasoning ReasoningContent) error + type OnReasoningStartFunc func(id string, reasoning ReasoningContent) error + type OnRetryCallback = func(err *ProviderError, delay time.Duration) + type OnSourceFunc func(source SourceContent) error + type OnStepFinishFunc func(stepResult StepResult) error + type OnStepFinishedFunction = func(step StepResult) + type OnStepStartFunc func(stepNumber int) error + type OnStreamFinishFunc func(usage Usage, finishReason FinishReason, providerMetadata ProviderMetadata) error + type OnTextDeltaFunc func(id, text string) error + type OnTextEndFunc func(id string) error + type OnTextStartFunc func(id string) error + type OnToolCallFunc func(toolCall ToolCallContent) error + type OnToolInputDeltaFunc func(id, delta string) error + type OnToolInputEndFunc func(id string) error + type OnToolInputStartFunc func(id, toolName string) error + type OnToolResultFunc func(result ToolResultContent) error + type OnWarningsFunc func(warnings []CallWarning) error + type PrepareStepFunction = func(ctx context.Context, options PrepareStepFunctionOptions) (context.Context, PrepareStepResult, error) + type PrepareStepFunctionOptions struct + Messages []Message + Model LanguageModel + StepNumber int + Steps []StepResult + type PrepareStepResult struct + ActiveTools []string + DisableAllTools bool + Messages []Message + Model LanguageModel + System *string + ToolChoice *ToolChoice + Tools []AgentTool + type Prompt []Message + type Provider interface + LanguageModel func(ctx context.Context, modelID string) (LanguageModel, error) + Name func() string + type ProviderDefinedTool struct + Args map[string]any + ID string + Name string + func (p *ProviderDefinedTool) UnmarshalJSON(data []byte) error + func (p ProviderDefinedTool) GetName() string + func (p ProviderDefinedTool) GetType() ToolType + func (p ProviderDefinedTool) MarshalJSON() ([]byte, error) + type ProviderError struct + Cause error + Message string + RequestBody []byte + ResponseBody []byte + ResponseHeaders map[string]string + StatusCode int + Title string + URL string + func (m *ProviderError) Error() string + func (m *ProviderError) IsRetryable() bool + type ProviderMetadata map[string]ProviderOptionsData + func UnmarshalProviderMetadata(data map[string]json.RawMessage) (ProviderMetadata, error) + type ProviderOptions map[string]ProviderOptionsData + func UnmarshalProviderOptions(data map[string]json.RawMessage) (ProviderOptions, error) + type ProviderOptionsData interface + Options func() + type ReasoningContent struct + ProviderMetadata ProviderMetadata + Text string + func (r *ReasoningContent) UnmarshalJSON(data []byte) error + func (r ReasoningContent) GetType() ContentType + func (r ReasoningContent) MarshalJSON() ([]byte, error) + type ReasoningPart struct + ProviderOptions ProviderOptions + Text string + func (r *ReasoningPart) UnmarshalJSON(data []byte) error + func (r ReasoningPart) GetType() ContentType + func (r ReasoningPart) MarshalJSON() ([]byte, error) + func (r ReasoningPart) Options() ProviderOptions + type RepairToolCallFunction = func(ctx context.Context, options ToolCallRepairOptions) (*ToolCallContent, error) + type Response struct + Content ResponseContent + FinishReason FinishReason + ProviderMetadata ProviderMetadata + Usage Usage + Warnings []CallWarning + func (r *Response) UnmarshalJSON(data []byte) error + type ResponseContent []Content + func (r ResponseContent) Files() []FileContent + func (r ResponseContent) Reasoning() []ReasoningContent + func (r ResponseContent) ReasoningText() string + func (r ResponseContent) Sources() []SourceContent + func (r ResponseContent) Text() string + func (r ResponseContent) ToolCalls() []ToolCallContent + func (r ResponseContent) ToolResults() []ToolResultContent + type RetryError struct + Errors []error + func (e *RetryError) Error() string + func (e RetryError) Unwrap() error + type RetryFn func() (T, error) + type RetryFunction func(ctx context.Context, fn RetryFn[T]) (T, error) + func RetryWithExponentialBackoffRespectingRetryHeaders[T any](options RetryOptions) RetryFunction[T] + type RetryOptions struct + BackoffFactor float64 + InitialDelayIn time.Duration + MaxRetries int + OnRetry OnRetryCallback + func DefaultRetryOptions() RetryOptions + type Schema = schema.Schema + type SourceContent struct + Filename string + ID string + MediaType string + ProviderMetadata ProviderMetadata + SourceType SourceType + Title string + URL string + func (s *SourceContent) UnmarshalJSON(data []byte) error + func (s SourceContent) GetType() ContentType + func (s SourceContent) MarshalJSON() ([]byte, error) + type SourceType string + const SourceTypeDocument + const SourceTypeURL + type StepResult struct + Messages []Message + type StopCondition = func(steps []StepResult) bool + func FinishReasonIs(reason FinishReason) StopCondition + func HasContent(contentType ContentType) StopCondition + func HasToolCall(toolName string) StopCondition + func MaxTokensUsed(maxTokens int64) StopCondition + func StepCountIs(stepCount int) StopCondition + type StreamObjectResult struct + func NewStreamObjectResult[T any](ctx context.Context, stream ObjectStreamResponse) *StreamObjectResult[T] + func (s *StreamObjectResult[T]) FullStream() iter.Seq[ObjectStreamPart] + func (s *StreamObjectResult[T]) Object() (*ObjectResult[T], error) + func (s *StreamObjectResult[T]) PartialObjectStream() iter.Seq[T] + func (s *StreamObjectResult[T]) TextStream() iter.Seq[string] + type StreamPart struct + Delta string + Error error + FinishReason FinishReason + ID string + ProviderExecuted bool + ProviderMetadata ProviderMetadata + SourceType SourceType + Title string + ToolCallInput string + ToolCallName string + Type StreamPartType + URL string + Usage Usage + Warnings []CallWarning + func (s *StreamPart) UnmarshalJSON(data []byte) error + func (s StreamPart) MarshalJSON() ([]byte, error) + type StreamPartType string + const StreamPartTypeError + const StreamPartTypeFinish + const StreamPartTypeReasoningDelta + const StreamPartTypeReasoningEnd + const StreamPartTypeReasoningStart + const StreamPartTypeSource + const StreamPartTypeTextDelta + const StreamPartTypeTextEnd + const StreamPartTypeTextStart + const StreamPartTypeToolCall + const StreamPartTypeToolInputDelta + const StreamPartTypeToolInputEnd + const StreamPartTypeToolInputStart + const StreamPartTypeToolResult + const StreamPartTypeWarnings + type StreamResponse = iter.Seq[StreamPart] + type TextContent struct + ProviderMetadata ProviderMetadata + Text string + func (t *TextContent) UnmarshalJSON(data []byte) error + func (t TextContent) GetType() ContentType + func (t TextContent) MarshalJSON() ([]byte, error) + type TextPart struct + ProviderOptions ProviderOptions + Text string + func (t *TextPart) UnmarshalJSON(data []byte) error + func (t TextPart) GetType() ContentType + func (t TextPart) MarshalJSON() ([]byte, error) + func (t TextPart) Options() ProviderOptions + type Tool interface + GetName func() string + GetType func() ToolType + func UnmarshalTool(data []byte) (Tool, error) + type ToolCall struct + ID string + Input string + Name string + type ToolCallContent struct + Input string + Invalid bool + ProviderExecuted bool + ProviderMetadata ProviderMetadata + ToolCallID string + ToolName string + ValidationError error + func (t *ToolCallContent) UnmarshalJSON(data []byte) error + func (t ToolCallContent) GetType() ContentType + func (t ToolCallContent) MarshalJSON() ([]byte, error) + type ToolCallPart struct + Input string + ProviderExecuted bool + ProviderOptions ProviderOptions + ToolCallID string + ToolName string + func (t *ToolCallPart) UnmarshalJSON(data []byte) error + func (t ToolCallPart) GetType() ContentType + func (t ToolCallPart) MarshalJSON() ([]byte, error) + func (t ToolCallPart) Options() ProviderOptions + type ToolCallRepairOptions struct + AvailableTools []AgentTool + Messages []Message + OriginalToolCall ToolCallContent + SystemPrompt string + ValidationError error + type ToolChoice string + const ToolChoiceAuto + const ToolChoiceNone + const ToolChoiceRequired + func SpecificToolChoice(name string) ToolChoice + type ToolInfo struct + Description string + Name string + Parallel bool + Parameters map[string]any + Required []string + type ToolResponse struct + Content string + Data []byte + IsError bool + MediaType string + Metadata string + Type string + func NewImageResponse(data []byte, mediaType string) ToolResponse + func NewMediaResponse(data []byte, mediaType string) ToolResponse + func NewTextErrorResponse(content string) ToolResponse + func NewTextResponse(content string) ToolResponse + func WithResponseMetadata(response ToolResponse, metadata any) ToolResponse + type ToolResultContent struct + ClientMetadata string + ProviderExecuted bool + ProviderMetadata ProviderMetadata + Result ToolResultOutputContent + ToolCallID string + ToolName string + func (t *ToolResultContent) UnmarshalJSON(data []byte) error + func (t ToolResultContent) GetType() ContentType + func (t ToolResultContent) MarshalJSON() ([]byte, error) + type ToolResultContentType string + const ToolResultContentTypeError + const ToolResultContentTypeMedia + const ToolResultContentTypeText + type ToolResultOutputContent interface + GetType func() ToolResultContentType + func UnmarshalToolResultOutputContent(data []byte) (ToolResultOutputContent, error) + type ToolResultOutputContentError struct + Error error + func (t *ToolResultOutputContentError) UnmarshalJSON(data []byte) error + func (t ToolResultOutputContentError) GetType() ToolResultContentType + func (t ToolResultOutputContentError) MarshalJSON() ([]byte, error) + type ToolResultOutputContentMedia struct + Data string + MediaType string + Text string + func (t *ToolResultOutputContentMedia) UnmarshalJSON(data []byte) error + func (t ToolResultOutputContentMedia) GetType() ToolResultContentType + func (t ToolResultOutputContentMedia) MarshalJSON() ([]byte, error) + type ToolResultOutputContentText struct + Text string + func (t *ToolResultOutputContentText) UnmarshalJSON(data []byte) error + func (t ToolResultOutputContentText) GetType() ToolResultContentType + func (t ToolResultOutputContentText) MarshalJSON() ([]byte, error) + type ToolResultPart struct + Output ToolResultOutputContent + ProviderOptions ProviderOptions + ToolCallID string + func (t *ToolResultPart) UnmarshalJSON(data []byte) error + func (t ToolResultPart) GetType() ContentType + func (t ToolResultPart) MarshalJSON() ([]byte, error) + func (t ToolResultPart) Options() ProviderOptions + type ToolType string + const ToolTypeFileSearch + const ToolTypeFunction + const ToolTypeProviderDefined + type UnmarshalFunc func([]byte) (ProviderOptionsData, error) + type Usage struct + CacheCreationTokens int64 + CacheReadTokens int64 + InputTokens int64 + OutputTokens int64 + ReasoningTokens int64 + TotalTokens int64 + func (u Usage) String() string