Documentation
¶
Overview ¶
Package agent provides a Go SDK for writing agents that run on agent-orca.
The SDK wraps an OpenAI-compatible client pointed at the model-router sidecar (http://localhost:8080 by default) and provides Go-idiomatic helpers for the built-in lifecycle tools (_done, _fail, _clarify, _handoff, _spawn).
Example::
agent := agent.New(agent.WithSystemPrompt("You are a helpful assistant."))
agent.Tool("search", "Search the web", func(args map[string]any) (string, error) {
return "results", nil
})
result, err := agent.Run(context.Background(), "Find the latest news about LLMs")
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Output)
Index ¶
- Variables
- type Agent
- func (a *Agent) Ask(question string) map[string]any
- func (a *Agent) Done(output string) map[string]any
- func (a *Agent) Fail(reason string, retryable bool) map[string]any
- func (a *Agent) Handoff(agentRef, input string) map[string]any
- func (a *Agent) LoadCheckpoint(sessionID string) []map[string]string
- func (a *Agent) Run(ctx context.Context, input string, opts ...RunOption) (*RunResult, error)
- func (a *Agent) RunStream(ctx context.Context, input string, opts ...RunOption) (<-chan string, <-chan error)
- func (a *Agent) SaveCheckpoint(sessionID string, messages []map[string]string) string
- func (a *Agent) Spawn(agentRef, input string, timeoutSeconds int) map[string]any
- func (a *Agent) Tool(name, description string, params map[string]any, handler ToolHandler)
- type Option
- type RunOption
- type RunResult
- type ToolHandler
- type ToolSpec
Constants ¶
This section is empty.
Variables ¶
var ErrNoTool = errors.New("tool not found")
ErrNoTool is returned when a tool is not found.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the Go SDK for writing agents that run on agent-orca. It wraps an OpenAI-compatible client pointed at the model-router sidecar and provides built-in lifecycle tool helpers.
func New ¶
New creates a new Agent with the given options. Defaults to http://localhost:8080 (the model-router sidecar).
func (*Agent) LoadCheckpoint ¶
LoadCheckpoint loads conversation history from the checkpoint store. This is a stub — in production, the model-router handles checkpoint loading via PriorRunRef.
func (*Agent) RunStream ¶
func (a *Agent) RunStream(ctx context.Context, input string, opts ...RunOption) (<-chan string, <-chan error)
RunStream executes the agent and streams the output tokens for a single turn.
func (*Agent) SaveCheckpoint ¶
SaveCheckpoint saves conversation history to the checkpoint store. This is a stub — in production, the model-router handles checkpointing automatically every N turns.
type Option ¶
type Option func(*Agent)
Option configures an Agent.
func WithAPIKey ¶
WithAPIKey sets the API key for the OpenAI-compatible endpoint.
func WithBaseURL ¶
WithBaseURL overrides the model-router endpoint URL.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithMaxTokens ¶
WithMaxTokens sets the maximum tokens to generate per turn.
func WithSystemPrompt ¶
WithSystemPrompt sets the system instruction.
func WithTemperature ¶
WithTemperature sets the sampling temperature.
type RunOption ¶
type RunOption func(*runConfig)
RunOption configures a Run call.
func WithMaxTurns ¶
WithMaxTurns sets the maximum number of LLM turns.
type RunResult ¶
type RunResult struct {
Output string
Phase string
SpendUSD string
FailureReason string
CompletedAt string
Raw map[string]any
}
RunResult is the final result of an agent run.
type ToolHandler ¶
ToolHandler is the function signature for a custom tool handler. It receives the parsed arguments as a map and returns a string result.