pipelines.agent.base

Agent-based task execution pipeline that wraps PatchPal to provide autonomous task completion capabilities.

source

AgentExecutor

def AgentExecutor(
    model:str, agent_type:str='function_calling', max_iterations:int=50, env_file:Optional[str]=None,
    sandbox:bool=False, image:str='ghcr.io/amaiya/patchpal-sandbox:latest', network:str='bridge',
    memory:Optional[str]=None, cpus:Optional[float]=None, restrict_network:bool=False,
    allow_urls:Optional[List[str]]=None, custom_tools:Optional[List[Callable]]=None,
    enabled_tools:Optional[List[str]]=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: ghcr.io/amaiya/patchpal-sandbox:latest) [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] restrict_network (bool): Enable iptables firewall for network isolation (default: False) [sandbox only] Automatically detects LLM endpoints from environment variables. Blocks all network access except whitelisted URLs. Web tools and MCP are automatically disabled. Ideal for sensitive/regulated environments. allow_urls (list): Additional URLs to whitelist when restrict_network=True [sandbox only] LLM provider endpoints are auto-detected from env vars. Use this to add package repos (pypi.org) or code repos (github.com). Example: allow_urls=[‘https://pypi.org’, ‘https://github.com’] 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',
                      'code_structure', 'repo_map']
                     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).

source

AgentExecutor.run

def run(
    task:str, working_dir:Optional[str]=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