@@ -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