Skip to content
Esc
↑↓navigate↵open⌘Jpreview
Start
On this page

Go API Reference

Complete API reference for the Autohand SDK Go. The SDK spawns the Autohand Code CLI as a subprocess and communicates over JSON-RPC.

Installation

go get github.com/autohandai/agent-sdk-go

Config

All fields are optional.

type Config struct {
    CWD            string
    CLIPath        string
    Debug          bool
    Timeout        int
    Model          string
    Provider       string
    APIKey         string
    BaseURL        string
    Temperature    float64
    PermissionMode string
    Skills         []SkillRef
    AutoSkill      bool
    ContextCompact bool
    MaxTokens      int
    SysPrompt      string
    AppendSysPrompt string
    PersistSession bool
    Resume         bool
    AdditionalDirectories []string
    EnvVars        map[string]string
    MCPServers     map[string]McpServerConfig
    ExtraArgs      []string
}

CLI 0.9.13 run options

Configure the CLI process through Config before startup.

  • MaxRequests, MaxDurationSeconds set the request budget and wall-clock limit in seconds.
  • AllowedTools, DisallowedTools accept lists of tool patterns.
  • Profile, SettingOverrides select a saved profile and apply ordered run-only overrides.
  • NoDaemon, SyncSettings, SearchEngine control background services, settings synchronization, and web search.

Use sdk.OnNotification and the packet’s Method and Params fields to read original CLI notifications. See run option semantics and notification payloads.

Low-Level API

AutohandSDK

sdk := autohand.NewSDK(&autohand.Config{...})
err := sdk.Start(ctx)
defer sdk.Close()

Prompting

err := sdk.Prompt(ctx, &autohand.PromptParams{Message: "Hello"})
events, err := sdk.StreamPrompt(ctx, &autohand.PromptParams{Message: "Hello"})

Control Methods

err := sdk.Interrupt(ctx)
err := sdk.SetPermissionMode(ctx, autohand.PermissionInteractive)
err := sdk.SetPlanMode(ctx, true)
err := sdk.SetModel(ctx, "openrouter/auto")
err := sdk.SetMaxThinkingTokens(ctx, 200000)
err := sdk.ApplyFlagSettings(ctx, &autohand.Config{...})

Information Methods

init, err := sdk.InitializationResult(ctx)
commands, err := sdk.SupportedCommands(ctx)
models, err := sdk.SupportedModels(ctx)
agents, err := sdk.SupportedAgents(ctx)
status, err := sdk.McpServerStatus(ctx)
usage, err := sdk.GetContextUsage(ctx)

High-Level API

Agent

agent, err := autohand.NewAgent(ctx, &autohand.Config{...})
defer agent.Close()
run, err := agent.Send(ctx, "Review this repo", nil)

Run

for event := range run.Stream(ctx) { ... }
result, err := run.Wait(ctx)
err := run.Abort(ctx)

CLI Runtime Control

Core lifecycle and auto-mode methods are available on Agent, SDK, and RPCClient. The extended control surface is available on SDK and RPCClient.

  • Lifecycle: Reset, CreateBrowserHandoff, AttachBrowserHandoff, AttachLatestBrowserHandoff.
  • Auto-mode: StartAutomode, GetAutomodeStatus, PauseAutomode, ResumeAutomode, CancelAutomode, GetAutomodeLog.
  • Approvals and sessions: AcknowledgePermission, RespondToDirectoryAccess, AcknowledgeDirectoryAccess, DecideChanges, GetHistory, GetSession, AttachSession.
  • Integrations: SetYolo, SetYoloAlias, SetVSCodeMCPTools, RespondToMCPInvocation, RecommendProjectLearning, UpdateProjectLearning, GenerateProjectSkill, GetToolsRegistry, SetContextCompact.

Read Control the Autohand Code CLI from every SDK for behavior, safety contracts, aliases, and the cross-language name map.

Events

StreamPrompt and Run.Stream return channels of typed events:

  • MessageUpdateEvent - Streaming assistant text delta
  • ToolStartEvent - Tool execution started
  • ToolEndEvent - Tool execution completed
  • PermissionRequestEvent - Runtime pause for approval
  • automode_iteration, automode_complete, and automode_error - Auto-mode lifecycle
  • ErrorEvent - Transport, runtime, or execution failure

See Hooks and events for the complete normalized event contract.

Error Handling

The SDK returns errors from the standard error interface.

See Also

Last updated on

Was this helpful?

Send Feedback

Help us improve this documentation page. Your feedback is valuable.

We'll only contact you if we need clarification