Skip to main content

Documentation Index

Fetch the complete documentation index at: https://allhandsai-redo-dynamic-workflow-mvp.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

A ready-to-run example is available here!
Dynamic workflows are experimental. The workflow tool executes generated Python orchestration code after best-effort validation, so use it only for workflows you are comfortable approving as generated code execution.

Overview

Dynamic workflows let a parent agent write a small Python script that coordinates sub-agents through a constrained wf object. This is useful when the parent agent needs to keep intermediate results out of the main conversation while fanning out work across independent areas and then reducing the results into one answer. The workflow script defines one entry point:
async def main(wf):
    ...
Inside that function, the script can:
  • run one sub-agent with await wf.run_agent(...)
  • fan out across many inputs with await wf.map_agents(...)
  • synthesize intermediate outputs with await wf.reduce_agent(...)
  • flatten one level of nested values with wf.flatten(...)
The implementation reuses the SDK’s existing sub-agent task machinery, so workflow sub-agents inherit the current workspace and normal tool/security behavior.

When to use dynamic workflows

Use dynamic workflows for tasks where the parent agent should create the orchestration plan at runtime, such as:
  • auditing test coverage across multiple project areas
  • reviewing documentation quality by directory
  • comparing several implementation strategies in parallel
  • collecting independent findings and reducing them into a final report
For simple sequential delegation, use Task Tool Set. For parallel tool calls chosen directly by a model in one step, see Parallel Tool Execution.

Ready-to-run example

The example below asks the parent agent to write and run workflow code for a realistic test coverage audit. The parent agent owns the workflow tool; the generated workflow fans out coverage_auditor sub-agents by project area and then reduces their findings into a repo-wide report.
examples/01_standalone_sdk/52_dynamic_workflow.py
# This code block is synced from the Agent SDK repository.
You can run the example code as-is.
The model name should follow the LiteLLM convention: provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o). The LLM_API_KEY should be the API key for your chosen provider.
ChatGPT Plus/Pro subscribers: You can use LLM.subscription_login() to authenticate with your ChatGPT account and access Codex models without consuming API credits. See the LLM Subscriptions guide for details.