Documentation
¶
Overview ¶
Example (MockAgent) ¶
Example_mockAgent demonstrates using mock agent with agentboot
// Create mock agent with custom config
mockAgent := NewAgent(Config{
MaxIterations: 3,
StepDelay: 100 * time.Millisecond, // Fast for testing
AutoApprove: true, // Auto-approve for demo
})
// Execute with context
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result, err := mockAgent.Execute(ctx, "Hello, mock agent!", agentboot.ExecutionOptions{
OutputFormat: agentboot.OutputFormatStreamJSON,
})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Success: %v\n", result.IsSuccess())
fmt.Printf("Steps: %d events\n", len(result.Events))
Output: Success: true Steps: 11 events
Example (MockAgentWithAskUserQuestion) ¶
Example_mockAgentWithAskUserQuestion demonstrates mock agent with AskUserQuestion
// Create mock agent that sends AskUserQuestion every 2 steps
mockAgent := NewAgent(Config{
MaxIterations: 4,
StepDelay: 50 * time.Millisecond,
AutoApprove: false,
AskUserQuestionFrequency: 2, // Every 2 steps, send AskUserQuestion
})
// Create handler that auto-approves everything
handler := agentboot.NewCompositeHandler().
SetApprovalHandler(&autoApprovalHandler{}).
SetAskHandler(&autoAskHandler{})
// Execute
ctx := context.Background()
result, err := mockAgent.Execute(ctx, "Test with AskUserQuestion", agentboot.ExecutionOptions{
Handler: handler,
OutputFormat: agentboot.OutputFormatStreamJSON,
})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Completed: %v\n", result.IsSuccess())
fmt.Printf("Events: %d\n", len(result.Events))
Output: Completed: true Events: 14
Example (MockAgentWithHandler) ¶
Example_mockAgentWithHandler demonstrates mock agent with message handler
// Create mock agent
mockAgent := NewAgent(Config{
MaxIterations: 2,
StepDelay: 50 * time.Millisecond,
AutoApprove: false, // Require manual approval
})
// Create message handler that auto-approves
handler := agentboot.NewCompositeHandler().
SetApprovalHandler(&autoApprovalHandler{}).
SetAskHandler(&autoAskHandler{})
// Execute with handler
ctx := context.Background()
result, err := mockAgent.Execute(ctx, "Test with handler", agentboot.ExecutionOptions{
Handler: handler,
OutputFormat: agentboot.OutputFormatStreamJSON,
})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Completed: %v\n", result.IsSuccess())
Output: Completed: true
Index ¶
- type Agent
- func (a *Agent) Execute(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (*agentboot.Result, error)
- func (a *Agent) GetDefaultFormat() agentboot.OutputFormat
- func (a *Agent) IsAvailable() bool
- func (a *Agent) SetAskUserQuestionFrequency(freq int)
- func (a *Agent) SetAutoApprove(autoApprove bool)
- func (a *Agent) SetDefaultFormat(format agentboot.OutputFormat)
- func (a *Agent) SetMaxIterations(max int)
- func (a *Agent) SetStepDelay(delay time.Duration)
- func (a *Agent) Type() agentboot.AgentType
- type Config
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent implements the agentboot.Agent interface for testing purposes. It simulates agent behavior by repeatedly requesting user permission confirmations.
func NewAgentWithConfig ¶
NewAgentWithConfig creates a new mock agent with both mock and agentboot configs
func (*Agent) Execute ¶
func (a *Agent) Execute(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (*agentboot.Result, error)
Execute runs the mock agent, simulating permission request cycles
func (*Agent) GetDefaultFormat ¶
func (a *Agent) GetDefaultFormat() agentboot.OutputFormat
GetDefaultFormat returns the current default format
func (*Agent) IsAvailable ¶
IsAvailable always returns true for mock agent
func (*Agent) SetAskUserQuestionFrequency ¶
SetAskUserQuestionFrequency configures how often to send AskUserQuestion requests
func (*Agent) SetAutoApprove ¶
SetAutoApprove configures auto-approval mode
func (*Agent) SetDefaultFormat ¶
func (a *Agent) SetDefaultFormat(format agentboot.OutputFormat)
SetDefaultFormat sets the default output format
func (*Agent) SetMaxIterations ¶
SetMaxIterations configures the maximum number of iterations
func (*Agent) SetStepDelay ¶
SetStepDelay configures the delay between steps
type Config ¶
type Config struct {
// MaxIterations is the maximum number of permission cycles (default: 5)
MaxIterations int `json:"max_iterations"`
// StepDelay is the delay between steps (default: 1s)
StepDelay time.Duration `json:"step_delay"`
// AutoApprove if true, auto-approves permissions without user interaction (default: false)
AutoApprove bool `json:"auto_approve"`
// ResponseTemplate is the template for mock responses
// Supports placeholders: {step}, {total}, {prompt}
ResponseTemplate string `json:"response_template"`
// PermissionMode sets how permissions are handled
PermissionMode agentboot.PermissionMode `json:"permission_mode"`
// AskUserQuestionFrequency controls how often to send AskUserQuestion requests
// 0 = never send AskUserQuestion, 1 = every step, 2 = every 2 steps, etc.
AskUserQuestionFrequency int `json:"ask_user_question_frequency"`
}
Config holds the mock agent configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default mock agent configuration