Repository navigation
Labels
agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
Description
Description
Description
When using OpenAIChatCompletionClient with an OpenAI-compatible provider that supports reasoning/thinking and tool calling, the follow-up request after a tool call can fail because reasoning_content is not preserved in the exact assistant message structure required by the provider.
The issue was reproduced with the official DeepSeek API and a thinking-enabled model.
Environment
- OS: macOS
- Python: 3.14
- Agent Framework: 1.18.0
- Client:
OpenAIChatCompletionClient - API: OpenAI-compatible Chat Completions API
- Provider: DeepSeek
- Base URL:
https://api.deepseek.com - Model:
deepseek-flash - requires-python = ">=3.14"
- dependencies = [
"numpy>=2.5.3",
"openmeteo-requests>=1.7.5",
"pandas>=3.0.5",
"python-dotenv>=1.2.3",
"requests-cache>=1.3.3",
"retry-requests>=2.0.0",
]
Minimal Reproduction
from agent_framework import Agent, tool
from agent_framework.openai import OpenAIChatCompletionClient
@tool
def get_weather(location: str) -> str:
return f"Weather result for {location}"
client = OpenAIChatCompletionClient(
base_url="https://api.deepseek.com",
api_key="...",
model="deepseek-flash",
)
agent = Agent(
client=client,
instructions="Use the get_weather tool when the user asks about weather.",
tools=[get_weather],
)
response = await agent.run(
"What is the weather in New York City?",
options={
"extra_body": {
"thinking": {
"type": "enabled"
}
}
},
)
### Code Sample
```markdown
import os
import sys
import asyncio
import json
from functools import partial
from pathlib import Path
from typing import Any
from dotenv import load_dotenv
from agent_framework import Agent, Content, tool
from agent_framework.openai import OpenAIChatCompletionClient, OpenAIChatClient
from agent_framework.anthropic import AnthropicClient
if __package__ in (None, ""):
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from utility.get_weather_from_open_meteo import WeatherAPI
def parse_openai_compatible_response(message: Any, contents: list[Content]) -> list[Content]:
reasoning_content = getattr(message, "reasoning_content", None)
if reasoning_content is None:
extra = getattr(message, "model_extra", None) or getattr(message, "additional_kwargs", None) or {}
reasoning_content = extra.get("reasoning_content") or extra.get("reasoning_details")
if reasoning_content and not any(content.type == "text_reasoning" for content in contents):
contents.append(Content.from_text_reasoning(protected_data=json.dumps(reasoning_content)))
return contents
def prepare_openai_compatible_message(
message: Any,
prepared_messages: list[dict[str, Any]],
reasoning_field: str = "reasoning_details",
) -> list[dict[str, Any]]:
for prepared_message in prepared_messages:
if "reasoning_details" in prepared_message:
prepared_message[reasoning_field] = prepared_message.pop("reasoning_details")
merged_messages = []
for prepared_message in prepared_messages:
is_assistant = prepared_message.get("role") == "assistant"
previous_message = merged_messages[-1] if merged_messages else None
can_merge = (
is_assistant
and previous_message is not None
and previous_message.get("role") == "assistant"
and "tool_call_id" not in prepared_message
and "tool_call_id" not in previous_message
)
if not can_merge:
merged_messages.append(prepared_message)
continue
if prepared_message.get("content"):
previous_content = previous_message.get("content")
if previous_content:
previous_message["content"] = f"{previous_content}{prepared_message['content']}"
else:
previous_message["content"] = prepared_message["content"]
if prepared_message.get("tool_calls"):
previous_message.setdefault("tool_calls", []).extend(prepared_message["tool_calls"])
if prepared_message.get("reasoning_content") is not None:
previous_message["reasoning_content"] = prepared_message["reasoning_content"]
return merged_messages
prepare_deepseek_message = partial(
prepare_openai_compatible_message,
reasoning_field="reasoning_content",
)
env_path = Path(__file__).parent.parent / ".env"
load_dotenv(env_path)
#deepseek model configuration
deepseek_url=os.environ.get("deepseek_base_url")
deepseek_api_key=os.environ.get("deepseek_api_key")
deepseek_model=os.environ.get("deepseek_model")
deepseek_client = OpenAIChatCompletionClient(
base_url=deepseek_url,
api_key=deepseek_api_key,
model=deepseek_model,
response_parser=parse_openai_compatible_response,
message_preparer=prepare_deepseek_message,
)
#create tool
@tool
def get_weather(location: str) -> str:
"""
Get hourly weather information for a given location name.
"""
try:
weather_df = WeatherAPI().get_weather(location)
except Exception as error:
return f"Weather lookup failed for {location!r}: {error}"
if weather_df.empty:
return f"Weather lookup returned no data for {location!r}."
return weather_df.to_string()
#create agents
agent1 = Agent(
client=deepseek_client,
instructions="You are a helpful assistant that answers questions by calling the get_weather tool to get weather information for a given location.",
tools=[get_weather]
)
agent2 = Agent(
client=anthropic_client,
instructions="You are a helpful assistant that answers questions by calling the get_weather tool to get weather information for a given location.",
tools=[get_weather]
)
async def main():
prompt = "What is the weather in Los Angeles?"
response = await agent1.run(
prompt,
options={"extra_body": {"thinking": {"type": "enabled"}}},
)
print("Response from agent1:")
print(response.text)
if __name__ == "__main__":
asyncio.run(main())Error Messages / Stack Traces
pls refer to below addition context.Package Versions
agent-framework-core version 1.18.0
Python Version
Python 3.14
Additional Context
Metadata
Metadata
Labels
agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Sep 15, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
The bug reproduces in
python/packages/openai/agent_framework_openai/_chat_completion_client.py::_parse_response_from_openaiand_build_openai_messageswhen one provider response contains text, a tool call, and protected reasoning. Minimal repro: parse aChatCompletionMessagecontainingcontent,tool_calls, andreasoning_contentthrough provider hooks, then prepare the parsed framework message; it produces two assistant dictionaries instead of one.python/packages/openai/tests/openai/test_openai_chat_completion_client.py::test_roundtrip_reasoning_content_with_text_and_function_call_keps_single_assistant_message1.14.31.14.3anishmehta24 commentedon Sep 15, 2026
I'd like to take this on. I reproduced it in a unit test:
_build_openai_messagesemits a text-only assistant dict and a separatetool_callsdict for one turn, and the buffered reasoning field only lands on the second one, which is why DeepSeek rejects the tool-result follow-up. The fix keeps text,tool_callsand the reasoning field on a single assistant message while leaving hook-surfaced reasoning text and other content untouched, so the existingresponse_parser/message_preparerpattern forreasoning_contentworks end to end. PR incoming with regression tests.fix(openai): preserve reasoning_content on tool-call follow-up messag…