Implementing streaming in Agency Swarm.
get_completion_stream
method with your own event handler. The process follows a similar pattern to the official OpenAI documentation.
The only difference is that you must extend the AgencyEventHandler
class, which has 2 additional properties: agent_name
and recipient_agent_name
, to get the names of the agents communicating with each other. (See the on_text_created
below.)
on_all_streams_end
class method is called when all streams have ended. This is particularly important since your
event handler might be called multiple times and possibly by multiple agents, unlike in the official OpenAI
documentation.