Open
Description
Please read this first
- Have you read the docs?Agents SDK docs
yes - Have you searched for related issues? Others may have faced similar issues.
yes
Describe the bug
I'm following the official Session example to build a demo, but encountered an error when processing the second round of conversation:
File "D:\030t0073\Documents\codes\DevHub\services\trunk\dataflow-agent\agent-by-openai\.venv\Lib\site-packages\agents\models\chatcmpl_converter.py", line 473, in items_to_messages
raise UserError(f"Unhandled item type or structure: {item}")
agents.exceptions.UserError: Unhandled item type or structure: {'id': '__fake_id__', 'summary': [{'text': "\nOkay, the user is asking which city the Golden Gate Bridge is in... San Francisco.\n", 'type': 'summary_text'}], 'type': 'reasoning'}
Debug information
- Agents SDK version: (e.g.
v0.2.1
) - Python version (e.g. Python 3.12)
Repro steps
- Create a session following the official example
- Initiate a conversation with multiple turns
- Error occurs during the second turn when the agent returns a reasoning type item
This is my complete code:
import asyncio
import uuid
from openai.types.responses import ResponseTextDeltaEvent
from agents import Agent, Runner, OpenAIChatCompletionsModel, AsyncOpenAI, SQLiteSession, trace
from agents.run import RunConfig
def get_agent():
agent = Agent(
name="Joker",
instructions="You are a helpful assistant.",
model=OpenAIChatCompletionsModel(
model="qwen3-30B",
openai_client=AsyncOpenAI(
api_key="****",
base_url="****",
timeout=60,
)
),
)
return agent
async def main():
agent = get_agent()
session = SQLiteSession("conversation_123", "conversation_history.db")
# session.clear_session()
while True:
user_input = input("\n\nUser: ") # "Please tell me 5 jokes."
if user_input in ["quit", "exit"]:
break
result = Runner.run_streamed(
agent,
input=user_input,
run_config=RunConfig(tracing_disabled=True),
session=session
)
print("Agent: ", end="")
async for event in result.stream_events():
# print(event)
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
print(event.data.delta, end="", flush=True)
if __name__ == "__main__":
asyncio.run(main())
Analysis
The error occurs because the models.chatcmpl_converter.Converter.items_to_messages()
method does not handle the {'type': 'reasoning'} structure. Current code only supports specific item types (e.g., message, function_call), but not the reasoning format returned by the agent.