Skip to main content
External Tool Execution allows you to mark tools as requiring external execution, causing the agent to pause and wait for results before continuing. This is essential for tools that call external services, require human approval, or execute in different systems.

Quick Start

Core Concepts

Defining External Tools

Use the @tool(external_execution=True) decorator to mark tools that require external execution:

External Tool Executor

Create a function to handle external tool execution:

Processing Requirements

When the agent pauses for external tools, access the requirements:

Continuation Methods

Resume with run_id (Same Agent)

The simplest approach - use run_id with the same agent:

Resume with task (Same Agent)

Use task object for in-memory context continuation:

Resume with run_id (New Agent - Cross-Process)

For cross-process resumption with persistent storage:

Resume with task (New Agent - Cross-Process)

New agent using task for continuation:

Multiple External Tools

Loop-Based Handling with run_id

Handle multiple external tools with a loop:

Loop-Based Handling with task

Same pattern using task:

Using Executor Callback for Multiple Tools

Let the executor handle all subsequent tools automatically:

Cross-Process External Tool Handling

Complete pattern for handling external tools across process restarts:

With run_id

With task

Important Notes

  • Direct Call Mode Only: HITL continuation only supports direct call mode. Streaming is not supported.
  • Requirements Parameter: When using a new agent, pass requirements=output.requirements to inject the results into the loaded state.
  • Persistent Storage: For cross-process scenarios, always use persistent storage like SqliteDatabase.
  • is_resolved Check: Always check requirement.is_resolved before processing to avoid re-executing completed tools.