@@ -288,20 +288,26 @@ def register(self, runtime: Runtime) -> None:
288288 """Register the agent specification to a runtime."""
289289 self .__runtime = runtime
290290
291- async def run (self , msg : RawMessage , timeout : float = 0.5 ) -> RawMessage :
291+ async def run (
292+ self , msg : RawMessage , session_id : str = "" , timeout : float = 0.5
293+ ) -> RawMessage :
292294 """Create an agent and run it with the given message."""
293295 self .__assert_runtime ()
294296
295- addr = Address (name = self .name , id = uuid .uuid4 ().hex )
297+ session_id = session_id or uuid .uuid4 ().hex
298+ addr = Address (name = self .name , id = session_id )
296299 return await self .__runtime .channel .publish (
297300 addr , msg , request = True , timeout = timeout
298301 )
299302
300- async def run_stream (self , msg : RawMessage ) -> AsyncIterator [RawMessage ]:
303+ async def run_stream (
304+ self , msg : RawMessage , session_id : str = ""
305+ ) -> AsyncIterator [RawMessage ]:
301306 """Create an agent and run it with the given message."""
302307 self .__assert_runtime ()
303308
304- addr = Address (name = self .name , id = uuid .uuid4 ().hex )
309+ session_id = session_id or uuid .uuid4 ().hex
310+ addr = Address (name = self .name , id = session_id )
305311 result = self .__runtime .channel .publish_multi (addr , msg )
306312 async for chunk in result :
307313 yield chunk
0 commit comments