Workflows are all about control and flexibility. You have full control over the multi-agent process, how the input is processed, which agents are used and in what order.
You also have full control over how the output is streamed.
Streaming
To stream the output, yield an Iterator[RunResponse]
from the run()
method of your workflow.
class GenerateNewsReport(Workflow):
agent_1: Agent = ...
agent_2: Agent = ...
agent_3: Agent = ...
def run(self, ...) -> Iterator[RunResponse]:
final_agent_input = ...
agent_3_response_stream: Iterator[RunResponse] = self.agent_3.run(final_agent_input, stream=True)
yield agent_3_response_stream
generate_news_report = GenerateNewsReport()
report_stream: Iterator[RunResponse] = generate_news_report.run(...)
pprint_run_response(report_stream, markdown=True)
Batch
Simply return a RunResponse
object from the run()
method of your workflow to return a single output.
class GenerateNewsReport(Workflow):
agent_1: Agent = ...
agent_2: Agent = ...
agent_3: Agent = ...
def run(self, ...) -> RunResponse:
final_agent_input = ...
agent_3_response: RunResponse = self.agent_3.run(final_agent_input)
return agent_3_response
generate_news_report = GenerateNewsReport()
report: RunResponse = generate_news_report.run(...)
pprint_run_response(report, markdown=True)