Documentation
¶
Index ¶
- func AggregateUsage(a, b provider.Usage) provider.Usage
- type Agent
- func (a *Agent) Continue(ctx context.Context, messages []provider.Message, prompt string) (*LoopResult, error)
- func (a *Agent) ContinueStream(ctx context.Context, messages []provider.Message, prompt string, ...) (*LoopResult, error)
- func (a *Agent) Messages(systemPrompt string, result *LoopResult) []provider.Message
- func (a *Agent) Run(ctx context.Context, prompt string) (*LoopResult, error)
- func (a *Agent) RunStream(ctx context.Context, prompt string, events chan<- StreamEvent) (*LoopResult, error)
- func (a *Agent) WithMaxToolSteps(n int) *Agent
- func (a *Agent) WithOnIterationEnd(cb IterationCallback) *Agent
- func (a *Agent) WithOnIterationStart(cb IterationCallback) *Agent
- func (a *Agent) WithOnToolEnd(cb ToolEndCallback) *Agent
- func (a *Agent) WithOnToolStart(cb ToolStartCallback) *Agent
- func (a *Agent) WithSettings(s Settings) *Agent
- func (a *Agent) WithStopConditions(conditions ...StopCondition) *Agent
- func (a *Agent) WithSystemPrompt(prompt string) *Agent
- func (a *Agent) WithTools(tools ...*tool.Tool) *Agent
- func (a *Agent) WithVerification(v VerifyCompletion) *Agent
- type CompletionReason
- type IterationCallback
- type IterationResult
- type LoopResult
- type Settings
- type StopCondition
- type StopConditionContext
- type StreamEvent
- type TokenCallback
- type ToolEndCallback
- type ToolResult
- type ToolStartCallback
- type VerificationContext
- type VerificationResult
- type VerifyCompletion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func (*Agent) Continue ¶
func (a *Agent) Continue(ctx context.Context, messages []provider.Message, prompt string) (*LoopResult, error)
Continue resumes a conversation with existing messages and a new user prompt. The messages should include the system prompt if one was used.
func (*Agent) ContinueStream ¶
func (a *Agent) ContinueStream(ctx context.Context, messages []provider.Message, prompt string, events chan<- StreamEvent) (*LoopResult, error)
ContinueStream resumes a conversation with streaming.
func (*Agent) Messages ¶
func (a *Agent) Messages(systemPrompt string, result *LoopResult) []provider.Message
Messages returns the full message history from a LoopResult, including the system prompt if provided.
func (*Agent) RunStream ¶
func (a *Agent) RunStream(ctx context.Context, prompt string, events chan<- StreamEvent) (*LoopResult, error)
RunStream runs the agent with streaming, sending events to the provided channel. The channel will be closed when the agent completes.
func (*Agent) WithMaxToolSteps ¶
func (*Agent) WithOnIterationEnd ¶
func (a *Agent) WithOnIterationEnd(cb IterationCallback) *Agent
func (*Agent) WithOnIterationStart ¶
func (a *Agent) WithOnIterationStart(cb IterationCallback) *Agent
func (*Agent) WithOnToolEnd ¶
func (a *Agent) WithOnToolEnd(cb ToolEndCallback) *Agent
func (*Agent) WithOnToolStart ¶
func (a *Agent) WithOnToolStart(cb ToolStartCallback) *Agent
func (*Agent) WithSettings ¶
func (*Agent) WithStopConditions ¶
func (a *Agent) WithStopConditions(conditions ...StopCondition) *Agent
func (*Agent) WithSystemPrompt ¶
func (*Agent) WithVerification ¶
func (a *Agent) WithVerification(v VerifyCompletion) *Agent
type CompletionReason ¶
type CompletionReason string
const ( CompletionReasonVerified CompletionReason = "verified" CompletionReasonMaxIterations CompletionReason = "max_iterations" CompletionReasonStopCondition CompletionReason = "stop_condition" CompletionReasonAborted CompletionReason = "aborted" CompletionReasonError CompletionReason = "error" )
type IterationCallback ¶
type IterationCallback func(iteration int, result *IterationResult)
type IterationResult ¶
type IterationResult struct {
Iteration int
Response *provider.ChatResponse
ToolCalls []provider.ToolCall
ToolResults []ToolResult
Usage provider.Usage
// Messages contains all messages generated during this iteration
// (assistant messages with tool_calls + tool result messages)
Messages []provider.Message
}
type LoopResult ¶
type LoopResult struct {
FinalText string
Iterations int
CompletionReason CompletionReason
Reason string
AllResults []*IterationResult
TotalUsage provider.Usage
}
type Settings ¶
type Settings struct {
MaxToolSteps int
StopConditions []StopCondition
VerifyCompletion VerifyCompletion
OnIterationStart IterationCallback
OnIterationEnd IterationCallback
OnToolStart ToolStartCallback
OnToolEnd ToolEndCallback
}
func DefaultSettings ¶
func DefaultSettings() Settings
type StopCondition ¶
type StopCondition func(ctx StopConditionContext) bool
func IterationCountIs ¶
func IterationCountIs(n int) StopCondition
func PromptTokensExceed ¶
func PromptTokensExceed(maxTokens int) StopCondition
PromptTokensExceed returns a stop condition that triggers when prompt tokens exceed the limit. This is useful for preventing context window overflow.
func TokenUsagePercent ¶
func TokenUsagePercent(maxTokens int, percent float64) StopCondition
TokenUsagePercent returns a stop condition that triggers when token usage exceeds a percentage of the limit.
func TotalTokensExceed ¶
func TotalTokensExceed(maxTokens int) StopCondition
TotalTokensExceed returns a stop condition that triggers when total tokens exceed the limit.
type StopConditionContext ¶
type StopConditionContext struct {
Iteration int
TotalUsage provider.Usage
LastResult *IterationResult
AllResults []*IterationResult
}
type StreamEvent ¶
type StreamEvent struct {
Type string `json:"type"` // "token", "tool_start", "tool_end", "error", "done"
Content string `json:"content,omitempty"`
ToolName string `json:"tool_name,omitempty"`
ToolArgs string `json:"tool_args,omitempty"`
ToolResult string `json:"tool_result,omitempty"`
Error string `json:"error,omitempty"`
SessionID string `json:"session_id,omitempty"`
}
StreamEvent represents an event during streaming
type TokenCallback ¶
type TokenCallback func(token string)
type ToolEndCallback ¶
type ToolEndCallback func(toolName string, args string, result *ToolResult)
type ToolResult ¶
type ToolStartCallback ¶
type VerificationContext ¶
type VerificationContext struct {
LastResult *IterationResult
Iteration int
AllResults []*IterationResult
OriginalPrompt string
TotalUsage provider.Usage
}
type VerificationResult ¶
type VerifyCompletion ¶
type VerifyCompletion func(ctx VerificationContext) VerificationResult
func DefaultVerification ¶
func DefaultVerification() VerifyCompletion
func NoToolCallsVerification ¶
func NoToolCallsVerification() VerifyCompletion
func TextContainsVerification ¶
func TextContainsVerification(substring string) VerifyCompletion