Skip to main content
Run your team with Team.run() (sync) or Team.arun() (async).

Basic Execution

Run the example

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

4

Run the example

Save the code as running_team.py, then run:

Execution Flow

When you call run():
  1. Pre-hooks execute (if configured)
  2. Reasoning runs (if enabled) to plan the task
  3. Context is built with system message, history, memories, and session state
  4. Model decides whether to respond directly, use tools, or delegate to members
  5. Delegated members execute their tasks. Multiple async member calls can run concurrently.
  6. Leader completes the run by returning a routed member response or synthesizing member results, depending on the mode.
  7. Post-hooks execute (if configured)
  8. Session and metrics are stored (if database configured)
Callable factories are resolved after session state is loaded, so factories can access run_context and session_state. Async factories require arun() or aprint_response(). In TeamMode.tasks, the leader uses task management tools to build and execute a shared task list, looping until the goal is complete or max_iterations is reached. Teams can pause for human-in-the-loop requirements (e.g., approvals or user input). When a run requires confirmation, the run returns with pending requirements so you can collect input or resolve approvals before continuing. Paused runs return status=RunStatus.paused and requirements on the TeamRunOutput.
Team execution flow

Streaming

Enable streaming with stream=True. This returns an iterator of team events and can include delegated member events.
In TeamMode.tasks, stream_events=True also emits TeamTaskCreated, TeamTaskUpdated, TeamTaskStateUpdated, TeamTaskIterationStarted, and TeamTaskIterationCompleted. See Task Mode Streaming Events.

Stream All Events

Team content is streamed by default. Delegated member events are also forwarded because stream_member_events=True by default. Set stream_events=True to include all team-level tool, reasoning, hook, and lifecycle events:

Stream Member Events

Delegated member events are forwarded by default. In async broadcast mode, member runs execute concurrently and their events can interleave. Set stream_member_events=False to suppress member events:

Run Output

Team.run() returns a TeamRunOutput object containing: See TeamRunOutput reference for the full schema.

Async Execution

Use arun() for async execution. Members run concurrently when the leader delegates to multiple members at once.

Tasks Mode

Tasks mode runs an iterative loop that creates, executes, and updates tasks until the goal is complete or max_iterations is reached.

Specifying User and Session

Associate runs with a user and session for history tracking:
See Sessions for details.

Passing Files

Pass images, audio, video, or files to the team:
See Multimodal for details.

Structured Output

Pass an output schema to get structured responses:
See Input & Output for details.

Cancelling Runs

Cancel a running team with Team.cancel_run(). See Run Cancellation. For development, use print_response() to display formatted output:

Core Events

Tool Events

Reasoning Events

Memory Events

Hook Events

Background Execution

Run teams in the background with arun(background=True). Background execution requires a database so Agno can persist run state. With stream=True, Agno retains up to 10,000 events per run in memory for reconnection while the AgentOS process remains alive. After a disconnect, an AgentOS client calls the run’s /resume endpoint with the last received event index. See Background Execution for polling, resumable streaming, and the /resume endpoint.

Developer Resources