Skip to main content
Persists message history across turns using Redis and WithConversation. Runs with the same conversation ID share context across multiple Run calls. Source: examples/agent_with_conversation/

What it demonstrates

  • conversation.Config with Redis backend
  • AgentRunOptions.ConversationOptions.ID per run
  • Interactive REPL (no args) or single-turn CLI prompt

Run

From examples/:
task infra:redis:up
go run ./agent_with_conversation
go run ./agent_with_conversation "Hello, remember I'm Alice"
Interactive mode accepts multiple prompts until you type exit.

Key code

conv, err := redis.New(conversation.Config{
    RedisAddr: cfg.RedisAddr,
})

a, err := agent.NewAgent(
    agent.WithLLMClient(llmClient),
    agent.WithConversation(conv),
)

result, err := a.Run(ctx, prompt, &agent.AgentRunOptions{
    ConversationOptions: &agent.ConversationRunOptions{
        ID: "session-123",
    },
})
Use a distributed store (Redis, not in-memory) when agent client and worker run in separate processes. See Conversation.

Expected output

> Hello, remember I'm Alice
Nice to meet you, Alice! How can I help you today?

> What's my name?
Your name is Alice — you told me at the start of our conversation.

> exit
Redis persists the session between process restarts. The same CONVERSATION_ID (or session-123 default) replays history on the next go run.

Learn more

Conversation

Backends and session scope

Stream + Conversation

Streaming with persisted history