Skip to main content
An agent contains configuration information for what provider and model you’d like to use, what settings you want to use, what tools, etc. However, an agent has no context (aka memory) to bring from one prompt to the next. That context comes from the message history, which you manage and send to each agent along with each prompt.

Basic Example

Each response from an Agent.sendXxx method includes a list of new messages, which you can accumulate into the history of the conversation.

Streaming Example

When using streaming, you can accumulate the messages as they arrive.

Multi-Provider Chat

You can pass a shared history to multiple agents, even across providers.

With Tools

When you use tools in a chat, the results are included in the history and provide context for the next request.

Prompt Caching with Provider Sessions

The OpenAI Responses provider attaches metadata to each response message it providers so that you do not need to pass the history around; you only need to send the new messages since the last response. This provides prompt caching and saves on network traffic. You still send messages around as normal, so your code doesn’t change. Moreover, this works across multiple providers; the OpenAI Responses provider can send along all of the messages since the last response, even the request/response pairs from other providers. You can control this behavior with the store parameter to the OpenAIResponsesChatModelOptions class.
When store is true (the default), the provider caches the entire conversation server-side. You can manually set store: false to force stateless behavior.

Examples

Next Steps