Skip to content

automaton.proxy

WARNING

This documentation is almost entirely "vibe coded"; while a helpful resource for humans and agents to understand this codebase, it should not be considered a source of ground truth in the way documentation normally is, and the user is responsible for verifying that all instructions given here are safe.

automaton.proxy

Loopback model proxy for Automaton.

A host-side broker forwards HTTP requests from a sandboxed harness to the upstream model API while a sandbox-local HTTP proxy serves the harness on sandbox localhost. This split design lets Automaton inject authentication credentials, honor provider TLS configuration, and retry dropped upstream requests within a bounded deadline without exposing the host network to the sandbox.

ProviderExecutedToolBlocked

ProviderExecutedToolBlocked(tool_types: list[str], detail: str)

Bases: RuntimeError

Raised when a request declares a provider-executed tool that is not allowed.

See :data:PROVIDER_EXECUTED_TOOL_TYPES for why these are blocked by default.

Source code in automaton/proxy.py
def __init__(self, tool_types: list[str], detail: str):
    self.tool_types = tool_types
    self.detail = detail
    super().__init__(detail)

EndpointRetryExhausted

EndpointRetryExhausted(detail: str)

Bases: RuntimeError

Raised when the model proxy cannot obtain a complete upstream response.

Source code in automaton/proxy.py
def __init__(self, detail: str):
    self.detail = detail
    super().__init__(detail)

ModelProxy

ModelProxy(model_registry: dict[str, dict[str, Any]], log_file: Path, request_deadline_seconds: float = 900.0, usage_records_file: Path | None = None, allowed_provider_executed_tools: frozenset[str] | set[str] | None = None, budget_exhausted_callback: 'Callable[[str], None] | None' = None)

Loopback-only split proxy for sandboxed harness execution.

A host-side broker forwards requests to the upstream model API while a sandbox-local HTTP proxy serves the harness on sandbox localhost.

Parameters:

Name Type Description Default
model_registry dict[str, dict[str, Any]]

Mapping of configured model names to upstream connection details

required
log_file Path

Path to log file for request/response logging

required
request_deadline_seconds float

Total time budget for one upstream request including retries

900.0
usage_records_file Path | None

Optional JSONL file to append per-request usage records to

None
allowed_provider_executed_tools Iterable[str] | None

Provider-executed tool types to permit. Empty/None (the default) blocks all of them: they run on the provider's infrastructure rather than in the sandbox, so the sandbox network namespace cannot confine them and their activity is invisible to the harness transcript. See :data:PROVIDER_EXECUTED_TOOL_TYPES.

None

Attributes:

Name Type Description
usage_records list[dict[str, Any]]

Recorded per-request usage accounting records

Examples:

>>> registry = {"demo": {"base_url": "https://api.example.com/v1", "api_key": "key", "model": "demo/model"}}
>>> with ModelProxy(registry, Path("proxy.log")) as proxy:
...     len(proxy.usage_records)
0
Source code in automaton/proxy.py
def __init__(
    self,
    model_registry: dict[str, dict[str, Any]],
    log_file: Path,
    request_deadline_seconds: float = 900.0,
    usage_records_file: Path | None = None,
    allowed_provider_executed_tools: frozenset[str] | set[str] | None = None,
    budget_exhausted_callback: "Callable[[str], None] | None" = None,
):
    self.core = _UpstreamProxyCore(
        model_registry,
        log_file,
        request_deadline_seconds=request_deadline_seconds,
        usage_records_file=usage_records_file,
        allowed_provider_executed_tools=allowed_provider_executed_tools,
        budget_exhausted_callback=budget_exhausted_callback,
    )
    self.log_file = log_file
    self._broker_thread: threading.Thread | None = None
    self._socketpair: tuple[socket.socket, socket.socket] | None = None
    self._broker_lock = threading.Lock()

budget_exhausted property

budget_exhausted: bool

True once the proxy saw an upstream spent-budget response (opt-in).

blocked_provider_executed_tools property

blocked_provider_executed_tools: list[str]

Provider-executed tool types this proxy refused to forward.

find_provider_executed_tools

find_provider_executed_tools(body: Any) -> list[str]

Return the provider-executed tool types declared in a request body.

Recurses into Responses-API namespace tools, which nest a tools list. Unknown tool types are reported too: a tool that is neither a recognized local type nor a known provider type is treated as suspect so that new provider-side capabilities fail closed rather than passing silently.

Parameters:

Name Type Description Default
body Any

Parsed JSON request body. Non-dict input yields an empty list.

required

Returns:

Type Description
list[str]

Sorted, de-duplicated tool types that are not locally executed.

Examples:

>>> find_provider_executed_tools({"tools": [{"type": "web_search"}]})
['web_search']
>>> find_provider_executed_tools({"tools": [{"type": "function", "name": "ls"}]})
[]
Source code in automaton/proxy.py
def find_provider_executed_tools(body: Any) -> list[str]:
    """Return the provider-executed tool types declared in a request body.

    Recurses into Responses-API ``namespace`` tools, which nest a ``tools`` list.
    Unknown tool types are reported too: a tool that is neither a recognized
    local type nor a known provider type is treated as suspect so that new
    provider-side capabilities fail closed rather than passing silently.

    Parameters
    ----------
    body : Any
        Parsed JSON request body. Non-dict input yields an empty list.

    Returns
    -------
    list[str]
        Sorted, de-duplicated tool types that are not locally executed.

    Examples
    --------
    >>> find_provider_executed_tools({"tools": [{"type": "web_search"}]})
    ['web_search']
    >>> find_provider_executed_tools({"tools": [{"type": "function", "name": "ls"}]})
    []
    """
    if not isinstance(body, dict):
        return []

    found: set[str] = set()

    def walk(tools: Any) -> None:
        if not isinstance(tools, list):
            return
        for tool in tools:
            if not isinstance(tool, dict):
                continue
            raw_type = tool.get("type")
            tool_type = str(raw_type).strip().lower() if raw_type is not None else ""

            if tool_type == "namespace":
                # Namespaces nest their own tool list; recurse into it.
                walk(tool.get("tools"))
                continue

            if tool_type in LOCALLY_EXECUTED_TOOL_TYPES:
                continue

            if tool_type in PROVIDER_EXECUTED_TOOL_TYPES:
                found.add(tool_type)
                continue

            # Unrecognized type. A locally executed tool carries a callable
            # signature (a name plus parameters/input schema); a provider-side
            # capability is typically just a bare type. Treat anything without a
            # local call signature as provider-executed so new native tools fail
            # closed.
            has_local_signature = "name" in tool and (
                "parameters" in tool or "input_schema" in tool
            )
            if not has_local_signature:
                found.add(tool_type or "<missing type>")

    walk(body.get("tools"))
    # Chat Completions nests the callable under "function"; those are local and
    # already skipped by type == "function" above.
    return sorted(found)