Versions in this module Expand all Collapse all v0 v0.26.0 Jun 13, 2026 Changes in this version + const DefaultLoopLimit + const DefaultMaxPDFSize + const HistoryVersion + var ErrCyclicReference = goerr.New("cyclic reference detected") + var ErrExitConversation = errors.New("exit conversation") + var ErrFunctionCallFormat = errors.New("function call format error") + var ErrHistoryVersionMismatch = errors.New("history version mismatch") + var ErrInvalidHistoryData = errors.New("invalid history data") + var ErrInvalidInputSchema = errors.New("invalid input schema") + var ErrInvalidParameter = errors.New("invalid parameter") + var ErrInvalidTag = goerr.New("invalid struct tag") + var ErrInvalidTool = errors.New("invalid tool specification") + var ErrLLMTypeMismatch = errors.New("llm type mismatch") + var ErrLoopLimitExceeded = errors.New("loop limit exceeded") + var ErrPlanAlreadyExecuted = errors.New("plan already executed") + var ErrPlanNotInitialized = errors.New("plan not properly initialized") + var ErrPlanStepFailed = errors.New("plan step execution failed") + var ErrProhibitedContent = errors.New("prohibited content") + var ErrSubAgentFactory = errors.New("subagent factory failed") + var ErrTagTokenExceeded = goerr.NewTag("token_exceeded") + var ErrTokenSizeExceeded = errors.New("token size exceeded") + var ErrToolArgsValidation = errors.New("tool arguments validation failed") + var ErrToolNameConflict = errors.New("tool name conflict") + var ErrUnsupportedType = goerr.New("unsupported type for schema conversion") + func IsValidImageMimeType(mimeType ImageMimeType) bool + func NewGenerateConfig(opts ...GenerateOption) generateConfig + type Agent struct + func New(llmClient LLMClient, options ...Option) *Agent + func (c *Agent) Clone() *gollemConfig + func (g *Agent) Execute(ctx context.Context, input ...Input) (_ *ExecuteResponse, err error) + func (x *Agent) Session() Session + type ContentBlockHandler func(ctx context.Context, req *ContentRequest) (*ContentResponse, error) + func BuildContentBlockChain(middlewares []ContentBlockMiddleware, handler ContentBlockHandler) ContentBlockHandler + type ContentBlockMiddleware func(next ContentBlockHandler) ContentBlockHandler + type ContentRequest struct + History *History + Inputs []Input + SystemPrompt string + type ContentResponse struct + Error error + FunctionCalls []*FunctionCall + InputToken int + OutputToken int + Texts []string + Thoughts []string + type ContentStreamHandler func(ctx context.Context, req *ContentRequest) (<-chan *ContentResponse, error) + func BuildContentStreamChain(middlewares []ContentStreamMiddleware, handler ContentStreamHandler) ContentStreamHandler + type ContentStreamMiddleware func(next ContentStreamHandler) ContentStreamHandler + type ContentType string + const ContentTypeJSON + const ContentTypeText + type ExecuteResponse struct + Texts []string + Thoughts []string + UserInputs []Input + func NewExecuteResponse(texts ...string) *ExecuteResponse + func (r *ExecuteResponse) IsEmpty() bool + func (r *ExecuteResponse) String() string + type FunctionCall struct + Arguments map[string]any + ID string + Name string + type FunctionResponse struct + Data map[string]any + Error error + ID string + Name string + func (f FunctionResponse) LogValue() slog.Value + func (f FunctionResponse) String() string + type GenerateOption func(*generateConfig) + func WithGenerateResponseSchema(schema *Parameter) GenerateOption + func WithMaxTokens(n int) GenerateOption + func WithTemperature(t float64) GenerateOption + func WithTopP(p float64) GenerateOption + type History struct + LLType LLMType + Messages []Message + Version int + func (x *History) Clone() *History + func (x *History) ToCount() int + func (x *History) UnmarshalJSON(data []byte) error + type HistoryRepository interface + Load func(ctx context.Context, sessionID string) (*History, error) + Save func(ctx context.Context, sessionID string, history *History) error + type Image struct + func NewImage(data []byte, opts ...ImageOption) (Image, error) + func NewImageFromReader(r io.Reader, opts ...ImageOption) (Image, error) + func (i Image) Base64() string + func (i Image) Data() []byte + func (i Image) LogValue() slog.Value + func (i Image) MimeType() string + func (i Image) String() string + type ImageContent struct + Data []byte + Detail string + MediaType string + URL string + type ImageMimeType string + const ImageMimeTypeGIF + const ImageMimeTypeHEIC + const ImageMimeTypeHEIF + const ImageMimeTypeJPEG + const ImageMimeTypePNG + const ImageMimeTypeWebP + type ImageOption func(*imageConfig) error + func WithMimeType(mimeType ImageMimeType) ImageOption + type Input interface + LogValue func() slog.Value + String func() string + type LLMClient interface + GenerateEmbedding func(ctx context.Context, dimension int, input []string) ([][]float64, error) + NewSession func(ctx context.Context, options ...SessionOption) (Session, error) + type LLMType string + const LLMTypeClaude + const LLMTypeGemini + const LLMTypeOpenAI + type Message struct + Contents []MessageContent + Metadata map[string]interface{} + Name string + Role MessageRole + type MessageContent struct + Data json.RawMessage + Meta json.RawMessage + Type MessageContentType + func NewImageContent(mediaType string, imageData []byte, url string, detail string) (MessageContent, error) + func NewPDFContent(pdfData []byte, url string) (MessageContent, error) + func NewTextContent(text string) (MessageContent, error) + func NewThinkingContent(text string) (MessageContent, error) + func NewToolCallContent(id, name string, args map[string]interface{}) (MessageContent, error) + func NewToolResponseContent(toolCallID, name string, response map[string]interface{}, isError bool) (MessageContent, error) + func (mc *MessageContent) GetImageContent() (*ImageContent, error) + func (mc *MessageContent) GetPDFContent() (*PDFContent, error) + func (mc *MessageContent) GetTextContent() (*TextContent, error) + func (mc *MessageContent) GetThinkingContent() (*ThinkingContent, error) + func (mc *MessageContent) GetToolCallContent() (*ToolCallContent, error) + func (mc *MessageContent) GetToolResponseContent() (*ToolResponseContent, error) + type MessageContentType string + const MessageContentTypeImage + const MessageContentTypePDF + const MessageContentTypeText + const MessageContentTypeThinking + const MessageContentTypeToolCall + const MessageContentTypeToolResponse + type MessageRole string + const RoleAssistant + const RoleSystem + const RoleTool + const RoleUser + type Option func(*gollemConfig) + func WithContentBlockMiddleware(middleware ContentBlockMiddleware) Option + func WithContentStreamMiddleware(middleware ContentStreamMiddleware) Option + func WithContentType(contentType ContentType) Option + func WithDisableArgsValidation() Option + func WithHistory(history *History) Option + func WithHistoryRepository(repo HistoryRepository, sessionID string) Option + func WithLogger(logger *slog.Logger) Option + func WithLoopLimit(loopLimit int) Option + func WithResponseMode(responseMode ResponseMode) Option + func WithResponseSchema(schema *Parameter) Option + func WithStrategy(strategy Strategy) Option + func WithSubAgents(subagents ...*SubAgent) Option + func WithSystemPrompt(systemPrompt string) Option + func WithToolMiddleware(middleware ToolMiddleware) Option + func WithToolSets(toolSets ...ToolSet) Option + func WithTools(tools ...Tool) Option + func WithTrace(handler trace.Handler) Option + type PDF struct + func NewPDF(data []byte, opts ...PDFOption) (PDF, error) + func NewPDFFromReader(r io.Reader, opts ...PDFOption) (PDF, error) + func (p PDF) Base64() string + func (p PDF) Data() []byte + func (p PDF) LogValue() slog.Value + func (p PDF) MimeType() string + func (p PDF) String() string + type PDFContent struct + Data []byte + URL string + type PDFOption func(*pdfOption) + func WithMaxPDFSize(size int) PDFOption + type Parameter struct + Default any + Description string + Enum []string + Items *Parameter + MaxItems *int + MaxLength *int + Maximum *float64 + MinItems *int + MinLength *int + Minimum *float64 + Pattern string + Properties map[string]*Parameter + Required bool + Title string + Type ParameterType + func MustToSchema(v any) *Parameter + func ToSchema(v any) (*Parameter, error) + func (p *Parameter) Validate() error + func (p *Parameter) ValidateValue(name string, value any) error + type ParameterType string + const TypeArray + const TypeBoolean + const TypeInteger + const TypeNumber + const TypeObject + const TypeString + type PromptTemplate struct + func DefaultPromptTemplate() *PromptTemplate + func NewPromptTemplate(tmpl string, params map[string]*Parameter) (*PromptTemplate, error) + func (p *PromptTemplate) Parameters() map[string]*Parameter + func (p *PromptTemplate) Render(args map[string]any) (string, error) + type QueryOption func(*queryConfig) + func WithQueryHistory(history *History) QueryOption + func WithQueryMaxRetry(n int) QueryOption + func WithQuerySystemPrompt(prompt string) QueryOption + type QueryResponse struct + Data *T + InputToken int + OutputToken int + func Query[T any](ctx context.Context, client LLMClient, prompt string, opts ...QueryOption) (*QueryResponse[T], error) + func SessionQuery[T any](ctx context.Context, session Session, prompt string, ...) (*QueryResponse[T], error) + type Response struct + Error error + FunctionCalls []*FunctionCall + InputToken int + OutputToken int + Texts []string + Thoughts []string + func (r *Response) HasData() bool + type ResponseMode string + const ResponseModeBlocking + const ResponseModeStreaming + func (x ResponseMode) String() string + type Session interface + AppendHistory func(*History) error + CountToken func(ctx context.Context, input ...Input) (int, error) + Generate func(ctx context.Context, input []Input, opts ...GenerateOption) (*Response, error) + GenerateContent func(ctx context.Context, input ...Input) (*Response, error) + GenerateStream func(ctx context.Context, input ...Input) (<-chan *Response, error) + History func() (*History, error) + Stream func(ctx context.Context, input []Input, opts ...GenerateOption) (<-chan *Response, error) + type SessionConfig struct + func NewSessionConfig(options ...SessionOption) SessionConfig + func (c *SessionConfig) ContentBlockMiddlewares() []ContentBlockMiddleware + func (c *SessionConfig) ContentStreamMiddlewares() []ContentStreamMiddleware + func (c *SessionConfig) ContentType() ContentType + func (c *SessionConfig) History() *History + func (c *SessionConfig) ResponseSchema() *Parameter + func (c *SessionConfig) SystemPrompt() string + func (c *SessionConfig) Tools() []Tool + type SessionOption func(cfg *SessionConfig) + func WithSessionContentBlockMiddleware(middlewares ...ContentBlockMiddleware) SessionOption + func WithSessionContentStreamMiddleware(middlewares ...ContentStreamMiddleware) SessionOption + func WithSessionContentType(contentType ContentType) SessionOption + func WithSessionHistory(history *History) SessionOption + func WithSessionResponseSchema(schema *Parameter) SessionOption + func WithSessionSystemPrompt(systemPrompt string) SessionOption + func WithSessionTools(tools ...Tool) SessionOption + type SessionQueryOption func(*sessionQueryConfig) + func WithSessionQueryMaxRetry(n int) SessionQueryOption + type Strategy interface + Handle func(ctx context.Context, state *StrategyState) ([]Input, *ExecuteResponse, error) + Init func(ctx context.Context, inputs []Input) error + Tools func(ctx context.Context) ([]Tool, error) + type StrategyState struct + History *History + InitInput []Input + Iteration int + LastResponse *Response + NextInput []Input + Session Session + SystemPrompt string + Tools []Tool + type SubAgent struct + func NewSubAgent(name, description string, agentFactory func() (*Agent, error), ...) *SubAgent + func (s *SubAgent) Run(ctx context.Context, args map[string]any) (_ map[string]any, retErr error) + func (s *SubAgent) Spec() ToolSpec + type SubAgentHandler func(ctx context.Context, args map[string]any) (SubAgentResult, error) + type SubAgentOption func(*SubAgent) + func WithPromptTemplate(prompt *PromptTemplate) SubAgentOption + func WithSubAgentMiddleware(middleware func(SubAgentHandler) SubAgentHandler) SubAgentOption + func WithSubAgentOptions(opts ...Option) SubAgentOption + type SubAgentResult struct + Data map[string]any + Session Session + type Text string + func (t Text) LogValue() slog.Value + func (t Text) String() string + type TextContent struct + Text string + type ThinkingContent struct + Text string + type Tool interface + Run func(ctx context.Context, args map[string]any) (map[string]any, error) + Spec func() ToolSpec + type ToolCallContent struct + Arguments map[string]interface{} + ID string + Name string + type ToolExecRequest struct + Tool *FunctionCall + ToolSpec *ToolSpec + type ToolExecResponse struct + Duration int64 + Error error + Result map[string]any + type ToolHandler func(ctx context.Context, req *ToolExecRequest) (*ToolExecResponse, error) + type ToolMiddleware func(next ToolHandler) ToolHandler + type ToolResponseContent struct + IsError bool + Name string + Response map[string]interface{} + ToolCallID string + type ToolSet interface + Run func(ctx context.Context, name string, args map[string]any) (map[string]any, error) + Specs func(ctx context.Context) ([]ToolSpec, error) + type ToolSpec struct + Description string + Name string + Parameters map[string]*Parameter + func (s *ToolSpec) Validate() error + func (s *ToolSpec) ValidateArgs(args map[string]any) error