Skip to main content
Agents can be executed using different methods depending on your needs - synchronous, asynchronous, or streaming.

Synchronous Execution

The simplest way to run an agent is using the do() method, which executes synchronously and returns the result.

List Input (Multiple Tasks)

do(), do_async(), print_do(), and print_do_async() accept a list of strings or a list of Task objects. They run each item in sequence and return a list of string results. A single-element list returns a single string (scalar); an empty list returns an empty list. Mixed lists of str and Task are supported.

List of strings

List of Task objects

Asynchronous Execution

For concurrent operations or async applications, use do_async() which returns a coroutine.

Streaming Text Output

For real-time output, use stream() to get responses as they’re generated.

Event Streaming

For full visibility into agent execution, use astream() (or stream() for synchronous code) with events=True to receive detailed events about every step of the pipeline.

Event Categories

Pipeline Events

Step Events

Tool Events

LLM Stream Events

Initialization & Model Events

Context & Input Build Events

These fire once per run as the agent assembles the request sent to the model. Useful for inspecting what the model actually receives (history size, prompt length, attached media).

Cache Events

Policy Events

Memory, Reflection & Reliability Events

Run Lifecycle Events

Common Attributes

All events inherit from AgentEvent and share these base attributes:

Synchronous Event Streaming

For synchronous code, use stream() with events=True:
Note: The stream() method returns an iterator that yields either:
  • str chunks when events=False (default) - for text streaming
  • AgentStreamEvent objects when events=True - for event streaming
For async streaming, use astream() with the same events parameter.

Tool Management

Tools can be added to agents during initialization or dynamically using add_tools(). Use get_tool_defs() to retrieve all registered tool definitions.