Skip to main content
The Workflow.run() function runs the agent and generates a response, either as a WorkflowRunResponse object or a stream of WorkflowRunResponse objects. Many of our examples use workflow.print_response() which is a helper utility to print the response in the terminal. This uses workflow.run() under the hood.

Running your Workflow

Here’s how to run your workflow. The response is captured in the response.
The Workflow.run() function returns a WorkflowRunResponse object when not streaming. Here is detailed documentation for `WorkflowRunResponse.

Async Execution

The Workflow.arun() function is the async version of Workflow.run(). Here is an example of how to use it:

Streaming Responses

To enable streaming, set stream=True when calling run(). This will return an iterator of WorkflowRunResponseEvent objects instead of a single response.

Streaming Intermediate Steps

In the case where you put stream_intermediate_steps=False (or not set it at all), we only yield WorkflowStartedEvent, WorkflowCompletedEvent along with all the Agent/Team events.
For even more detailed streaming, you can enable intermediate steps by setting stream_intermediate_steps=True. This will provide real-time updates about each step of the workflow.

Async Streaming

The Workflow.arun(stream=True) returns an async iterator of WorkflowRunResponseEvent objects instead of a single response. So for example, if you want to stream the response, you can do the following:

Event Types

The following events are yielded by the Workflow.run() and Workflow.arun() functions depending on the workflow’s configuration:

Core Events

Step Events

Step Output Events (For custom functions)

Parallel Execution Events

Condition Execution Events

Loop Execution Events

Router Execution Events

Steps Execution Events

See detailed documentation in the WorkflowRunResponseEvent documentation.