Basic Example
Each response from anAgent.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 thestore parameter to the
OpenAIResponsesChatModelOptions class.
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
- Tool Calling - Using tools in conversations
- Streaming Output - Real-time responses

