mock

package
v0.260402.2330 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

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

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 NewAgent

func NewAgent(config Config) *Agent

NewAgent creates a new mock agent with the given configuration

func NewAgentWithConfig

func NewAgentWithConfig(mockConfig Config, abConfig agentboot.Config) *Agent

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

func (a *Agent) IsAvailable() bool

IsAvailable always returns true for mock agent

func (*Agent) SetAskUserQuestionFrequency

func (a *Agent) SetAskUserQuestionFrequency(freq int)

SetAskUserQuestionFrequency configures how often to send AskUserQuestion requests

func (*Agent) SetAutoApprove

func (a *Agent) SetAutoApprove(autoApprove bool)

SetAutoApprove configures auto-approval mode

func (*Agent) SetDefaultFormat

func (a *Agent) SetDefaultFormat(format agentboot.OutputFormat)

SetDefaultFormat sets the default output format

func (*Agent) SetMaxIterations

func (a *Agent) SetMaxIterations(max int)

SetMaxIterations configures the maximum number of iterations

func (*Agent) SetStepDelay

func (a *Agent) SetStepDelay(delay time.Duration)

SetStepDelay configures the delay between steps

func (*Agent) Type

func (a *Agent) Type() agentboot.AgentType

Type returns the mock agent type

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

func (Config) Merge

func (c Config) Merge(defaults Config) Config

Merge merges the given config with defaults

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL