44 PreExtractedContent ,
55 RetrievalConfig ,
66 StringContent ,
7- ToolCallMetadata ,
7+ ToolCallCustomInput ,
8+ ToolCallFuncInput ,
9+ ToolCallInput ,
810)
911from engram ._serialization import (
1012 build_add_body ,
@@ -160,12 +162,15 @@ def test_build_add_body_conversation_content_with_message_timestamps() -> None:
160162 assert "tool_call_metadata" not in msg
161163
162164
163- def test_build_add_body_conversation_content_with_tool_call_metadata () -> None :
165+ def test_build_add_body_conversation_content_with_tool_calls () -> None :
164166 messages = [
165167 MessageContent (
166168 role = "assistant" ,
167- content = "using tool" ,
168- tool_call_metadata = ToolCallMetadata (name = "search" , id = "tc1" ),
169+ tool_calls = [
170+ ToolCallInput (
171+ id = "tc1" , function = ToolCallFuncInput (name = "search" , arguments = '{"q":"x"}' )
172+ )
173+ ],
169174 )
170175 ]
171176 body = build_add_body (
@@ -175,7 +180,62 @@ def test_build_add_body_conversation_content_with_tool_call_metadata() -> None:
175180 group = None ,
176181 )
177182 msg = body ["content" ]["conversation" ]["messages" ][0 ]
178- assert msg ["tool_call_metadata" ] == {"name" : "search" , "id" : "tc1" }
183+ assert msg ["tool_calls" ] == [
184+ {"id" : "tc1" , "type" : "function" , "function" : {"name" : "search" , "arguments" : '{"q":"x"}' }}
185+ ]
186+
187+
188+ def test_build_add_body_conversation_content_with_custom_tool_calls () -> None :
189+ messages = [
190+ MessageContent (
191+ role = "assistant" ,
192+ tool_calls = [
193+ ToolCallInput (
194+ id = "tc2" ,
195+ type = "custom" ,
196+ custom = ToolCallCustomInput (name = "my_tool" , input = "some input" ),
197+ )
198+ ],
199+ )
200+ ]
201+ body = build_add_body (
202+ ConversationContent (messages = messages ),
203+ user_id = None ,
204+ conversation_id = None ,
205+ group = None ,
206+ )
207+ msg = body ["content" ]["conversation" ]["messages" ][0 ]
208+ assert msg ["tool_calls" ] == [
209+ {"id" : "tc2" , "type" : "custom" , "custom" : {"name" : "my_tool" , "input" : "some input" }}
210+ ]
211+
212+
213+ def test_build_add_body_conversation_content_with_tool_role () -> None :
214+ messages = [MessageContent (role = "tool" , content = "result" , tool_call_id = "tc1" , name = "search" )]
215+ body = build_add_body (
216+ ConversationContent (messages = messages ),
217+ user_id = None ,
218+ conversation_id = None ,
219+ group = None ,
220+ )
221+ msg = body ["content" ]["conversation" ]["messages" ][0 ]
222+ assert msg ["role" ] == "tool"
223+ assert msg ["tool_call_id" ] == "tc1"
224+ assert msg ["name" ] == "search"
225+ assert msg ["content" ] == "result"
226+
227+
228+ def test_build_add_body_conversation_content_with_developer_role () -> None :
229+ messages = [MessageContent (role = "developer" , content = "You are a helpful assistant." )]
230+ body = build_add_body (
231+ ConversationContent (messages = messages ),
232+ user_id = None ,
233+ conversation_id = None ,
234+ group = None ,
235+ )
236+ msg = body ["content" ]["conversation" ]["messages" ][0 ]
237+ assert msg ["role" ] == "developer"
238+ assert msg ["content" ] == "You are a helpful assistant."
179239
180240
181241# ── build_memory_params ─────────────────────────────────────────────────
0 commit comments