Skip to content

Commit 55eafa2

Browse files
committed
allow reasoning details to pass through
1 parent 2ae135a commit 55eafa2

2 files changed

Lines changed: 48 additions & 22 deletions

File tree

eval_protocol/mcp/execution/base_policy.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ def __init__(
5959
# Initialize conversation state tracking for proper OpenAI trajectories
6060
self.initialized = False
6161

62+
def _supports_reasoning_details(self) -> bool:
63+
"""
64+
Returns True if this policy is configured for a provider/model that expects
65+
top-level reasoning_details to be preserved (e.g., Gemini 3 via OpenRouter).
66+
"""
67+
model_id = getattr(self, "model_id", "") or ""
68+
base_url = getattr(self, "base_url", "") or ""
69+
70+
if isinstance(model_id, str) and "openrouter" in model_id:
71+
return True
72+
if isinstance(base_url, str) and "openrouter.ai" in base_url:
73+
return True
74+
return False
75+
6276
@abstractmethod
6377
async def _make_llm_call(self, messages: List[Dict], tools: List[Dict]) -> Dict:
6478
"""
@@ -199,6 +213,9 @@ async def _generate_live_tool_calls(
199213
if message.get("tool_calls"):
200214
assistant_message_for_history["tool_calls"] = message["tool_calls"]
201215

216+
if message.get("reasoning_details") and self._supports_reasoning_details():
217+
assistant_message_for_history["reasoning_details"] = message["reasoning_details"]
218+
202219
# Add to actual conversation history
203220
conversation_history.append(assistant_message_for_history)
204221

eval_protocol/mcp/execution/policy.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def _clean_messages_for_api(self, messages: List[Dict]) -> List[Dict]:
148148
# Standard OpenAI message fields
149149
allowed_fields = {"role", "content", "tool_calls", "tool_call_id", "name"}
150150

151+
if self._supports_reasoning_details():
152+
allowed_fields.add("reasoning_details")
153+
151154
clean_messages = []
152155
for msg in messages:
153156
# Only keep allowed fields
@@ -217,31 +220,37 @@ async def _make_llm_call(self, messages: List[Dict[str, Any]], tools: List[Dict[
217220
logger.debug(f"🔄 API call for model: {self.model_id}")
218221

219222
# LiteLLM already returns OpenAI-compatible format
223+
message_obj = getattr(response.choices[0], "message", object())
224+
225+
message_dict: Dict[str, Any] = {
226+
"role": getattr(message_obj, "role", "assistant"),
227+
"content": getattr(message_obj, "content", None),
228+
"tool_calls": (
229+
[
230+
{
231+
"id": getattr(tc, "id", None),
232+
"type": getattr(tc, "type", "function"),
233+
"function": {
234+
"name": getattr(getattr(tc, "function", None), "name", "tool"),
235+
"arguments": getattr(getattr(tc, "function", None), "arguments", "{}"),
236+
},
237+
}
238+
for tc in (getattr(message_obj, "tool_calls", []) or [])
239+
]
240+
if getattr(message_obj, "tool_calls", None)
241+
else []
242+
),
243+
}
244+
245+
if self._supports_reasoning_details():
246+
rd = getattr(message_obj, "reasoning_details", None)
247+
if rd is not None:
248+
message_dict["reasoning_details"] = rd
249+
220250
return {
221251
"choices": [
222252
{
223-
"message": {
224-
"role": getattr(getattr(response.choices[0], "message", object()), "role", "assistant"),
225-
"content": getattr(getattr(response.choices[0], "message", object()), "content", None),
226-
"tool_calls": (
227-
[
228-
{
229-
"id": getattr(tc, "id", None),
230-
"type": getattr(tc, "type", "function"),
231-
"function": {
232-
"name": getattr(getattr(tc, "function", None), "name", "tool"),
233-
"arguments": getattr(getattr(tc, "function", None), "arguments", "{}"),
234-
},
235-
}
236-
for tc in (
237-
getattr(getattr(response.choices[0], "message", object()), "tool_calls", [])
238-
or []
239-
)
240-
]
241-
if getattr(getattr(response.choices[0], "message", object()), "tool_calls", None)
242-
else []
243-
),
244-
},
253+
"message": message_dict,
245254
"finish_reason": getattr(response.choices[0], "finish_reason", None),
246255
}
247256
],

0 commit comments

Comments
 (0)