@@ -431,25 +431,26 @@ async def end(self) -> None:
431431 await stop_bidirectional_connection (self ._session )
432432 self ._session = None
433433
434- async def __call__ (
434+ async def run (
435435 self ,
436- send_callable : Callable [[Any ], Any ],
437- receive_callable : Callable [[], Any ],
436+ * ,
437+ sender : Callable [[Any ], Any ],
438+ receiver : Callable [[], Any ],
438439 ) -> None :
439440 """Run the agent with send/receive loop management.
440441
441442 Starts the session, pipes events between the agent and transport layer,
442443 and handles cleanup on disconnection.
443444
444445 Args:
445- send_callable : Async callable that sends events to the client (e.g., websocket.send_json).
446- receive_callable : Async callable that receives events from the client (e.g., websocket.receive_json).
446+ sender : Async callable that sends events to the client (e.g., websocket.send_json).
447+ receiver : Async callable that receives events from the client (e.g., websocket.receive_json).
447448
448449 Example:
449450 ```python
450451 # With WebSocket
451452 agent = BidirectionalAgent(model=model, tools=[calculator])
452- await agent.run(websocket.send_json, websocket.receive_json)
453+ await agent.run(sender= websocket.send_json, receiver= websocket.receive_json)
453454
454455 # With custom transport
455456 async def custom_send(event):
@@ -460,7 +461,7 @@ async def custom_receive():
460461 # Custom receive logic
461462 return event
462463
463- await agent.run(custom_send, custom_receive)
464+ await agent.run(sender= custom_send, receiver= custom_receive)
464465 ```
465466
466467 Raises:
@@ -472,7 +473,7 @@ async def receive_from_agent():
472473 """Receive events from agent and send to client."""
473474 try :
474475 async for event in self .receive ():
475- await send_callable (event )
476+ await sender (event )
476477 except Exception as e :
477478 logger .debug (f"Receive from agent stopped: { e } " )
478479 raise
@@ -481,7 +482,7 @@ async def send_to_agent():
481482 """Receive events from client and send to agent."""
482483 try :
483484 while self ._session and self ._session .active :
484- event = await receive_callable ()
485+ event = await receiver ()
485486 await self .send (event )
486487 except Exception as e :
487488 logger .debug (f"Send to agent stopped: { e } " )
0 commit comments