pipelines.agent.base
AgentExecutor
def AgentExecutor(
model:str, agent_type:str='function_calling', max_iterations:int=50, env_file:Optional=None, sandbox:bool=False,
image:str='python:3.11-slim', network:str='bridge', memory:Optional=None, cpus:Optional=None,
custom_tools:Optional=None, enabled_tools:Optional=None, disable_shell:bool=False,
completion_promise:str='COMPLETE', verbose:bool=True
):
Sandboxed agent executor using patchpal-sandbox.
This executor is a Python wrapper around patchpal-sandbox, providing: - Resource isolation and security via Docker/Podman containers - Support for both cloud and local LLMs - Custom tool integration via ~/.patchpal/tools/ - API key management via .env files
Args: model (str): LiteLLM model identifier (e.g., ‘anthropic/claude-sonnet-4-5’, ‘ollama_chat/gpt-oss-120b’) agent_type (str): Type of agent (‘function_calling’ or ‘react’) max_iterations (int): Maximum number of autopilot iterations env_file (str): Path to .env file with API keys sandbox (bool): Run in container sandbox (default: False). Set True for isolated/secure execution. image (str): Container image to use (default: python:3.11-slim) [sandbox only] network (str): Network mode (‘bridge’, ‘host’, ‘none’) [sandbox only] memory (str): Memory limit (e.g., ‘2g’, ‘4g’) [sandbox only] cpus (float): CPU limit (e.g., 2, 4) [sandbox only] custom_tools (list): List of Python functions to use as custom tools. Each function should have type hints and a docstring. These will be written to .patchpal/tools/ directory in the working directory and automatically discovered by PatchPal.
Example:
def calculate_sum(a: int, b: int) -> int:
'''Add two numbers together.
Args:
a: First number
b: Second number
Returns:
Sum of a and b
'''
return a + b
executor = AgentExecutor(
model='anthropic/claude-sonnet-4-5',
custom_tools=[calculate_sum]
)
enabled_tools (list): List of tool names to enable. If None, uses DEFAULT_TOOLS:
['read_file', 'read_lines', 'edit_file', 'write_file',
'grep', 'find', 'run_shell', 'web_search', 'web_fetch']
Pass an empty list [] to use all available patchpal tools.
disable_shell (bool): If True, remove 'run_shell' from default tools (default: False).
Only applies when enabled_tools=None. Useful for security when you
want defaults but no shell access.
completion_promise (str): String that signals task completion (default: 'COMPLETE')
verbose (bool): Show progress output in real-time (default: True). When False, output is
captured but not displayed (useful for automated scripts/logging).
AgentExecutor.run
def run(
task:str, working_dir:Optional=None
)->str:
Run the agent on a given task in a sandboxed environment.
Args: task (str): The task description/prompt working_dir (str): Directory to run in (default: current directory)
Returns: str: The agent’s response/output
Raises: RuntimeError: If agent execution fails FileNotFoundError: If patchpal-sandbox is not installed