Skip to main content
Conversation history enables agents to maintain context across multiple interactions. By preserving previous messages, agents can reference earlier exchanges and build upon prior context, facilitating natural, context-aware conversations.

Overview

When a conversation history manager is provided to an agent, it performs the following operations:
  • Loads Previous Messages: Automatically retrieves conversation history based on the thread ID
  • Saves Automatically: Persists new messages after each execution

Enabling Conversation History

To enable conversation history, create a history manager with hastekit.NewFileHistory and pass the created instance to the agent’s History field. While invoking the agent, optionally set Namespace to bucket the conversations by namespaces.

Continuing the conversation

To continue the conversation, pass same thread ID while invoking the agent again.

Persistence

The conversation manager supports three persistence configurations for storing conversation history:

1. File Persistence

When the SDK client is initialized without an endpoint, messages are persisted as JSON files written to the disk (under ./conversations).

2. HasteKit Gateway Persistence

When the SDK client is initialized with an endpoint, the conversation manager automatically persists messages to the HasteKit’s Gateway server.

3. Custom Persistence

To implement custom persistence, implement the ConversationPersistenceAdapter interface:
Then pass your implementation to the conversation manager constructor:
When you use hastekit.NewFileHistory("./conversations"), the SDK wires a file-backed adapter that persists messages as JSON on disk.

Message Filtering & Attribution

Each stored message bundle (messages.Message) carries a SenderID, which lets the conversation manager attribute turns to a specific participant in multi-participant conversations. You can transform a run’s message bundles before they are attributed and sent to the provider by supplying a MessageFilter via history.WithMessageFilter. A common use is rewriting each bundle’s SenderID from an opaque id into a human-friendly name.
The other available option is history.WithSummarizer, covered on the Summarization page.

Listing Threads

agent.History() returns the agent’s *history.CommonConversationManager. When its persistence adapter implements history.ThreadLister, you can enumerate stored threads. Pass an empty namespace ("") to list across all namespaces.

Complete Example

The following example demonstrates an agent with conversation history: