- Enhanced security: Execute sensitive operations in a controlled environment
- External service calls: Integrate with services that require special handling
- Database operations: Run queries through your own connection management
- Custom execution logic: Add validation, logging, or rate limiting before execution
- Sandboxed environments: Execute potentially dangerous operations safely
How It Works
When you mark a tool with@tool(external_execution=True), your agent will:
- Pause execution when the tool is about to be called
- Set
is_pausedtoTrueon the run response - Populate
tools_awaiting_external_executionwith tools that need external handling - Wait for you to execute the tool and set its result
- Continue execution once you call
continue_run()with the result
execute_shell_command but doesn’t actually execute it. Instead, it pauses and gives you the tool name and arguments. You then execute it yourself (or something completely different!) and provide the result back.
Understanding External Tool Execution Requirements
When a run is paused for external execution, the returnedRunOutput will contain a list of requirement objects.
These requirement objects will contain the tool executions that need to run outside of the agent’s run.
You can find the tool related to each requirement in requirement.tool_execution. Each tool execution object contains:
tool_name: The name of the tool that was calledtool_args: A dictionary of arguments the agent wants to pass to the toolexternal_execution_required: A boolean flag set toTrueresult: Where you set the execution result (initiallyNone)
Important: You must resolve all external tool execution requirements before calling
continue_run().
An external tool execution requirement is considered resolved when you set requirement.external_execution_result.Else Agno will raise a ValueError, letting you know that not all requirements have been resolved.Using Toolkits with External Execution
If you’re using aToolkit, you can specify which tools require external execution using the external_execution_required_tools parameter:
Mixed Tool Scenarios
You can absolutely have a mix of regular tools and external execution tools in the same agent. When the agent wants to call multiple tools, only the ones marked with@tool(external_execution=True) will cause a pause:
Async Support
External execution works seamlessly with async operations. Usearun() and acontinue_run() for async flows:
Streaming Support
You can also use external execution with streaming responses:Best Practices
- Always set results: Make sure you set
requirement.external_execution_resultfor all requirements before continuing - Error handling: Wrap your external execution in try-catch blocks and provide meaningful error messages as results
- Security validation: Use external execution to add extra security checks before running sensitive operations
- Logging: Log all external executions for audit trails
- Timeouts: Consider adding timeouts to your external execution logic to prevent hanging
Usage Examples
Basic External Execution
Execute tools outside the agent’s control
Async External Execution
Using external execution with async agents
Streaming External Execution
External execution with streaming responses
Toolkit External Execution
Using external execution with toolkits