-
Notifications
You must be signed in to change notification settings - Fork 594
Description
- Have you read the docs? Yes - Agents SDK docs
- Have you searched for related issues? Yes - searched for similar issues but couldn't find a match for this specific error. Most of the issue are around stateless use or suggest managing the conversation your self
Describe the bug
We're experiencing a random 400 error when using the OpenAI Agents SDK with OpenAIConversationsSession to store conversation context. The error message is:
400 Item 'XX_XX' of type 'reasoning' was provided without its required following item.
This error occurs intermittently between chat conversations, typically after several turns in a conversation.
The error suggests that a reasoning item is being included in the conversation input without its required following item (which should be an assistant response). This appears to be a validation error from the OpenAI API when processing the conversation history stored in OpenAIConversationsSession.
Debug information
- Agents SDK version:
@openai/agents@^0.4.4 - Runtime environment: Node.js 22.19.0
- OpenAI SDK version:
openai@^6.15.0 - Model settings: Using
reasoning: { effort: 'medium', summary: 'concise' }inModelSettings - Streaming: Enabled (
stream: true) - Model: gpt-5-mini-2025-08-07
Repro steps
The issue occurs when:
Using OpenAIConversationsSession to persist conversation context across multiple turns
Here's a minimal reproduction scenario:
import { Agent, OpenAIConversationsSession, Runner, ModelSettings } from "@openai/agents";
const defaultModelSettings: ModelSettings = {
parallelToolCalls: false,
truncation: 'auto',
store: true,
reasoning: {
effort: 'medium',
summary: 'concise'
},
text: {
verbosity: 'low'
},
};
// Usage
const agent = new Agent({
name: "TestAgent",
prompt: { promptId: "your-prompt-id" },
modelSettings: defaultModelSettings,
tools: [/* User-specific tools that make DB calls */],
});
const runner = new Runner({
traceId: "test-trace",
groupId: "conversation-id",
});
// After several turns in a conversation
const session = new OpenAIConversationsSession({
conversationId: "existing-conversation-id",
});
const result = await runner.run(agent, "User message", {
session: session,
context: {
userId: "user-id",
},
stream: true,
});
// Error occurs randomly when processing the stream
for await (const value of result) {
// Error: "400 Item 'XX_XX' of type 'reasoning' was provided without its required following item."
}Key observations:
- The error is random and doesn't occur on every request
Additional context
Our implementation details:
- We're using
OpenAIConversationsSessionto persist conversation state across multiple turns - We're using
reasoning: { effort: 'medium', summary: 'concise' }in model settings - Streaming is enabled (
stream: true) - We're using custom tools that make database calls based on user authentication:
- Tools query user-specific data (routes, organizations, documents, etc.) based on the
userIdpassed in thecontextparameter - The
contextincludesuserId. - These tools are called during agent execution and return data specific to the logged-in user
- Tools query user-specific data (routes, organizations, documents, etc.) based on the
- The agent uses direct function tools that access our database
Questions:
- What is the exact requirement for reasoning items? Must they always be immediately followed by an assistant response?
- How should reasoning items be handled when using
OpenAIConversationsSession? Should the SDK automatically ensure reasoning items are always paired with their required following items? - Could tool calls interactions affect how reasoning items are stored or retrieved from the conversation session?
Workaround
Currently, we're working around this by:
- Catching the error and retrying the request with a new conversationId (basically starting a fresh conversation)
- However, this is not ideal as it doesn't prevent the error from occurring
We would appreciate guidance on the correct way to handle reasoning items when using OpenAIConversationsSession for persistent conversation state.