Skip to content

Latest commit

Β 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 

README.md

Conversational Agent Example

This example demonstrates how to wrap any agent with long-term memory for multi-turn conversations with context awareness.

Overview

The Conversational Agent pattern adds semantic memory to any agent (ReAct, RAG, Supervisor, etc.) enabling:

  • Context recall: Automatically recalls relevant past messages before the agent runs
  • Conversation storage: Stores the exchange after each interaction
  • Session isolation: Each user/session has its own memory context

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Conversational Agent                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  START β†’ Memory Recall β†’ Wrapped Agent β†’ Memory Store β†’ END β”‚
β”‚                              β”‚                               β”‚
β”‚                         ReAct/RAG/                           β”‚
β”‚                       Supervisor/etc.                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Running the Example

export OPENAI_API_KEY=your-key-here
go run main.go

Key Features

Session ID (Required)

Each conversation needs a session ID to isolate memory:

chatAgent.Run(ctx, messages,
    graph.WithInitialValue(agent.SessionIDKey, "user-123-session"),
)

Configuration Options

The conversational agent uses a dual-memory approach combining:

  • Short-term memory: Recent N messages (recency-based)
  • Long-term memory: Semantically similar messages from history (relevance-based)
agent.NewConversational(reactAgent, mem,
    agent.WithShortTermMessages(5),       // Last 5 messages for immediate context
    agent.WithLongTermMessages(5),        // 5 semantically similar messages
    agent.WithMinSimilarityScore(0.5),    // Threshold for long-term recall
    agent.WithFailOnStoreError(false),    // Don't fail if storage fails
)
Option Description Default
WithShortTermMessages(n) Number of recent messages to always include 5
WithLongTermMessages(n) Number of semantically similar messages 5
WithMinSimilarityScore(s) Minimum similarity for long-term recall 0.5
WithFailOnStoreError(b) Fail if memory storage fails false

Memory Types

  • VectorMemory: Semantic search using embeddings (recommended for production)
  • SimpleMemory: Basic FIFO storage without semantic search (good for testing)

Example Output

=== Turn 1: Setting up context ===
Agent: Nice to meet you, Alice! San Francisco is a wonderful city...

=== Turn 2: Using tool ===
Agent: Let me check the weather in San Francisco for you...
Agent: The weather in San Francisco is currently sunny at 72Β°F.

=== Turn 3: Recalling from memory ===
Agent: Your name is Alice and you live in San Francisco.

=== Conversation complete! ===
The agent remembered context from earlier turns using semantic memory.

See Also