Skip to content

API Reference parrot.bots.flows.crew.tool_node

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

parrot.bots.flows.crew.tool_node

View source

ToolNode — deterministic tool execution node for AgentCrew.

Provides a crew member that is NOT an LLM agent but a direct tool caller: it invokes an AbstractTool with statically declared args/kwargs (pass-through) and wraps the outcome so it is indistinguishable from an agent-execution result to the rest of the flow machinery (FlowResult, context summaries, persistence, FSM lifecycle). No LLM tokens are spent.

Template placeholders — resolved deterministically at execution time from prior results (never via an LLM):

  • {input} — the node's input. Sequential/loop modes: the composed previous input; parallel mode: the task's query; flow mode: the last completed dependency's output (or the initial task when the node has no dependencies).
  • {nodes.<node_name>.output} — the stored output of a previously completed node. Avoid dots in node ids: they are ambiguous inside this placeholder syntax.

A string value that consists of exactly one placeholder is replaced by the referenced value with its native type preserved (a dict result passes through to the tool as a dict). Placeholders embedded in a larger string are substituted via str(). Literal braces that do not match the placeholder grammar (e.g. inline JSON) are left untouched.

Alias AgentTaskMachine

Re-exported from parrot.bots.flows.core.fsm.AgentTaskMachine.

Alias Node

Re-exported from parrot.bots.flows.core.node.Node.

Class TemplateResolutionError

A template placeholder references a node with no stored result.

Class ToolLike

Structural protocol for any object usable as a ToolNode tool.

Mirrors the AgentLike pattern from flows.core.types: using a Protocol (rather than requiring an AbstractTool subclass) keeps the node testable with lightweight doubles while every real AbstractTool satisfies the contract.

Attributes:

Attribute Type Description
name str Tool identifier.

Method ToolLike.execute

Execute the tool and return a ToolResult.

execute(*args: Any, **kwargs: Any) -> Any

Parameter Type Default Description
*args Any ()
**kwargs Any {}

Returns: Any

Class ToolNode

Deterministic tool-caller crew node (no LLM involved).

Registered into a crew via AgentCrew.add_tool_node(), this node participates in every execution mode: sequential/parallel/loop runs dispatch to :meth:call_tool (via AgentCrew._execute_agent), while flow mode invokes :meth:execute with the same contract as AgentNode.execute.

Duck-typing notes:

  • is_configured defaults to True so _ensure_agent_ready never attempts LLM configuration.
  • agent is a self-referencing property: flow-mode plumbing reads node.agent.name and build_node_metadata probes agent attributes with getattr(..., None) — both are safe on this model.
  • The FSM lifecycle is driven externally by the crew scheduler, exactly as for CrewAgentNode.

Attributes:

Attribute Type Description
tool ToolLike
node_id str
args List[Any]
kwargs Dict[str, Any]
description Optional[str]
dependencies Set[str]
successors Set[str]
fsm Optional[AgentTaskMachine]
is_configured bool
name str Node identity (same as node_id for tool nodes).
agent 'ToolNode' Self-reference for flow-mode plumbing that reads node.agent.

Method ToolNode.model_post_init

Auto-create the FSM if not provided; initialise logger.

model_post_init(__context: Any) -> None

Parameter Type Default Description
__context Any

Method ToolNode.configure

No-op — the wrapped tool needs no LLM configuration.

configure() -> None

Method ToolNode.call_tool

Resolve templates and invoke the tool (sequential/parallel/loop path).

Does NOT fire pre/post actions — the sequential, parallel, and loop modes fire run_pre_actions/run_post_actions externally around _execute_agent, so firing them here would double-invoke hooks.

call_tool(*, input_text: str, results: Mapping[str, Any], timeout: Optional[float] = None) -> ToolResult

Parameter Type Default Description
input_text str The node's input for {input} placeholders.
results Mapping[str, Any] Prior node outputs for {nodes.<name>.output}.
timeout Optional[float] None Optional per-call timeout in seconds.

Returns: ToolResult — The successful ToolResult.

Raises:

  • TemplateResolutionError — If a placeholder cannot be resolved.
  • ToolNodeExecutionError — If the tool reports failure.

Method ToolNode.execute

Execute the tool node in flow mode.

Signature/return contract mirrors AgentNode.execute so AgentCrew._execute_parallel_agents can consume the result uniformly.

The FSM lifecycle (start/succeed/fail) is managed externally by the scheduler — do NOT touch self.fsm here.

execute(ctx: Any, deps: Mapping[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameter Type Default Description
ctx Any The current flow execution context.
deps Mapping[str, Any] Mapping of completed dependency node_id → result.
**kwargs Any {} Scheduler kwargs; timeout is honoured, the rest are ignored (never forwarded to the tool).

Returns: Dict[str, Any] — Dict with keys 'response' (the ToolResult), 'output' (string form), 'execution_time' and 'prompt' (rendered call description).

Class ToolNodeExecutionError

The wrapped tool reported failure (ToolResult.success == False).

Alias ToolResult

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

Function extract_tool_output

Return the string form of a ToolResult payload.

Used wherever the crew stores node outputs as strings (FlowContext.results, context summaries, NodeResult).

extract_tool_output(tool_result: ToolResult) -> str

Parameter Type Default Description
tool_result ToolResult The tool execution result to stringify.

Returns: str — The raw string when the payload already is one, otherwise its JSON encoding (falling back to str() for non-serialisable payloads).

Function resolve_templates

Recursively resolve template placeholders inside a value.

Walks nested dicts/lists/tuples and substitutes placeholders found in string values. Non-string leaves pass through unchanged.

resolve_templates(value: Any, *, input_text: str, results: Mapping[str, Any]) -> Any

Parameter Type Default Description
value Any The value to resolve (str, dict, list, tuple, or any leaf).
input_text str Replacement for the {input} placeholder.
results Mapping[str, Any] Mapping of node_id → stored output, used to resolve {nodes.<node_name>.output} placeholders.

Returns: Any — The value with all placeholders resolved. A string that is exactly one placeholder returns the referenced value with native type preserved; embedded placeholders are substituted via str().

Raises:

  • TemplateResolutionError — If a {nodes.<name>.output} placeholder references a node absent from results.

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