@@ -21,10 +21,14 @@ def _dbg_print(*args):
2121
2222
2323def serialize_lc_message_to_ep (msg : BaseMessage ) -> Message :
24- _dbg_print ("[EP-Ser] Input LC msg:" , type (msg ).__name__ , {
25- "has_additional_kwargs" : isinstance (getattr (msg , "additional_kwargs" , None ), dict ),
26- "content_type" : type (getattr (msg , "content" , None )).__name__ ,
27- })
24+ _dbg_print (
25+ "[EP-Ser] Input LC msg:" ,
26+ type (msg ).__name__ ,
27+ {
28+ "has_additional_kwargs" : isinstance (getattr (msg , "additional_kwargs" , None ), dict ),
29+ "content_type" : type (getattr (msg , "content" , None )).__name__ ,
30+ },
31+ )
2832
2933 if isinstance (msg , HumanMessage ):
3034 ep_msg = Message (role = "user" , content = str (msg .content ))
@@ -65,11 +69,13 @@ def _normalize_tool_calls(tc_list: list) -> list[dict]:
6569 import json as _json
6670
6771 fn_args = _json .dumps (fn_args or {}, ensure_ascii = False )
68- mapped .append ({
69- "id" : call_id ,
70- "type" : "function" ,
71- "function" : {"name" : fn_name , "arguments" : fn_args },
72- })
72+ mapped .append (
73+ {
74+ "id" : call_id ,
75+ "type" : "function" ,
76+ "function" : {"name" : fn_name , "arguments" : fn_args },
77+ }
78+ )
7379 except Exception :
7480 continue
7581 return mapped
@@ -92,16 +98,23 @@ def _normalize_tool_calls(tc_list: list) -> list[dict]:
9298 # Extract reasoning/thinking parts into reasoning_content
9399 reasoning_content = None
94100 if isinstance (msg .content , list ):
95- collected = [it .get ("thinking" , "" ) for it in msg .content if isinstance (it , dict ) and it .get ("type" ) == "thinking" ]
101+ collected = [
102+ it .get ("thinking" , "" ) for it in msg .content if isinstance (it , dict ) and it .get ("type" ) == "thinking"
103+ ]
96104 if collected :
97105 reasoning_content = "\n \n " .join ([s for s in collected if s ]) or None
98106
99- ep_msg = Message (role = "assistant" , content = content , tool_calls = tool_calls_payload , reasoning_content = reasoning_content )
100- _dbg_print ("[EP-Ser] -> EP Message:" , {
101- "role" : ep_msg .role ,
102- "content_len" : len (ep_msg .content or "" ),
103- "tool_calls" : len (ep_msg .tool_calls or []) if isinstance (ep_msg .tool_calls , list ) else 0 ,
104- })
107+ ep_msg = Message (
108+ role = "assistant" , content = content , tool_calls = tool_calls_payload , reasoning_content = reasoning_content
109+ )
110+ _dbg_print (
111+ "[EP-Ser] -> EP Message:" ,
112+ {
113+ "role" : ep_msg .role ,
114+ "content_len" : len (ep_msg .content or "" ),
115+ "tool_calls" : len (ep_msg .tool_calls or []) if isinstance (ep_msg .tool_calls , list ) else 0 ,
116+ },
117+ )
105118 return ep_msg
106119
107120 if isinstance (msg , ToolMessage ):
@@ -113,13 +126,13 @@ def _normalize_tool_calls(tc_list: list) -> list[dict]:
113126 role = "tool" ,
114127 name = tool_name ,
115128 tool_call_id = tool_call_id ,
116- content = f"<{ tool_name } status=\" { status } \" >\n { content } \n </{ tool_name } >" ,
129+ content = f'<{ tool_name } status="{ status } ">\n { content } \n </{ tool_name } >' ,
130+ )
131+ _dbg_print (
132+ "[EP-Ser] -> EP Message:" , {"role" : ep_msg .role , "name" : ep_msg .name , "has_id" : bool (ep_msg .tool_call_id )}
117133 )
118- _dbg_print ("[EP-Ser] -> EP Message:" , {"role" : ep_msg .role , "name" : ep_msg .name , "has_id" : bool (ep_msg .tool_call_id )})
119134 return ep_msg
120135
121136 ep_msg = Message (role = getattr (msg , "type" , "assistant" ), content = str (getattr (msg , "content" , "" )))
122137 _dbg_print ("[EP-Ser] -> EP Message (fallback):" , {"role" : ep_msg .role , "len" : len (ep_msg .content or "" )})
123138 return ep_msg
124-
125-
0 commit comments