Documentation
¶
Index ¶
- Constants
- func AgentLoop(prompts []llm.Message, agentContext AgentContext, config AgentLoopConfig, ...) *llm.EventStream[AgentEvent, []llm.Message]
- func AgentLoopContinue(agentContext AgentContext, config AgentLoopConfig, ctx context.Context, ...) (*llm.EventStream[AgentEvent, []llm.Message], error)
- func RunAgentLoop(prompts []llm.Message, agentContext AgentContext, config AgentLoopConfig, ...) ([]llm.Message, error)
- func RunAgentLoopContinue(agentContext AgentContext, config AgentLoopConfig, emit AgentEventSink, ...) ([]llm.Message, error)
- func SetDefaultStreamFn(streamFn StreamFn)
- func StreamProxy(model llm.Model, llmContext llm.Context, options ProxyStreamOptions) *llm.AssistantMessageEventStream
- type AfterToolCallContext
- type AfterToolCallResult
- type Agent
- func (a *Agent) Abort()
- func (a *Agent) ClearAllQueues()
- func (a *Agent) ClearFollowUpQueue()
- func (a *Agent) ClearSteeringQueue()
- func (a *Agent) Continue(ctx context.Context) error
- func (a *Agent) FollowUp(message llm.Message)
- func (a *Agent) FollowUpMode() string
- func (a *Agent) HasQueuedMessages() bool
- func (a *Agent) Prompt(ctx context.Context, messages ...llm.Message) error
- func (a *Agent) PromptText(ctx context.Context, text string, images ...llm.ContentPart) error
- func (a *Agent) Reset()
- func (a *Agent) SetFollowUpMode(mode string)
- func (a *Agent) SetMessages(messages []llm.Message)
- func (a *Agent) SetModel(model llm.Model)
- func (a *Agent) SetSteeringMode(mode string)
- func (a *Agent) SetSystemPrompt(prompt string)
- func (a *Agent) SetThinkingLevel(level string)
- func (a *Agent) SetTools(tools []AgentTool)
- func (a *Agent) State() AgentState
- func (a *Agent) Steer(message llm.Message)
- func (a *Agent) SteeringMode() string
- func (a *Agent) Subscribe(listener func(AgentEvent, context.Context) error) func()
- func (a *Agent) WaitForIdle(ctx context.Context) error
- type AgentContext
- type AgentEvent
- type AgentEventSink
- type AgentLoopConfig
- type AgentLoopTurnUpdate
- type AgentMessage
- type AgentOption
- func WithConvertToLLM(convert func(messages []llm.Message) ([]llm.Message, error)) AgentOption
- func WithInitialState(state AgentState) AgentOption
- func WithSession(id string) AgentOption
- func WithStreamFn(streamFn StreamFn) AgentOption
- func WithToolExecution(mode string) AgentOption
- func WithToolHooks(...) AgentOption
- func WithTransformContext(...) AgentOption
- type AgentOptions
- type AgentState
- type AgentTool
- type AgentToolCall
- type AgentToolResult
- type AgentToolUpdateCallback
- type BeforeToolCallContext
- type BeforeToolCallResult
- type PrepareNextTurnContext
- type ProxyAssistantMessageEvent
- type ProxyStreamOptions
- type ShouldStopAfterTurnContext
- type StreamFn
Constants ¶
View Source
const ( ToolExecutionSequential = "sequential" ToolExecutionParallel = "parallel" QueueAll = "all" QueueOneAtTime = "one-at-a-time" )
Variables ¶
This section is empty.
Functions ¶
func AgentLoop ¶
func AgentLoop(prompts []llm.Message, agentContext AgentContext, config AgentLoopConfig, ctx context.Context, streamFn StreamFn) *llm.EventStream[AgentEvent, []llm.Message]
func AgentLoopContinue ¶
func AgentLoopContinue(agentContext AgentContext, config AgentLoopConfig, ctx context.Context, streamFn StreamFn) (*llm.EventStream[AgentEvent, []llm.Message], error)
func RunAgentLoop ¶
func RunAgentLoop(prompts []llm.Message, agentContext AgentContext, config AgentLoopConfig, emit AgentEventSink, ctx context.Context, streamFn StreamFn) ([]llm.Message, error)
func RunAgentLoopContinue ¶
func RunAgentLoopContinue(agentContext AgentContext, config AgentLoopConfig, emit AgentEventSink, ctx context.Context, streamFn StreamFn) ([]llm.Message, error)
func SetDefaultStreamFn ¶ added in v0.82.0
func SetDefaultStreamFn(streamFn StreamFn)
SetDefaultStreamFn configures the fallback used when an Agent or low-level loop caller omits its stream function. Passing nil clears the fallback.
func StreamProxy ¶
func StreamProxy(model llm.Model, llmContext llm.Context, options ProxyStreamOptions) *llm.AssistantMessageEventStream
Types ¶
type AfterToolCallContext ¶
type AfterToolCallContext struct {
AssistantMessage llm.Message
ToolCall AgentToolCall
Args map[string]any
Result AgentToolResult
IsError bool
Context AgentContext
}
type AfterToolCallResult ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func New ¶
func New(options ...AgentOption) *Agent
func NewAgent ¶
func NewAgent(options AgentOptions) *Agent
func (*Agent) ClearAllQueues ¶
func (a *Agent) ClearAllQueues()
func (*Agent) ClearFollowUpQueue ¶
func (a *Agent) ClearFollowUpQueue()
func (*Agent) ClearSteeringQueue ¶
func (a *Agent) ClearSteeringQueue()
func (*Agent) FollowUpMode ¶
func (*Agent) HasQueuedMessages ¶
func (*Agent) PromptText ¶
func (*Agent) SetFollowUpMode ¶
func (*Agent) SetMessages ¶
func (*Agent) SetSteeringMode ¶
func (*Agent) SetSystemPrompt ¶
func (*Agent) SetThinkingLevel ¶
func (*Agent) State ¶
func (a *Agent) State() AgentState
func (*Agent) SteeringMode ¶
type AgentContext ¶
type AgentEvent ¶
type AgentEventSink ¶
type AgentEventSink func(event AgentEvent) error
type AgentLoopConfig ¶
type AgentLoopConfig struct {
llm.SimpleStreamOptions
Model llm.Model
ConvertToLLM func(messages []llm.Message) ([]llm.Message, error)
TransformContext func(ctx context.Context, messages []llm.Message) ([]llm.Message, error)
GetAPIKey func(provider string) string
ShouldStopAfterTurn func(ShouldStopAfterTurnContext) (bool, error)
PrepareNextTurn func(PrepareNextTurnContext) (AgentLoopTurnUpdate, bool, error)
GetSteeringMessages func() ([]llm.Message, error)
GetFollowUpMessages func() ([]llm.Message, error)
ToolExecution string
BeforeToolCall func(context.Context, BeforeToolCallContext) (BeforeToolCallResult, error)
AfterToolCall func(context.Context, AfterToolCallContext) (AfterToolCallResult, error)
}
type AgentLoopTurnUpdate ¶
type AgentLoopTurnUpdate struct {
Context *AgentContext
Model *llm.Model
ThinkingLevel *string
}
type AgentMessage ¶
type AgentOption ¶
type AgentOption func(*AgentOptions)
func WithConvertToLLM ¶
func WithInitialState ¶
func WithInitialState(state AgentState) AgentOption
func WithSession ¶
func WithSession(id string) AgentOption
func WithStreamFn ¶
func WithStreamFn(streamFn StreamFn) AgentOption
func WithToolExecution ¶
func WithToolExecution(mode string) AgentOption
func WithToolHooks ¶
func WithToolHooks( before func(context.Context, BeforeToolCallContext) (BeforeToolCallResult, error), after func(context.Context, AfterToolCallContext) (AfterToolCallResult, error), ) AgentOption
func WithTransformContext ¶
type AgentOptions ¶
type AgentOptions struct {
InitialState AgentState
ConvertToLLM func(messages []llm.Message) ([]llm.Message, error)
TransformContext func(ctx context.Context, messages []llm.Message) ([]llm.Message, error)
StreamFn StreamFn
GetAPIKey func(provider string) string
BeforeToolCall func(context.Context, BeforeToolCallContext) (BeforeToolCallResult, error)
AfterToolCall func(context.Context, AfterToolCallContext) (AfterToolCallResult, error)
PrepareNextTurn func(context.Context) (AgentLoopTurnUpdate, bool, error)
SteeringMode string
FollowUpMode string
SessionID string
ThinkingBudgets map[string]int
Transport string
MaxRetryDelayMs int
ToolExecution string
}
type AgentState ¶
type AgentTool ¶
type AgentTool struct {
Name string
Label string
Description string
Parameters llm.Schema
PrepareArguments func(args any) (map[string]any, error)
Execute func(ctx context.Context, toolCallID string, params map[string]any, onUpdate AgentToolUpdateCallback) (AgentToolResult, error)
ExecutionMode string
}
type AgentToolCall ¶
type AgentToolCall = llm.ContentPart
type AgentToolResult ¶
type AgentToolResult struct {
Content []llm.ContentPart
Details any
Terminate bool
}
type AgentToolUpdateCallback ¶
type AgentToolUpdateCallback func(partialResult AgentToolResult)
type BeforeToolCallContext ¶
type BeforeToolCallContext struct {
AssistantMessage llm.Message
ToolCall AgentToolCall
Args map[string]any
Context AgentContext
}
type BeforeToolCallResult ¶
type PrepareNextTurnContext ¶
type PrepareNextTurnContext = ShouldStopAfterTurnContext
type ProxyAssistantMessageEvent ¶
type ProxyAssistantMessageEvent struct {
Type string `json:"type"`
ContentIndex int `json:"contentIndex,omitempty"`
Delta string `json:"delta,omitempty"`
ContentSignature string `json:"contentSignature,omitempty"`
ID string `json:"id,omitempty"`
ToolName string `json:"toolName,omitempty"`
Reason string `json:"reason,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
Usage llm.Usage `json:"usage,omitempty"`
}
type ProxyStreamOptions ¶
type StreamFn ¶
type StreamFn func(model llm.Model, llmContext llm.Context, options llm.SimpleStreamOptions) (*llm.AssistantMessageEventStream, error)
func GetDefaultStreamFn ¶ added in v0.82.0
GetDefaultStreamFn returns the configured fallback stream function.
func NewProxyStreamFn ¶
Click to show internal directories.
Click to hide internal directories.