@@ -344,14 +344,14 @@ def __del__(self) -> None:
344344 self .thread_pool .shutdown (wait = False )
345345 logger .debug ("thread pool executor shutdown complete" )
346346
347- def __call__ (self , prompt : str , ** kwargs : Any ) -> AgentResult :
347+ def __call__ (self , prompt : Union [ str , list [ ContentBlock ]] , ** kwargs : Any ) -> AgentResult :
348348 """Process a natural language prompt through the agent's event loop.
349349
350350 This method implements the conversational interface (e.g., `agent("hello!")`). It adds the user's prompt to
351351 the conversation history, processes it through the model, executes any tool calls, and returns the final result.
352352
353353 Args:
354- prompt: The natural language prompt from the user .
354+ prompt: User input as text or list of ContentBlock objects for multi-modal content .
355355 **kwargs: Additional parameters to pass through the event loop.
356356
357357 Returns:
@@ -370,14 +370,14 @@ def execute() -> AgentResult:
370370 future = executor .submit (execute )
371371 return future .result ()
372372
373- async def invoke_async (self , prompt : str , ** kwargs : Any ) -> AgentResult :
373+ async def invoke_async (self , prompt : Union [ str , list [ ContentBlock ]] , ** kwargs : Any ) -> AgentResult :
374374 """Process a natural language prompt through the agent's event loop.
375375
376376 This method implements the conversational interface (e.g., `agent("hello!")`). It adds the user's prompt to
377377 the conversation history, processes it through the model, executes any tool calls, and returns the final result.
378378
379379 Args:
380- prompt: The natural language prompt from the user .
380+ prompt: User input as text or list of ContentBlock objects for multi-modal content .
381381 **kwargs: Additional parameters to pass through the event loop.
382382
383383 Returns:
@@ -456,7 +456,7 @@ async def structured_output_async(self, output_model: Type[T], prompt: Optional[
456456 finally :
457457 self ._hooks .invoke_callbacks (EndRequestEvent (agent = self ))
458458
459- async def stream_async (self , prompt : str , ** kwargs : Any ) -> AsyncIterator [Any ]:
459+ async def stream_async (self , prompt : Union [ str , list [ ContentBlock ]] , ** kwargs : Any ) -> AsyncIterator [Any ]:
460460 """Process a natural language prompt and yield events as an async iterator.
461461
462462 This method provides an asynchronous interface for streaming agent events, allowing
@@ -465,7 +465,7 @@ async def stream_async(self, prompt: str, **kwargs: Any) -> AsyncIterator[Any]:
465465 async environments.
466466
467467 Args:
468- prompt: The natural language prompt from the user .
468+ prompt: User input as text or list of ContentBlock objects for multi-modal content .
469469 **kwargs: Additional parameters to pass to the event loop.
470470
471471 Returns:
@@ -488,10 +488,13 @@ async def stream_async(self, prompt: str, **kwargs: Any) -> AsyncIterator[Any]:
488488 """
489489 callback_handler = kwargs .get ("callback_handler" , self .callback_handler )
490490
491- self ._start_agent_trace_span (prompt )
491+ content : list [ContentBlock ] = [{"text" : prompt }] if isinstance (prompt , str ) else prompt
492+ message : Message = {"role" : "user" , "content" : content }
493+
494+ self ._start_agent_trace_span (message )
492495
493496 try :
494- events = self ._run_loop (prompt , kwargs )
497+ events = self ._run_loop (message , kwargs )
495498 async for event in events :
496499 if "callback" in event :
497500 callback_handler (** event ["callback" ])
@@ -507,18 +510,22 @@ async def stream_async(self, prompt: str, **kwargs: Any) -> AsyncIterator[Any]:
507510 self ._end_agent_trace_span (error = e )
508511 raise
509512
510- async def _run_loop (self , prompt : str , kwargs : dict [str , Any ]) -> AsyncGenerator [dict [str , Any ], None ]:
511- """Execute the agent's event loop with the given prompt and parameters."""
513+ async def _run_loop (self , message : Message , kwargs : dict [str , Any ]) -> AsyncGenerator [dict [str , Any ], None ]:
514+ """Execute the agent's event loop with the given message and parameters.
515+
516+ Args:
517+ message: The user message to add to the conversation.
518+ kwargs: Additional parameters to pass to the event loop.
519+
520+ Yields:
521+ Events from the event loop cycle.
522+ """
512523 self ._hooks .invoke_callbacks (StartRequestEvent (agent = self ))
513524
514525 try :
515- # Extract key parameters
516526 yield {"callback" : {"init_event_loop" : True , ** kwargs }}
517527
518- # Set up the user message with optional knowledge base retrieval
519- message_content : list [ContentBlock ] = [{"text" : prompt }]
520- new_message : Message = {"role" : "user" , "content" : message_content }
521- self .messages .append (new_message )
528+ self .messages .append (message )
522529
523530 # Execute the event loop cycle with retry logic for context limits
524531 events = self ._execute_event_loop_cycle (kwargs )
@@ -613,16 +620,16 @@ def _record_tool_execution(
613620 messages .append (tool_result_msg )
614621 messages .append (assistant_msg )
615622
616- def _start_agent_trace_span (self , prompt : str ) -> None :
623+ def _start_agent_trace_span (self , message : Message ) -> None :
617624 """Starts a trace span for the agent.
618625
619626 Args:
620- prompt : The natural language prompt from the user.
627+ message : The user message .
621628 """
622629 model_id = self .model .config .get ("model_id" ) if hasattr (self .model , "config" ) else None
623630
624631 self .trace_span = self .tracer .start_agent_span (
625- prompt = prompt ,
632+ message = message ,
626633 agent_name = self .name ,
627634 model_id = model_id ,
628635 tools = self .tool_names ,
0 commit comments