agent-sdk-go

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0

README

agent-sdk-go

Go clients for the Codex app-server and Claude Code CLI. Both SDKs use the github.com/zoumo/agent-sdk-go module and require Go 1.26 or newer.

If you need Use Get started
Codex protocol types, turn operations, or saved thread queries github.com/zoumo/agent-sdk-go/codex Codex SDK
Claude protocol types, CLI options, or saved session queries github.com/zoumo/agent-sdk-go/claude Claude SDK
The same live session API for Codex and Claude github.com/zoumo/agent-sdk-go/agent and one adapter per Core Run the unified session example

The native SDKs have separate codex/types and claude/types packages. Use the native SDK for protocol-specific controls and saved history even when your application uses agent for live sessions. See the dependency rules.

If you are Read
Moving from the earlier standalone modules Migration guide
Testing an SDK change Validation guide
Running an SDK against a recorded case Simulation guide
Looking up contracts or terms Documentation index, glossary
Preparing a release Release checks, licenses and attribution

Optional unified live layer

Run the example from the repository root. The example uses synthetic providers.

go test -count=1 -v ./agent -run '^ExampleCore$'

The test passes after both providers report a reply, close the session, resume it by its saved ID, and stop. Follow the same lifecycle in your application. ExampleCore source and expected output

  1. Create a Core with agentcodex.New or agentclaude.New. Call Core.Start to initialize it and get its capabilities.
  2. Call Core.Open with an absolute OpenOptions.Cwd. To restore an existing native session, call Core.Resume with its saved SessionID and the open options. Use the native SDK to read saved content.
  3. Call Session.Events once. Assign one consumer to read the event stream with Next and distribute events to the rest of your application.
  4. Call Session.StartOrSteer to submit input. Check the receipt before correlating events with the submission. If the result is InputNotApplied, your application still owns the input and controls any retry.
  5. When an InteractionRequestedPayload arrives, show the request to your user or apply your application's policy. Send the resulting answer to Session.Answer with the original Interaction reference. For a permission answer, use the OptionID of the selected option. The offline example uses allow-once for its synthetic request.
  6. Consume events until your application has the result it needs. Session state such as idle describes the session. Use the input receipt and the relevant events for submission-specific evidence.
  7. Call Session.Close to release each session, then call Core.Stop. Core.Stop rejects the call while a session is open or an open or resume operation is in progress.

Read your adapter's package docs for setup and capabilities. Codex adapter · Claude adapter

Unified Claude Open returns the native session ID from claim_session before the first input. Local startup checks for a stable Claude CLI at version 2.1.293 or newer. Session identity and startup contract

To append context without requesting a model response, check whether the session implements agent.Injector, then call Inject. The receipt records acceptance. An unsupported native version returns agent.ErrorUnsupported. Context injection contract

Restrict local tools

Set OpenOptions.Features.RestrictLocalTools when you open or resume a session. Session.EffectiveFeatures reports whether the adapter configured its native restrictions. Claude sends a tool deny list. Codex disables the shell, image viewing, and image generation features. The Codex mapping still permits other local capabilities, including apply_patch where the model exposes it. Mappings and limits

Additional system prompt

Set OpenOptions.AdditionalSystemPrompt to add text to the native system prompt. Supply the value on each Open or Resume call that needs it. Additional system prompt contract

External MCP servers

Set OpenOptions.MCPServers to the full list of external servers for an Open or Resume call. Declare each server as mcp.TransportStdio or mcp.TransportHTTP. If your application combines runtime defaults with session settings, compose the list before calling the Core. Match names case-sensitively and replace a same-name server as a whole. Send the full list again on resume.

Run the offline configuration example from the repository root. The test validates the declared fields for both transports.

go test -count=1 -v ./agent -run '^ExampleOpenOptions_mcpServers$'

If your application requires a fixed set of servers, isolate the native configuration. Verify connectivity and tool availability through the native provider after opening the session. Check provider support and configuration precedence before adding credentials or resuming a session. Codex MCP options · Claude MCP options · Unified MCP contract · Example source

Directories

Path Synopsis
Package agent defines the optional adapter-neutral contract for one live Agent session.
Package agent defines the optional adapter-neutral contract for one live Agent session.
claude
Package agentclaude adapts the native Claude Session to the adapter-neutral live agent contract.
Package agentclaude adapts the native Claude Session to the adapter-neutral live agent contract.
codex
Package agentcodex adapts the native Codex app-server SDK to the optional adapter-neutral agent runtime contract.
Package agentcodex adapts the native Codex app-server SDK to the optional adapter-neutral agent runtime contract.
internal/corelease
Package corelease owns the Core-scoped state shared by unified Agent adapters.
Package corelease owns the Core-scoped state shared by unified Agent adapters.
internal/eventenvelope
Package eventenvelope builds validated adapter-neutral event envelopes.
Package eventenvelope builds validated adapter-neutral event envelopes.
internal/interactionledger
Package interactionledger owns adapter-neutral interaction authority state.
Package interactionledger owns adapter-neutral interaction authority state.
internal/submissiontrace
Package submissiontrace owns the best-effort span lifecycle of one admitted unified submission.
Package submissiontrace owns the best-effort span lifecycle of one admitted unified submission.
internal/telemetry
Package telemetry instruments the public operations of the unified adapters.
Package telemetry instruments the public operations of the unified adapters.
Package claude provides an independent native Session over an explicitly selected local Claude Code process.
Package claude provides an independent native Session over an explicitly selected local Claude Code process.
examples/remote-execution-offline command
This example demonstrates how Claude can retain external MCP tools while disabling ordinary built-in tools.
This example demonstrates how Claude can retain external MCP tools while disabling ordinary built-in tools.
examples/session-messages-offline command
This example creates synthetic saved content and queries it without Claude.
This example creates synthetic saved content and queries it without Claude.
examples/session-metadata-offline command
This example discovers synthetic saved sessions without a Claude runtime.
This example discovers synthetic saved sessions without a Claude runtime.
examples/subagents-offline command
This example runs only its own synthetic peer, never an installed Claude CLI.
This example runs only its own synthetic peer, never an installed Claude CLI.
tests/replay
SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: Apache-2.0
types
Package types provides the SDK's pure event, content, permission-answer, and callback-free configuration data, plus the existing JSON decoding codecs.
Package types provides the SDK's pure event, content, permission-answer, and callback-free configuration data, plus the existing JSON decoding codecs.
Package codex provides native long-running Sessions over Codex app-server.
Package codex provides native long-running Sessions over Codex app-server.
examples/apiusage
Package apiusage contains compile-checked examples.
Package apiusage contains compile-checked examples.
examples/history-query-offline command
history-query-offline uses a synthetic subprocess, never an installed agent.
history-query-offline uses a synthetic subprocess, never an installed agent.
examples/observe-subagents-offline command
This executable talks only to a synthetic copy of itself, never to Codex.
This executable talks only to a synthetic copy of itself, never to Codex.
examples/observe-turn command
Observe a managed root and descendants on an explicitly chosen executable.
Observe a managed root and descendants on an explicitly chosen executable.
examples/remote-execution-offline command
This example demonstrates a best-effort remote MCP profile for Codex.
This example demonstrates a best-effort remote MCP profile for Codex.
examples/resume-thread command
Command resume-thread explicitly opens a fresh connection, resumes a native ID already known to the caller, reads it, and detaches server-side observation.
Command resume-thread explicitly opens a fresh connection, resumes a native ID already known to the caller, reads it, and detaches server-side observation.
tests/replay
SDK-specific fixtures and process adapters; native protocol matching belongs to the tool.
SDK-specific fixtures and process adapters; native protocol matching belongs to the tool.
types
Package types exposes native app-server parameters, results, and recursive model types from the exact official Codex revision recorded in the generated source.
Package types exposes native app-server parameters, results, and recursive model types from the exact official Codex revision recorded in the generated source.
internal
lineage
Package lineage maintains bounded, confirmed parent relationships.
Package lineage maintains bounded, confirmed parent relationships.
mocktest
Package mocktest bridges Go SDK fixture assertions to the in-process testify library.
Package mocktest bridges Go SDK fixture assertions to the in-process testify library.
queue
Package queue adapts ChannX to typed event streams, with atomic admission and explicit drain/abort lifecycle.
Package queue adapts ChannX to typed event streams, with atomic admission and explicit drain/abort lifecycle.
uuidv4
Package uuidv4 creates random RFC 4122 version 4 identifiers.
Package uuidv4 creates random RFC 4122 version 4 identifiers.
Package mcp defines one external MCP server configuration shared by the native Codex and Claude SDKs and the adapter-neutral agent layer.
Package mcp defines one external MCP server configuration shared by the native Codex and Claude SDKs and the adapter-neutral agent layer.
tests
simulation/drivers command
Explicit offline Go SDK acceptance entry.
Explicit offline Go SDK acceptance entry.
simulation/simulate
SDK-owned offline simulation.
SDK-owned offline simulation.

Jump to

Keyboard shortcuts

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