44import uuid
55import asyncio
66from datetime import UTC , datetime
7+ from typing import cast
78from unittest .mock import AsyncMock , MagicMock , patch
89
910from agentex .types .span import Span
@@ -287,12 +288,13 @@ async def capture_end(span: Span) -> None:
287288 span_queue = queue ,
288289 )
289290
290- initial_input = {"messages" : [{"role" : "user" , "content" : "hello" }]}
291+ initial_input : dict [ str , object ] = {"messages" : [{"role" : "user" , "content" : "hello" }]}
291292 async with trace .span ("llm-call" , input = initial_input ) as span :
292293 # Simulate modifying input after start (e.g. chatbot appending messages)
293- span .input ["messages" ].append ({"role" : "assistant" , "content" : "hi there" })
294- span .input ["messages" ].append ({"role" : "user" , "content" : "how are you?" })
295- span .output = {"response" : "I'm good!" }
294+ messages = cast (list [dict [str , str ]], cast (dict [str , object ], span .input )["messages" ])
295+ messages .append ({"role" : "assistant" , "content" : "hi there" })
296+ messages .append ({"role" : "user" , "content" : "how are you?" })
297+ span .output = cast (dict [str , object ], {"response" : "I'm good!" })
296298
297299 await queue .shutdown ()
298300
@@ -301,11 +303,11 @@ async def capture_end(span: Span) -> None:
301303
302304 # START should carry the original input (serialized at start time)
303305 assert start_spans [0 ].input is not None
304- assert len (start_spans [0 ].input ["messages" ]) == 1 # only the original message
306+ assert len (cast ( dict [ str , list [ object ]], start_spans [0 ].input ) ["messages" ]) == 1 # only the original message
305307
306308 # END should carry the modified input (re-serialized at end time)
307309 assert end_spans [0 ].input is not None
308- assert len (end_spans [0 ].input ["messages" ]) == 3 # all three messages
310+ assert len (cast ( dict [ str , list [ object ]], end_spans [0 ].input ) ["messages" ]) == 3 # all three messages
309311
310312 # END should still carry output and end_time
311313 assert end_spans [0 ].output is not None
0 commit comments