agent

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func New(opts ...Option) *Agent

New creates a new Agent with the given options. Defaults to http://localhost:8080 (the model-router sidecar).

func (*Agent) Ask

func (a *Agent) Ask(question string) map[string]any

Ask asks the user for clarification.

func (*Agent) Done

func (a *Agent) Done(output string) map[string]any

Done signals that the task is complete.

func (*Agent) Fail

func (a *Agent) Fail(reason string, retryable bool) map[string]any

Fail signals an unrecoverable failure.

func (*Agent) Handoff

func (a *Agent) Handoff(agentRef, input string) map[string]any

Handoff hands off the task to another agent.

func (*Agent) LoadCheckpoint

func (a *Agent) LoadCheckpoint(sessionID string) []map[string]string

LoadCheckpoint loads conversation history from the checkpoint store. This is a stub — in production, the model-router handles checkpoint loading via PriorRunRef.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, input string, opts ...RunOption) (*RunResult, error)

Run executes the agent on the given input until a terminal state.

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

func (a *Agent) SaveCheckpoint(sessionID string, messages []map[string]string) string

SaveCheckpoint saves conversation history to the checkpoint store. This is a stub — in production, the model-router handles checkpointing automatically every N turns.

func (*Agent) Spawn

func (a *Agent) Spawn(agentRef, input string, timeoutSeconds int) map[string]any

Spawn spawns a child agent.

func (*Agent) Tool

func (a *Agent) Tool(name, description string, params map[string]any, handler ToolHandler)

Tool registers a custom tool that the LLM can call.

type Option

type Option func(*Agent)

Option configures an Agent.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the API key for the OpenAI-compatible endpoint.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the model-router endpoint URL.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithMaxTokens

func WithMaxTokens(n int) Option

WithMaxTokens sets the maximum tokens to generate per turn.

func WithModel

func WithModel(model string) Option

WithModel sets the default model identifier.

func WithSystemPrompt

func WithSystemPrompt(prompt string) Option

WithSystemPrompt sets the system instruction.

func WithTemperature

func WithTemperature(t float64) Option

WithTemperature sets the sampling temperature.

type RunOption

type RunOption func(*runConfig)

RunOption configures a Run call.

func WithMaxTurns

func WithMaxTurns(n int) RunOption

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

type ToolHandler func(args map[string]any) (string, error)

ToolHandler is the function signature for a custom tool handler. It receives the parsed arguments as a map and returns a string result.

type ToolSpec

type ToolSpec struct {
	Name        string
	Description string
	Parameters  map[string]any
	Handler     ToolHandler
}

ToolSpec describes a tool callable by the LLM.

Jump to

Keyboard shortcuts

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