Versions in this module Expand all Collapse all v0 v0.0.1 Aug 10, 2026 Changes in this version + const OUTPUT_SCHEMA_INSTRUCTION + const OutputSchemaInstruction + const ProviderAnthropic + const ProviderBailian + const ProviderGoogle + const ProviderOpenAI + const ProviderOpenai + const ProviderProxy + var DefaultModelInfos = map[string]ModelInfo + var ErrMaxTurnExceeded = errors.New("max turn exceeded") + var ErrSessionBusy = errors.New("session busy") + var ErrSessionClosed = errors.New("session closed") + var ErrSessionStarted = errors.New("session already started") + func ApplyCompression(history []*types.Message, compress *EventCompression) ([]*types.Message, int64, error) + func Completion(ctx context.Context, model string, messages []*types.Message, ...) (*types.Completion, error) + func DefaultModelsInitError() error + func Embedding(ctx context.Context, model string, input []string, ...) (*types.Embedding, error) + func NewProvider(name string, opts ...types.ProviderOption) (types.Provider, error) + func Realtime(ctx context.Context, model string, messages []*types.Message, ...) (types.RealTimeSession, error) + func RegistProviderCreator(name string, Creator ProviderCreator) + func RegisterProviderCreator(name string, creator ProviderCreator) error + func Rerank(ctx context.Context, model string, input *types.RerankInput, ...) (*types.RerankOutput, error) + func RunCompletionTask[T any](ctx context.Context, m *Model, prompt string, failRetry int, ...) (*T, error) + type Agent struct + Description string + Name string + func NewAgent(name string, description string, models *Models, opts ...AgentOption) (*Agent, error) + func (a *Agent) NewSession(history []*Event, opts ...AgentOption) (*Session, error) + func (a *Agent) Run(ctx context.Context, history []*Event, input *SessionInput, ...) (*SessionResult, error) + func (a *Agent) Start(ctx context.Context, history []*Event, opts ...AgentOption) (*Runner, error) + type AgentOption func(*AgentOptions) + func WithAdditionalTools(tools ...*Tool) AgentOption + func WithCompress(compress *CompressOptions) AgentOption + func WithEventSink(sink EventSink) AgentOption + func WithInstruction(instruction string) AgentOption + func WithLLMInterceptor(interceptors ...LLMInterceptor) AgentOption + func WithLoop(loop Loop) AgentOption + func WithMaxTurn(maxTurn int) AgentOption + func WithModel(model string) AgentOption + func WithReasonLevel(level int) AgentOption + func WithStream(stream bool) AgentOption + func WithToolCallInterceptor(interceptors ...ToolCallInterceptor) AgentOption + func WithTools(tools ...*Tool) AgentOption + type AgentOptions struct + Compress *CompressOptions + EventSink EventSink + Instruction string + LLMInterceptors []LLMInterceptor + Loop Loop + MaxTurn int + Model string + ReasonLevel int + Stream bool + ToolCallInterceptors []ToolCallInterceptor + Tools []*Tool + func ApplyAgentOptions(options *AgentOptions, opts ...AgentOption) *AgentOptions + func DefaultAgentOptions() *AgentOptions + func (o *AgentOptions) Clone() *AgentOptions + type CompressInput struct + Messages []*types.Message + Model string + Options *CompressOptions + Tokens int64 + type CompressOptions struct + KeepLastTurn int + SummaryBridge string + SummaryBridgeTag string + SummaryInstruction string + SummaryLevel float64 + SummaryModel string + SummaryTimeout time.Duration + ToolResultLevel float64 + ToolResultReplace string + ToolResultReplaceTag string + type CompressResultSummary struct + Message *types.Message + Usage types.CompletionUsage + type CompressResultToolResult struct + Instructions map[string]string + Result string + type Event struct + Compression *EventCompression + HumanRequest *EventHumanRequest + HumanResponse *EventHumanResponse + ID string + Message *types.Message + State *EventState + Usage *EventUsage + func Compress(ctx context.Context, models *Models, in *CompressInput) ([]*Event, error) + func NewEventCompression(compression *EventCompression) *Event + func NewEventHumanRequest(request *EventHumanRequest) *Event + func NewEventHumanResponse(response *EventHumanResponse) *Event + func NewEventMessage(message *types.Message) *Event + func NewEventState(state map[string]string, patch bool) *Event + func NewEventUsage(usage types.CompletionUsage) *Event + func (e *Event) Clone() *Event + func (e *Event) Validate() error + type EventCompression struct + Summary *CompressResultSummary + ToolResult *CompressResultToolResult + UntilMessageID string + func (e *EventCompression) Clone() *EventCompression + type EventHumanRequest struct + Arguments map[string]any + ID string + ToolCall *types.MessageToolCall + func (e *EventHumanRequest) Clone() *EventHumanRequest + type EventHumanResponse struct + ID string + Result map[string]any + func (e *EventHumanResponse) Clone() *EventHumanResponse + type EventSink func(context.Context, *Event) error + type EventState struct + Patch bool + State map[string]string + type EventUsage struct + Usage types.CompletionUsage + type LLMHandler func(context.Context, *SessionTurn) (*types.Completion, error) + type LLMInterceptor func(LLMHandler) LLMHandler + type Loop func(ctx context.Context, turn *SessionTurnResult) (LoopAction, error) + type LoopAction uint8 + const LoopContinue + const LoopStop + const LoopWait + func ReactLoop(_ context.Context, turn *SessionTurnResult) (LoopAction, error) + type Model struct + Fallback *ModelFallback + MaxToken int64 + Model string + Name string + Provider types.Provider + func GetModel(name string) (*Model, error) + func (m *Model) Completion(ctx context.Context, messages []*types.Message, ...) (*types.Completion, error) + func (m *Model) Embedding(ctx context.Context, input []string, options ...types.EmbeddingOption) (*types.Embedding, error) + func (m *Model) Realtime(ctx context.Context, messages []*types.Message, ...) (types.RealTimeSession, error) + func (m *Model) Rerank(ctx context.Context, input *types.RerankInput, options ...types.RerankOption) (*types.RerankOutput, error) + type ModelConfig struct + Fallback *ModelConfigFallback + MaxToken int64 + Model string + Name string + Provider string + type ModelConfigFallback struct + MaxSeconds int + Providers []ModelConfigFallbackProvider + type ModelConfigFallbackProvider struct + Model string + Provider string + type ModelFallback struct + MaxSeconds int + Providers []*ModelFallbackProvider + type ModelFallbackProvider struct + Model string + Provider types.Provider + ProviderName string + type ModelInfo struct + MaxOutputToken int64 + MaxToken int64 + type Models struct + var DefaultModels *Models = NewModels() + func NewModels() *Models + func NewModelsWithConfig(config ModelsConfig) (*Models, error) + func NewModelsWithConfigFile(fn string) (*Models, error) + func (m *Models) AddModel(conf ModelConfig) (*Model, error) + func (m *Models) AddProvider(conf ProviderConfig) (types.Provider, error) + func (m *Models) Close() error + func (m *Models) GetModel(name string) (*Model, error) + func (m *Models) RegisterProvider(name string, provider types.Provider) error + func (ms *Models) Completion(ctx context.Context, model string, messages []*types.Message, ...) (*types.Completion, error) + func (ms *Models) Embedding(ctx context.Context, model string, input []string, ...) (*types.Embedding, error) + func (ms *Models) Realtime(ctx context.Context, model string, messages []*types.Message, ...) (types.RealTimeSession, error) + func (ms *Models) Rerank(ctx context.Context, model string, input *types.RerankInput, ...) (*types.RerankOutput, error) + type ModelsConfig struct + Models []ModelConfig + Providers []ProviderConfig + type ProviderConfig struct + EmbeddingArgs *types.ProviderEmbeddingArgs + Insecure bool + Name string + Provider string + Sk string + ThinkArgs *types.ProviderThinkArgs + Url string + type ProviderCreator func(opts ...types.ProviderOption) (types.Provider, error) + type ProviderEnv struct + ApiKey string + LegacyAPIKey string + LegacyURL string + Provider string + Url string + type Runner struct + func (r *Runner) Done() <-chan struct{} + func (r *Runner) Send(ctx context.Context, input *SessionInput) error + func (r *Runner) Wait() (*SessionResult, error) + type Session struct + func NewSession(agent *Agent, history []*Event, opts ...AgentOption) (*Session, error) + func (s *Session) Run(ctx context.Context, input *SessionInput) (*SessionResult, error) + func (s *Session) Start(ctx context.Context) (*Runner, error) + type SessionHumanResponse struct + ID string + Result map[string]any + type SessionInput struct + HumanResponses []*SessionHumanResponse + Messages []*types.Message + State map[string]string + StateDelta map[string]string + func NewHumanResponseInput(requestID string, result map[string]any) *SessionInput + func NewSessionInput(messages ...*types.Message) *SessionInput + func NewUserInput(text string) *SessionInput + func (i *SessionInput) Clone() *SessionInput + func (i *SessionInput) IsEmpty() bool + func (i *SessionInput) Validate() error + func (i *SessionInput) WithHumanResponse(id string, result map[string]any) *SessionInput + func (i *SessionInput) WithMessages(messages ...*types.Message) *SessionInput + func (i *SessionInput) WithState(state map[string]string, delta bool) *SessionInput + type SessionResult struct + Cause error + Events []*Event + State map[string]string + StopReason StopReason + Turns int + func (r *SessionResult) Clone() *SessionResult + type SessionTurn struct + History []*types.Message + Index int + Instruction string + Model string + Tools []*Tool + func (t *SessionTurn) Clone() *SessionTurn + func (t *SessionTurn) GetState(key string) (string, bool) + func (t *SessionTurn) StateSnapshot() map[string]string + type SessionTurnResult struct + Events []*Event + Index int + TurnEventIndex int + type StopReason string + const StopCanceled + const StopDone + const StopError + const StopMaxTurn + type Tool struct + Description string + Invoker ToolInvoker + Name string + Parameters map[string]any + func MustNewTool[T any](name string, desc string, invoker func(ToolContext, *T) (any, error)) *Tool + func NewTool[T any](name string, desc string, invoker func(ToolContext, *T) (any, error)) (*Tool, error) + type ToolCallHandler func(ToolContext, *types.MessageToolCall) (any, error) + type ToolCallInterceptor func(ToolCallHandler) ToolCallHandler + type ToolContext interface + HumanRequest func() *EventHumanRequest + HumanResponse func() *EventHumanResponse + SetState func(patch map[string]string) error + State func() map[string]string + ToolCallID func() string + type ToolInvoker func(ToolContext, string) (any, error) + type ToolResultHuman struct + Arguments map[string]any + type ToolResultNotify struct + type ToolResultWithInstruction struct + Instruction map[string]string + Result any + type ToolRun struct + Call *types.MessageToolCall + Duration time.Duration + Error error + Result any + StatePatches []map[string]string