Skip to content

API Reference parrot.tools.executors.runner

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.executors.runner

View source

In-process envelope runner shared by LocalToolExecutor and the k8s/qworker worker entrypoints.

The runner takes a deserialized ToolExecutionEnvelope, imports the referenced class, instantiates it, and invokes the underlying _execute method (or the toolkit-bound method) returning a :class:ToolResult. It is intentionally minimal: permission checks, lifecycle events, and result-shape normalisation have already happened on the caller side (or will, when the result returns).

Attribute RESULT_BEGIN_MARKER

Attribute RESULT_END_MARKER

Alias ToolExecutionEnvelope

Re-exported from parrot.tools.executors.abstract.ToolExecutionEnvelope.

Alias ToolResult

Re-exported from parrot.tools.abstract.ToolResult.

Attribute logger

Function parse_sentinel_output

Extract the worker's marker-delimited ToolResult from output.

The worker writes the JSON result between __PARROT_TOOL_RESULT_BEGIN__ and __PARROT_TOOL_RESULT_END__ so unrelated log chatter is ignored. Shared by every executor that reads worker stdout (K8s pod logs, Docker container logs / exec streams).

parse_sentinel_output(output: str, *, metadata: Dict[str, Any]) -> 'ToolResult'

Parameter Type Default Description
output str Raw combined stdout/stderr captured from the worker.
metadata Dict[str, Any] Executor-identifying keys stamped onto the result's metadata in every branch (success and error) so observers can correlate.

Returns: 'ToolResult'

Function run_envelope_inprocess

Execute envelope in the current Python process.

Returns the :class:ToolResult produced by the tool's underlying _execute implementation (or by the toolkit-bound method). The caller is responsible for any further normalisation — typically AbstractTool.execute does that wrapping.

Layered behaviour:

  • Plain AbstractTool subclasses are instantiated and await tool._execute(**arguments) is called.
  • Toolkit-bound envelopes (method_name is not None) instantiate the toolkit, look up the named method, and call it with arguments. This mirrors what :meth:ToolkitTool._execute would do, minus the _pre_execute / _post_execute hooks because we want the remote runtime to behave like a pure worker.

FEAT-391: this runner instantiates a fresh instance per envelope and never goes through AbstractTool.execute() / ToolkitTool._execute() — so the auto_open lazy-lifecycle wiring in those methods never runs here. If instance.auto_open is True (only present on tool/toolkit classes built on this feature), this function calls _ensure_open() itself before invoking _execute()/the bound method, and — because the instance is ephemeral (discarded after this single call, never pooled across envelopes) — always calls _close() afterwards in a finally so resources opened for this one call don't leak.

run_envelope_inprocess(envelope: ToolExecutionEnvelope) -> Any

Parameter Type Default Description
envelope ToolExecutionEnvelope

Returns: Any

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally