agent-sdk-go

module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0

README ΒΆ

Agent SDK for Go

CI Release Go Reference License Mentioned in Awesome Go

AI agents that keep running even when your process doesn't β€” powered by Temporal.

Open-source Go SDK for building AI agents β€” run in-process with zero setup, or on Temporal for crash-resilient, distributed execution that survives restarts and deploys. Every core component is a pluggable interface, so nothing is locked in.

πŸ“– Documentation Β Β·Β  Quickstart Β Β·Β  Examples

Versioning: Semantic versioning; releases are git tags. See the latest release.

Independent community library β€” not affiliated with Temporal Technologies.

Install

go get github.com/agenticenv/agent-sdk-go@latest

Go 1.26+. No infrastructure required for in-process mode. A running Temporal server is required for durable execution.

Quick Start

In-process (zero setup):

import (
    "context"
    "fmt"
    "time"

    "github.com/agenticenv/agent-sdk-go/pkg/agent"
    "github.com/agenticenv/agent-sdk-go/pkg/llm"
    "github.com/agenticenv/agent-sdk-go/pkg/llm/openai"
)

// errors omitted for brevity
llmClient, _ := openai.NewClient(
    llm.WithAPIKey("sk-..."),
    llm.WithModel("gpt-4o"),
)

a, _ := agent.NewAgent(
    agent.WithSystemPrompt("You are a helpful assistant."),
    agent.WithLLMClient(llmClient),
)
defer a.Close()

// --- Run ---
run, _ := a.Run(context.Background(), "Reply with a short greeting.", nil)
result, _ := run.Get(context.Background())
fmt.Println(result.Content)

// --- Non-blocking ---
run, _ = a.Run(context.Background(), "Explain durable agents in two short paragraphs.", nil)
select {
case <-run.Done():
    result, _ = run.Get(context.Background())
    fmt.Println(result.Content)
case <-time.After(5 * time.Second):
    fmt.Println("still running, check back later")
}

// --- Stream (AG-UI events: text deltas, tools, approvals, lifecycle, …) ---
stream, _ := a.Stream(context.Background(), "Write a four-line poem about the ocean.", nil)
events, _ := stream.Events(context.Background())
for event := range events {
    switch e := event.(type) {
    case *agent.AgentTextMessageContentEvent:
        fmt.Print(e.Delta)
    case *agent.AgentToolCallStartEvent:
        fmt.Println("\n[tool call]", e.ToolCallName)
    case *agent.AgentCustomEvent:
        // tool / delegation approval (when approval policy requires it)
        if e.Name == string(agent.AgentCustomEventNameToolApproval) {
            if v, err := agent.ParseCustomEventApproval(e); err == nil {
                // replace with real approval logic β€” this auto-approves for demonstration
                _ = stream.Approve(context.Background(), v.ApprovalToken, agent.ApprovalStatusApproved)
            }
        }
    // also RunFinished, ToolCallResult, …
    }
}

Temporal (durable execution):

a, _ := agent.NewAgent(
    agent.WithSystemPrompt("You are a helpful assistant."),
    agent.WithLLMClient(llmClient),
    agent.WithTemporalConfig(&agent.TemporalConfig{
        Host:      "localhost",
        Port:      7233,
        Namespace: "default",
        TaskQueue: "agent-task-queue",
    }),
)
defer a.Close()

// --- Run ---
run, _ := a.Run(context.Background(), "Reply with a short greeting.", nil)
result, _ := run.Get(context.Background())
fmt.Println(result.Content)

// --- Non-blocking ---
run, _ = a.Run(context.Background(), "Explain durable agents in two short paragraphs.", nil)
select {
case <-run.Done():
    result, _ = run.Get(context.Background())
    fmt.Println(result.Content)
case <-time.After(5 * time.Second):
    fmt.Println("still running, check back later")
}

// --- Stream (AG-UI events: text deltas, tools, approvals, lifecycle, …) ---
stream, _ := a.Stream(context.Background(), "Write a four-line poem about the ocean.", nil)
savedRunID := stream.ID() // persist before consuming events
events, _ := stream.Events(context.Background())
for event := range events {
    // persist event.Offset() before handling β€” needed for WithOffset on reconnect
    _ = event
}

// --- Reconnect after a process crash ---
// replace with last persisted offset from your storage
savedOffset := int64(0)
s, _ := a.GetAgentStream(context.Background(), savedRunID)
ch, _ := s.Events(context.Background(), agent.WithOffset(savedOffset))
for event := range ch {
    _ = event
}

Crashes and process restarts don't have to mean lost work or missed approvals β€” the durable agent example shows how a run keeps executing durably even if your process crashes, and how to reconnect to an active run and stream its remaining events once it's back. For the stream reconnect protocol (GetAgentStream + WithOffset), see the reconnect example.

Features

  • LLM providers β€” OpenAI, Anthropic, Gemini, DeepSeek, Ollama (local) + custom via interfaces.LLMClient
  • Tools & MCP β€” built-in and custom tools; MCP servers over stdio or streamable HTTP
  • A2A β€” expose agents as A2A servers or connect remote A2A agents as tools
  • Sub-agents β€” delegate to specialist agents with independent LLMs, tools, and task queues
  • Human-in-the-loop approvals β€” gate tool calls, MCP invocations, and delegation
  • Conversation history β€” multi-turn sessions via in-memory or Redis backends
  • Memory & RAG β€” long-term scoped memory and retrieval-augmented generation
  • Streaming & AG-UI β€” partial token streaming; AG-UI protocol for frontend integration
  • Reasoning β€” extended thinking on Anthropic, Gemini, DeepSeek, and OpenAI reasoning models
  • Token usage β€” aggregate prompt, completion, and reasoning token counts per run
  • Hooks & guardrails β€” middleware at LLM, tool, retrieval, and memory lifecycle points
  • Execution config β€” per-operation timeouts and max attempts via With*ExecutionConfig
  • Durable execution β€” crash-resilient runs via Temporal; reconnect to active runs and resume event streams after a restart
  • Distributed execution β€” leverage Temporal to decouple client triggers from worker execution, scaling agent workloads horizontally across separate processes or nodes.
  • Observability β€” OpenTelemetry traces, metrics, and structured logs

CLI (agctl)

Download a binary from GitHub Releases, extract it, and put agctl on your PATH.

export AGCTL_LLM_APIKEY=sk-your-key
agctl run --model gpt-4o --prompt "hello"
# or interactive
agctl chat

See the CLI docs for commands, config, and env vars.

Reference Apps

  • Agent Chat β€” web chat demo with durable conversations; reference for wiring the SDK into an HTTP-backed app.

Examples

Runnable examples in [examples/](examples/) β€” see [examples/README.md](examples/README.md) for setup and run instructions.

Benchmarks

Config-driven benchmark runner β€” see benchmarks/README.md

Eval Harness

Evaluate agent quality with Promptfoo and DeepEval β€” locally or in CI. See eval-harness/README.md

Development

See CONTRIBUTING.md for setup, workflow, and guidelines. Project policies: SECURITY.md Β· CODE_OF_CONDUCT.md

Quick commands (requires Task): task check | task test | task lint | task fmt | task tidy | task test-coverage

Coverage reports (PR and default branch) are on Codecov. Run task test-coverage locally to produce coverage.out and coverage.html.

License

Apache 2.0

Disclaimer

This project is provided "as is" under the Apache License 2.0. When building AI agents that execute real-world actions, ensure appropriate safeguards, validation, and human-in-the-loop approval workflows are in place. You are responsible for compliance, access control, and operational safety in your deployment. For security issues, follow SECURITY.md.

Directories ΒΆ

Path Synopsis
worker command
eval-harness
runner command
agent_with_code_execution command
Package main implements a CodeTool that lets the LLM write and execute code inside an agent run.
Package main implements a CodeTool that lets the LLM write and execute code inside an agent run.
agent_with_concurrent_runs command
agent_with_concurrent_runs shows multiple Run calls dispatched concurrently on a single Agent instance.
agent_with_concurrent_runs shows multiple Run calls dispatched concurrently on a single Agent instance.
agent_with_execution_config command
Package main demonstrates execution config.
Package main demonstrates execution config.
agent_with_hooks command
Example agent demonstrating all middleware hook points.
Example agent demonstrating all middleware hook points.
agent_with_memory/common
Package common holds shared configuration and agent options for the agent_with_memory examples.
Package common holds shared configuration and agent options for the agent_with_memory examples.
agent_with_memory/pgvector command
Example agent using PostgreSQL pgvector for long-term memory.
Example agent using PostgreSQL pgvector for long-term memory.
agent_with_memory/weaviate command
Example agent using Weaviate for long-term memory.
Example agent using Weaviate for long-term memory.
agent_with_nonblocking_run command
agent_with_nonblocking_run demonstrates non-blocking Agent.Run: start the run, poll AgentRun.Status while waiting, optionally Cancel after a few polls, wait on Done(), then Get.
agent_with_nonblocking_run demonstrates non-blocking Agent.Run: start the run, poll AgentRun.Status while waiting, optionally Cancel after a few polls, wait on Done(), then Get.
agent_with_observability/config command
OTLP via agent.WithObservabilityConfig β€” the SDK constructs tracer, metrics, and logs (OTLP log export for the default SDK logger via the slog bridge; internal default batching/export timing).
OTLP via agent.WithObservabilityConfig β€” the SDK constructs tracer, metrics, and logs (OTLP log export for the default SDK logger via the slog bridge; internal default batching/export timing).
agent_with_observability/objects command
OTLP via pre-built observability.NewTracer, observability.NewMetrics, observability.NewLogs, then agent.WithTracer, agent.WithMetrics, agent.WithLogs.
OTLP via pre-built observability.NewTracer, observability.NewMetrics, observability.NewLogs, then agent.WithTracer, agent.WithMetrics, agent.WithLogs.
agent_with_observability/setup
Package setup shares OTLP env parsing and base agent options for the config/ and objects/ examples.
Package setup shares OTLP env parsing and base agent options for the config/ and objects/ examples.
agent_with_reconnect/agent command
agent_with_reconnect demonstrates Agent.GetAgentStream: how to subscribe to a prior run's Temporal Workflow Streams event log from a saved offset, simulating a mid-run crash and recovery in a single process.
agent_with_reconnect demonstrates Agent.GetAgentStream: how to subscribe to a prior run's Temporal Workflow Streams event log from a saved offset, simulating a mid-run crash and recovery in a single process.
agent_with_reconnect/worker command
Worker process for the agent_with_reconnect example.
Worker process for the agent_with_reconnect example.
agent_with_retriever/common
Package common holds shared configuration and agent options for the agent_with_retriever examples.
Package common holds shared configuration and agent options for the agent_with_retriever examples.
agent_with_retriever/pgvector command
Example agent using a PostgreSQL pgvector retriever.
Example agent using a PostgreSQL pgvector retriever.
agent_with_retriever/weaviate command
Example agent using a Weaviate vector retriever.
Example agent using a Weaviate vector retriever.
agent_with_temporal_client command
agent_with_temporal_client demonstrates using WithTemporalClient to pass a pre-configured Temporal client to the agent.
agent_with_temporal_client demonstrates using WithTemporalClient to pass a pre-configured Temporal client to the agent.
agent_with_worker/agent command
Interactive streaming REPL for the agent_with_worker example.
Interactive streaming REPL for the agent_with_worker example.
agent_with_workflows command
agent_with_workflows demonstrates deterministic workflow execution inside an agent.
agent_with_workflows demonstrates deterministic workflow execution inside an agent.
durable_agent/agent command
Interactive streaming REPL for the durable_agent example.
Interactive streaming REPL for the durable_agent example.
multiple_agents command
simple_agent command
internal
hooks
Package hooks defines agent middleware hook types used by the SDK runtime.
Package hooks defines agent middleware hook types used by the SDK runtime.
runtime
Package runtime defines internal execution contracts for agent backends (Temporal, in-process, etc.).
Package runtime defines internal execution contracts for agent backends (Temporal, in-process, etc.).
runtime/base
Package base provides the shared runtime struct and core execution methods used by both the local and temporal runtime backends.
Package base provides the shared runtime struct and core execution methods used by both the local and temporal runtime backends.
runtime/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
runtime/temporal
Package temporal contains helpers for integrating this SDK with go.temporal.io (client, worker, etc.).
Package temporal contains helpers for integrating this SDK with go.temporal.io (client, worker, etc.).
testing
Package testutil provides test helpers for the agent SDK.
Package testutil provides test helpers for the agent SDK.
pkg
a2a
Package a2a defines skill-filter shapes for A2A agent connections.
Package a2a defines skill-filter shapes for A2A agent connections.
a2a/client
Package client implements interfaces.A2AClient, interfaces.A2AStreamingClient, and interfaces.A2ATaskClient using the github.com/a2aproject/a2a-go/v2 SDK.
Package client implements interfaces.A2AClient, interfaces.A2AStreamingClient, and interfaces.A2ATaskClient using the github.com/a2aproject/a2a-go/v2 SDK.
agent/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
conversation/inmem
Package inmem provides in-memory conversation storage.
Package inmem provides in-memory conversation storage.
conversation/redis
Package redis provides Redis-backed conversation storage.
Package redis provides Redis-backed conversation storage.
interfaces/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
llm
llm/deepseek
Package deepseek provides an interfaces.LLMClient for DeepSeek.
Package deepseek provides an interfaces.LLMClient for DeepSeek.
llm/ollama
Package ollama provides an interfaces.LLMClient for Ollama, covering both a local daemon and Ollama Cloud (ollama.com).
Package ollama provides an interfaces.LLMClient for Ollama, covering both a local daemon and Ollama Cloud (ollama.com).
logger
Package logger defines the SDK Logger interface and slog-backed implementations.
Package logger defines the SDK Logger interface and slog-backed implementations.
mcp
Package mcp defines transport and tool-filter shapes for MCP server connections.
Package mcp defines transport and tool-filter shapes for MCP server connections.
mcp/client
Package client implements interfaces.MCPClient.
Package client implements interfaces.MCPClient.
memory/pgvector
Package pgvector provides a interfaces.Memory implementation backed by PostgreSQL with pgvector.
Package pgvector provides a interfaces.Memory implementation backed by PostgreSQL with pgvector.
memory/weaviate
Package weaviate provides a interfaces.Memory implementation backed by Weaviate.
Package weaviate provides a interfaces.Memory implementation backed by Weaviate.
retriever/pgvector
Package pgvector provides a retriever backed by PostgreSQL with the pgvector extension.
Package pgvector provides a retriever backed by PostgreSQL with the pgvector extension.
retriever/weaviate
Package weaviate provides a vector retriever backed by Weaviate's nearText GraphQL API.
Package weaviate provides a vector retriever backed by Weaviate's nearText GraphQL API.
tools
Package tools provides schema helpers for building tool parameter JSON schemas.
Package tools provides schema helpers for building tool parameter JSON schemas.

Jump to

Keyboard shortcuts

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