Documentation
¶
Overview ¶
Package agents provides interfaces and implementations for spawning AI agents. Unlike providers (which track usage), agents execute tasks autonomously.
claude.go implements the Agent interface for Claude Code CLI.
codex.go implements the Agent interface for OpenAI Codex CLI.
copilot.go implements the Agent interface for GitHub Copilot CLI.
Index ¶
- Constants
- type Agent
- type ClaudeAgent
- func (a *ClaudeAgent) Available() bool
- func (a *ClaudeAgent) Execute(ctx context.Context, opts ExecuteOptions) (*ExecuteResult, error)
- func (a *ClaudeAgent) ExecuteWithFiles(ctx context.Context, prompt string, files []string, workDir string) (*ExecuteResult, error)
- func (a *ClaudeAgent) Name() string
- func (a *ClaudeAgent) Version() (string, error)
- type ClaudeOption
- type CodexAgent
- func (a *CodexAgent) Available() bool
- func (a *CodexAgent) Execute(ctx context.Context, opts ExecuteOptions) (*ExecuteResult, error)
- func (a *CodexAgent) ExecuteWithFiles(ctx context.Context, prompt string, files []string, workDir string) (*ExecuteResult, error)
- func (a *CodexAgent) Name() string
- func (a *CodexAgent) Version() (string, error)
- type CodexOption
- type CommandRunner
- type CopilotAgent
- func (a *CopilotAgent) Available() bool
- func (a *CopilotAgent) Execute(ctx context.Context, opts ExecuteOptions) (*ExecuteResult, error)
- func (a *CopilotAgent) ExecuteWithFiles(ctx context.Context, prompt string, files []string, workDir string) (*ExecuteResult, error)
- func (a *CopilotAgent) Name() string
- func (a *CopilotAgent) Version() (string, error)
- type CopilotOption
- type ExecRunner
- type ExecuteOptions
- type ExecuteResult
Constants ¶
const DefaultTimeout = 30 * time.Minute
DefaultTimeout is the default agent execution timeout (30 minutes).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface {
// Name returns the agent identifier.
Name() string
// Execute runs a prompt and returns the output.
Execute(ctx context.Context, opts ExecuteOptions) (*ExecuteResult, error)
}
Agent is the interface for AI agent execution.
type ClaudeAgent ¶
type ClaudeAgent struct {
// contains filtered or unexported fields
}
ClaudeAgent spawns Claude Code CLI for task execution.
func NewClaudeAgent ¶
func NewClaudeAgent(opts ...ClaudeOption) *ClaudeAgent
NewClaudeAgent creates a Claude Code agent.
func (*ClaudeAgent) Available ¶
func (a *ClaudeAgent) Available() bool
Available checks if the claude binary is available in PATH.
func (*ClaudeAgent) Execute ¶
func (a *ClaudeAgent) Execute(ctx context.Context, opts ExecuteOptions) (*ExecuteResult, error)
Execute runs claude --print with the given prompt.
func (*ClaudeAgent) ExecuteWithFiles ¶
func (a *ClaudeAgent) ExecuteWithFiles(ctx context.Context, prompt string, files []string, workDir string) (*ExecuteResult, error)
ExecuteWithFiles runs claude with file context included.
func (*ClaudeAgent) Version ¶
func (a *ClaudeAgent) Version() (string, error)
Version returns the claude CLI version.
type ClaudeOption ¶
type ClaudeOption func(*ClaudeAgent)
ClaudeOption configures a ClaudeAgent.
func WithBinaryPath ¶
func WithBinaryPath(path string) ClaudeOption
WithBinaryPath sets a custom path to the claude binary.
func WithDangerouslySkipPermissions ¶
func WithDangerouslySkipPermissions(enabled bool) ClaudeOption
WithDangerouslySkipPermissions sets whether to pass --dangerously-skip-permissions.
func WithDefaultTimeout ¶
func WithDefaultTimeout(d time.Duration) ClaudeOption
WithDefaultTimeout sets the default execution timeout.
func WithRunner ¶
func WithRunner(r CommandRunner) ClaudeOption
WithRunner sets a custom command runner (for testing).
type CodexAgent ¶
type CodexAgent struct {
// contains filtered or unexported fields
}
CodexAgent spawns Codex CLI for task execution.
func NewCodexAgent ¶
func NewCodexAgent(opts ...CodexOption) *CodexAgent
NewCodexAgent creates a Codex CLI agent.
func (*CodexAgent) Available ¶
func (a *CodexAgent) Available() bool
Available checks if the codex binary is available in PATH.
func (*CodexAgent) Execute ¶
func (a *CodexAgent) Execute(ctx context.Context, opts ExecuteOptions) (*ExecuteResult, error)
Execute runs codex with the given prompt in non-interactive mode.
func (*CodexAgent) ExecuteWithFiles ¶
func (a *CodexAgent) ExecuteWithFiles(ctx context.Context, prompt string, files []string, workDir string) (*ExecuteResult, error)
ExecuteWithFiles runs codex with file context included.
func (*CodexAgent) Version ¶
func (a *CodexAgent) Version() (string, error)
Version returns the codex CLI version.
type CodexOption ¶
type CodexOption func(*CodexAgent)
CodexOption configures a CodexAgent.
func WithCodexBinaryPath ¶
func WithCodexBinaryPath(path string) CodexOption
WithCodexBinaryPath sets a custom path to the codex binary.
func WithCodexDefaultTimeout ¶
func WithCodexDefaultTimeout(d time.Duration) CodexOption
WithCodexDefaultTimeout sets the default execution timeout.
func WithCodexRunner ¶
func WithCodexRunner(r CommandRunner) CodexOption
WithCodexRunner sets a custom command runner (for testing).
func WithDangerouslyBypassApprovalsAndSandbox ¶
func WithDangerouslyBypassApprovalsAndSandbox(enabled bool) CodexOption
WithDangerouslyBypassApprovalsAndSandbox sets whether to pass --dangerously-bypass-approvals-and-sandbox.
type CommandRunner ¶
type CommandRunner interface {
Run(ctx context.Context, name string, args []string, dir string, stdin string) (stdout, stderr string, exitCode int, err error)
}
CommandRunner executes shell commands. Allows mocking in tests.
type CopilotAgent ¶ added in v0.3.3
type CopilotAgent struct {
// contains filtered or unexported fields
}
CopilotAgent spawns GitHub Copilot CLI for task execution.
GitHub Copilot CLI implementation notes: - Supports both 'gh copilot' (passthrough to copilot binary) and standalone 'copilot' binary - Non-interactive mode: use -p/--prompt flag (exits after completion) - Uses --no-ask-user to disable the ask_user tool (fully autonomous) - Uses --silent to output only the agent response (no stats)
Install options: - Via gh: gh copilot (downloads copilot binary automatically if not in PATH) - Standalone: npm install -g @github/copilot or curl script - Usage: copilot -p "<prompt>" --no-ask-user --silent
func NewCopilotAgent ¶ added in v0.3.3
func NewCopilotAgent(opts ...CopilotOption) *CopilotAgent
NewCopilotAgent creates a GitHub Copilot CLI agent.
func (*CopilotAgent) Available ¶ added in v0.3.3
func (a *CopilotAgent) Available() bool
Available checks if the gh binary is available in PATH and copilot extension is installed.
func (*CopilotAgent) Execute ¶ added in v0.3.3
func (a *CopilotAgent) Execute(ctx context.Context, opts ExecuteOptions) (*ExecuteResult, error)
Execute runs the Copilot CLI with the given prompt in non-interactive mode.
Both 'gh copilot' and standalone 'copilot' use the same -p flag interface. For 'gh copilot', '--' is used to pass flags through to the copilot binary.
func (*CopilotAgent) ExecuteWithFiles ¶ added in v0.3.3
func (a *CopilotAgent) ExecuteWithFiles(ctx context.Context, prompt string, files []string, workDir string) (*ExecuteResult, error)
ExecuteWithFiles runs gh copilot with file context included.
func (*CopilotAgent) Name ¶ added in v0.3.3
func (a *CopilotAgent) Name() string
Name returns "copilot".
func (*CopilotAgent) Version ¶ added in v0.3.3
func (a *CopilotAgent) Version() (string, error)
Version returns the copilot CLI version.
type CopilotOption ¶ added in v0.3.3
type CopilotOption func(*CopilotAgent)
CopilotOption configures a CopilotAgent.
func WithCopilotBinaryPath ¶ added in v0.3.3
func WithCopilotBinaryPath(path string) CopilotOption
WithCopilotBinaryPath sets a custom path to the copilot binary ("gh" or "copilot").
func WithCopilotDangerouslySkipPermissions ¶ added in v0.3.4
func WithCopilotDangerouslySkipPermissions(enabled bool) CopilotOption
WithCopilotDangerouslySkipPermissions sets whether to pass --allow-all-tools and --allow-all-urls.
func WithCopilotDefaultTimeout ¶ added in v0.3.3
func WithCopilotDefaultTimeout(d time.Duration) CopilotOption
WithCopilotDefaultTimeout sets the default execution timeout.
func WithCopilotRunner ¶ added in v0.3.3
func WithCopilotRunner(r CommandRunner) CopilotOption
WithCopilotRunner sets a custom command runner (for testing).
type ExecuteOptions ¶
type ExecuteOptions struct {
Prompt string // The prompt/task for the agent
WorkDir string // Working directory for execution
Files []string // Optional file paths to include as context
Timeout time.Duration // Execution timeout (0 = default)
}
ExecuteOptions configures an agent execution.
type ExecuteResult ¶
type ExecuteResult struct {
Output string // Agent's text output
JSON []byte // Structured JSON output if available
ExitCode int // Process exit code
Duration time.Duration // Execution duration
Error string // Error message if failed
}
ExecuteResult holds the outcome of an agent execution.
func (*ExecuteResult) IsSuccess ¶
func (r *ExecuteResult) IsSuccess() bool
IsSuccess returns true if the execution succeeded.