> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agenticenv.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent SDK for Go

> Build AI agents in Go, crash-resilient by default — scale out with Temporal or Restate when you need to.

**Agent SDK for Go** is a Go library for building production AI agents. It handles the full execution loop — LLM calls, tool use, approvals, memory, multi-agent delegation — so you write configuration and business logic, not plumbing.

**Who it's for:** Go backend engineers who want to ship agents in the same language, type system, and deployment pipeline as the rest of their stack — without glue code, dynamic typing, or a Python runtime.

## Your First Agent

```go theme={null}
llmClient, _ := openai.NewClient(
    llm.WithAPIKey(os.Getenv("OPENAI_API_KEY")),
    llm.WithModel("gpt-4o"),
)

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

agentRun, _ := a.Run(ctx, "What is the capital of France?", nil)
result, _ := agentRun.Get(ctx)
fmt.Println(result.Content) // Paris.
```

That's it — configure once, call repeatedly. Tools, memory, and streaming are additive options — not new APIs to learn. This agent is already durable: it journals every LLM call and tool execution to disk via [durable-go](https://github.com/agenticenv/durable-go), no extra config needed.

## Install

```bash theme={null}
go get github.com/agenticenv/agent-sdk-go@latest
```

Go 1.26+. OpenAI API key required for the example above; Anthropic and Gemini are also built in. Temporal and Restate are optional — they add distributed, horizontally-scaled execution, not durability itself.

## Why Agent SDK for Go

* **Idiomatic Go** — functional options, typed interfaces, no reflection magic. Swap any component (LLM client, memory backend, approval policy) by passing a different option.
* **Durable by default, no infrastructure** — the in-process runtime journals every step via [durable-go](https://github.com/agenticenv/durable-go); kill the process and reconnect after a restart. Add `temporal.WithTemporalConfig` (from `pkg/agent/runtime/temporal`) or `restate.WithRestateConfig` (from `pkg/agent/runtime/restate`) only when you need horizontal scale or a client/worker split. Nothing else changes.
* **Concurrent by default** — one `Agent` instance handles parallel `Run` and `Stream` calls; every runtime issues each a unique run automatically.
* **Protocol-native integrations** — MCP tool servers, A2A agent-to-agent delegation, and AG-UI streaming events are first-class, not adapters bolted on after the fact.
* **Middleware hooks** — intercept LLM calls, tool use, retrieval, and memory at any lifecycle point for logging, PII scrubbing, and guardrails without touching agent logic.
* **Error control** — after retries, swap to a fallback model, grant more iterations, or skip a looping tool. See [Error Control](/features/error-control).
* **Cache-aware requests** — LLM requests are structured for provider caching, with Anthropic prompt-cache breakpoints to reduce cost on multi-turn runs.

## Runtimes

Run agents in-process — durable by default, no infrastructure — or add Temporal or Restate when you need horizontal scale or a client/worker split.

| | In-process (default) | Temporal | Restate |
| - | - | - | - |
| Setup | No infra | Running Temporal server | Running Restate server |
| Durability | Survives crashes and restarts (durable-go journal); opt out with `local.DurabilityOff()` | Survives crashes and restarts | Survives crashes and restarts |
| Scale | Single process | Horizontal worker pools | Multiple registered endpoints |
| When | Dev, scripts, low-volume APIs, and production single-process deployments | Production, long-running, horizontally-scaled tasks | Production, long-running, horizontally-scaled tasks |

Add `temporal.WithTemporalConfig` or `restate.WithRestateConfig` to switch. See [Runtimes](/runtimes/overview).

## Start here

<CardGroup cols={2}>
  <Card title="Quickstart" icon="bolt" href="/getting-started/quickstart" horizontal>
    Your first agent, step by step — under 5 minutes
  </Card>

  <Card title="Architecture" icon="sitemap" href="/architecture" horizontal>
    How the agent loop maps to capabilities and runtimes
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.