> ## 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 Chat

> Durable chat reference app built with Agent SDK for Go — Temporal workflows, SSE streaming, and crash recovery

[Agent Chat](https://github.com/agenticenv/agent-chat) is a full-stack reference application built end-to-end with **Agent SDK for Go** — React UI, Go API, Temporal-backed agent runs, and real-time streaming over SSE.

> Demo app for learning and reference. Not intended for production use as-is.

## What it demonstrates

Most agent frameworks run in-process — if your HTTP server restarts or the browser drops, the agent turn is gone. Agent Chat shows how the SDK's Temporal-first model powers a **durable chat product**:

| Capability | What users experience | What the SDK enables |
| - | - | - |
| Durable agent turns | Closing the tab or restarting the API does not cancel the run | Temporal workflows keep running; client reconnects with `GetAgentStream` |
| Crash-safe streaming | Reopen a chat mid-reply and tokens continue | Persist stream id + event offset; resume with `Events(WithOffset(…))` |
| Split API / worker | Scale workers independently of the web tier | `NewAgent` + `DisableLocalWorker` (client) and `NewAgentWorker` on a shared task queue |
| Matching client & worker | Same agent config on both processes so activities are accepted | Shared options (name, LLM, conversation, Temporal) — SDK fingerprint check |
| Shared conversation memory | History survives restarts across replicas | Custom `interfaces.Conversation` (Postgres) via `WithConversation` |
| Live UI streaming | Chat bubbles update token-by-token | AG-UI events from `Stream()` / `GetAgentStream` over SSE |

## Architecture

The API and Temporal worker are **separate processes** from the same server image. `APP_MODE` selects the role:

| Mode | Process | SDK pattern |
| - | - | - |
| `server` | HTTP API + agent client | `NewAgent` with `DisableLocalWorker` |
| `worker` | Temporal worker | `NewAgentWorker` with matching config |

Both share agent options (name, LLM, conversation, Temporal queue) so the SDK fingerprint check passes.

```
Browser → React UI → Go API (agent client)
                          ↓
                     Temporal cluster
                          ↓
                     Worker process (AgentWorker)
                          ↓
                     LLM provider
```

Conversations and messages live in PostgreSQL. The SDK conversation bridge feeds history into `WithConversation` on each turn.

## Resilience and crash recovery

**Without a durable runtime:**

* Browser refresh mid-stream → reply lost
* API process crash → in-memory agent run gone
* Long LLM / tool turns → HTTP timeouts force awkward workarounds

**With Agent SDK for Go + Temporal:**

1. `agent.Stream(...)` starts a Temporal-backed run; events bridge to the browser as SSE (`ev.ToJSON()`)
2. Stream id (`agentStream.ID()`) and each event’s durable offset are checkpointed
3. Cancelling the SSE subscriber does **not** cancel the workflow — Temporal keeps the turn alive
4. On reconnect — `GetAgentStream(savedID)` + `Events(ctx, WithOffset(savedOffset))` resumes the stream (Temporal runtime; not LocalRuntime). The UI reopens a chat still marked in-progress and continues the same AG-UI → bubble mapping
5. On `RUN_FINISHED` / `RUN_ERROR` — checkpoint clears; conversation history remains via `WithConversation` / Postgres

Client and worker both use the **same** agent options so the worker can execute workflows the API started — see [Distributed Execution](/advanced/distributed-execution).

## SDK features demonstrated

| Feature | Agent Chat usage |
| - | - |
| [Temporal runtime](/runtimes/temporal) | Every chat turn is a durable workflow |
| [Streaming](/getting-started/streaming) | `Stream()` bridged to browser SSE via `ev.ToJSON()` |
| [Reconnect / GetAgentStream](/examples/reconnect) | Resume mid-turn after disconnect or API restart |
| [Distributed Execution](/advanced/distributed-execution) | Shared agent options; `NewAgent` client + `NewAgentWorker` |
| [Conversation](/features/conversation) | Custom PostgreSQL-backed `interfaces.Conversation` |
| [AG-UI Protocol](/features/ag-ui-protocol) | `TEXT_MESSAGE_CONTENT`, `RUN_FINISHED`, `RUN_ERROR` |
| [LLM Providers](/getting-started/llm-providers) | OpenAI, Anthropic, or Gemini via env config |

For setup, run instructions, and app internals see the [Agent Chat repository](https://github.com/agenticenv/agent-chat).

## Related

<CardGroup cols={2}>
  <Card title="Reconnect" icon="rotate" href="/examples/reconnect" horizontal>
    GetAgentStream + WithOffset after a crash
  </Card>

  <Card title="Durable Agent (Temporal)" icon="shield" href="/examples/durable-agent" horizontal>
    SDK durable execution example
  </Card>

  <Card title="Agent Worker" icon="server" href="/examples/agent-worker" horizontal>
    Client and worker split example
  </Card>

  <Card title="Streaming" icon="wave-pulse" href="/getting-started/streaming" horizontal>
    Stream, Events, and AG-UI wiring
  </Card>
</CardGroup>


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