Help us shape the future of Go! Take the 2026 Go Developer Survey

agent

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package agent provides a Go SDK for writing agents that run on agent-orca.

The SDK talks to the run's model-router (OPENAI_BASE_URL). The router keeps the conversation, injects the Agent's system prompt, and runs the Agent's tools and the built-in lifecycle tools (_done, _fail, _clarify, _handoff, _spawn, ...). Tools registered with Agent.Tool run in the agent process instead, e.g. a shell inside the agent's sandbox; they need spec.runtime.localTools on the Agent (docs/agent-run-tools.md).

Example::

a := agent.New()
a.Tool("search", "Search the web", params, func(args map[string]any) (string, error) {
    return "results", nil
})
result, err := a.Run(context.Background(), "Find the latest news about LLMs")
if err != nil {
    log.Fatal(err)
}
fmt.Println(result.Phase, result.Output)

Index

Constants

View Source
const (
	PhaseSucceeded       = "Succeeded"
	PhaseFailed          = "Failed"
	PhaseHandedOff       = "HandedOff"
	PhaseWaitingForInput = "WaitingForInput"
)

Run phases, matching the AgentRun phases they lead to.

Variables

View Source
var ErrMaxTurns = errors.New("max turns exceeded")

ErrMaxTurns is returned in RunResult.FailureReason when the turn limit is hit.

Functions

func Input added in v0.9.0

func Input() string

Input returns the run's input (AGENTORC_INPUT). In a sandbox, a multi-line input arrives base64-encoded in AGENTORC_INPUT_B64, because the sandbox gateway accepts no line breaks in environment values, while AGENTORC_INPUT holds a one-line version; Input prefers the exact one.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent is the Go SDK for writing agents that run on agent-orca.

func New

func New(opts ...Option) *Agent

New creates a new Agent with the given options.

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 the model ends the turn with text (see WithContinuePrompt) or the router closes the run.

func (*Agent) RunStream

func (a *Agent) RunStream(ctx context.Context, input string) (<-chan string, <-chan error)

RunStream sends input as a single turn and streams the reply's text. It does not run tools; use Run for that.

func (*Agent) Tool

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

Tool registers a tool the agent process runs. Its name must not start with "_" or match a router tool; the router rejects such requests.

type Option

type Option func(*Agent)

Option configures an Agent.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the bearer token for the router (default $OPENAI_API_KEY).

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the model-router endpoint URL (default $OPENAI_BASE_URL, else http://localhost:8080/v1).

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets a custom HTTP client. A turn streams for as long as the router's tool loop runs, so avoid a client-wide Timeout; use the context.

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 model identifier sent with each request. The router chooses the provider, so this is usually left unset.

func WithSystemPrompt

func WithSystemPrompt(prompt string) Option

WithSystemPrompt sets a system instruction sent with the first request, in addition to the Agent's spec.systemPrompt, which the router injects.

func WithTemperature

func WithTemperature(t float64) Option

WithTemperature sets the sampling temperature.

func WithToolObserver added in v0.9.0

func WithToolObserver(fn func(ToolEvent)) Option

WithToolObserver calls fn after each tool call the agent runs, e.g. to log progress.

type RunOption

type RunOption func(*runConfig)

RunOption configures a Run call.

func WithContinuePrompt added in v0.9.0

func WithContinuePrompt(prompt string) RunOption

WithContinuePrompt keeps the run going when the model replies with text instead of a tool call: prompt is sent as the next user message. The run then ends only when the model calls a lifecycle tool (_done, _fail, ...), which the router reports by closing the run. Without it, a text reply ends the run.

func WithMaxTurns

func WithMaxTurns(n int) RunOption

WithMaxTurns sets the maximum number of requests to the router (default 200).

type RunResult

type RunResult struct {
	// Output is the model's last text reply.
	Output string
	// Phase is one of the Phase* constants.
	Phase string
	// FailureReason explains a Failed phase.
	FailureReason string
}

RunResult is the final result of an agent run.

type ToolEvent added in v0.9.0

type ToolEvent struct {
	Name      string
	Arguments string
	Result    string
	Duration  time.Duration
}

ToolEvent describes one tool call the agent ran.

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.

Directories

Path Synopsis
Package devtools gives a coding agent a shell and file tools over one workspace directory: shell, read_file, write_file, edit_file, list_dir and grep.
Package devtools gives a coding agent a shell and file tools over one workspace directory: shell, read_file, write_file, edit_file, list_dir and grep.

Jump to

Keyboard shortcuts

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