Skip to content

API Reference parrot.tools.host_hooks

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

parrot.tools.host_hooks

View source

Hooks a HOST (e.g. the Agent Studio service) registers to police the tools of the agents it builds.

Every hook is optional; absent means the previous behaviour. FEATURES is the boot-time probe: a host checks "toolkit_param_hook" in parrot.tools.host_hooks.FEATURES (an ImportError means an older parrot).

Toolkit-parameter hook (PA-9)

app[STUDIO_TOOLKIT_PARAM_HOOK] = hook with hook(slug, params, subject) -> params:

  • slug is the tool/toolkit slug, params a COPY of the constructor parameters (client values, then the server-managed fill), subject a :class:~parrot.tools.tooling_policy.ToolingSubject (tenant, agent id, actor and the phase: write/activate at write time, attach for a live assignment, build for a stored agent).
  • it returns the FINAL parameters: it may add, replace or remove keys (force a directory, programs…). The special key exclude_tools (a sequence of method names) is applied to the constructed instance, whatever its constructor accepts, and can only ADD to the class's own exclusions.
  • it may raise :class:~parrot.tools.tooling_policy.ToolParamRefused naming the refused parameters. Any other error, an awaitable or a non-mapping result also refuses (fail closed).

The hook runs on every path that constructs a toolkit for a Studio agent: at write time (policy enforcement, dry run: the result is discarded), on a live assignment, and at build time of a stored agent (which fails closed).

TOOL_CALL guardrails (PA-10)

app[STUDIO_TOOL_CALL_GUARDRAILS] = [guardrail, ...] — the existing TOOL_CALL guardrail protocol (:class:parrot.bots.guardrails.base.Guardrail: async check(content, ctx) -> GuardrailResult). Every Studio-built bot gets each of them on its TOOL_CALL pipeline, so they run before every tool call with ctx.extras["arguments"] (the call's arguments) and ctx.tool_name. Each guardrail is wrapped per bot: it sees ctx.extras["studio"] == {"tenant", "agent_id", "agent", "visibility"} of THAT bot, a raising guardrail BLOCKS (fail closed) whatever its own on_error, and a BLOCK's reason is the tool's refusal that reaches the LLM and the audit line. The direct POST /tools/{slug}/execute route runs the same guardrails (agent is None there).

Attribute EXCLUDE_TOOLS_KEY

Attribute FEATURES

Attribute STUDIO_TOOLKIT_PARAM_HOOK

Attribute STUDIO_TOOL_CALL_GUARDRAILS

Alias ToolParamRefused

Re-exported from parrot.tools.tooling_policy.ToolParamRefused.

Attribute ToolkitParamHook

Function apply_exclude_tools

Hide exclude methods of a constructed toolkit (instance-level; the class's own exclusions are kept).

apply_exclude_tools(instance: Any, exclude: tuple[str, ...]) -> None

Parameter Type Default Description
instance Any
exclude tuple[str, ...]

Function bind_host_tool_call_guardrails

Register the host's guardrails on pipeline (a bot's TOOL_CALL pipeline) for the bot described by studio; returns how many were registered. An object without a check method is a configuration error.

bind_host_tool_call_guardrails(pipeline: Any, guardrails: Any, studio: Mapping[str, Any]) -> int

Parameter Type Default Description
pipeline Any
guardrails Any
studio Mapping[str, Any]

Returns: int

Function bind_tenant_allow_list_guardrail

Enforce the host's per-tenant allow-lists (tenant_builtin_tools / tenant_toolkits) when a tool is CALLED.

The lists are write-time checks (an unchanged stored tool is exempt so an unrelated edit stays possible and a stored agent still builds), so shrinking a tenant's list would otherwise leave every stored agent running the removed tool. This guardrail closes that: a call to a built-in / host toolkit the tenant no longer has is BLOCKED (builtin_not_permitted / toolkit_unavailable). Nothing is registered (returns False) when there is no tenant or the policy has neither callback, so hosts that do not use the lists see no change.

bind_tenant_allow_list_guardrail(pipeline: Any, policy: Any, tenant: str | None, tool_manager: Any) -> bool

Parameter Type Default Description
pipeline Any
policy Any
tenant str | None
tool_manager Any

Returns: bool

Function check_toolkit_params

Write-time dry run: the host hook sees every toolkit spec's parameters and may refuse them.

A no-op without a registered hook. The hook's result is discarded here (forced values are applied when the toolkit is constructed); only a refusal matters. Raises :class:ToolParamRefused (a TenantToolingRefused).

check_toolkit_params(app: Mapping[str, Any], tooling: 'NormalizedTooling', *, subject: 'ToolingSubject') -> None

Parameter Type Default Description
app Mapping[str, Any]
tooling 'NormalizedTooling'
subject 'ToolingSubject'

Function host_tool_call_pipeline

A stand-alone TOOL_CALL pipeline of the host's guardrails (for tool calls made outside a bot).

host_tool_call_pipeline(guardrails: Any, studio: Mapping[str, Any]) -> Any

Parameter Type Default Description
guardrails Any
studio Mapping[str, Any]

Returns: Any

Function run_toolkit_param_hook

The final parameters of slug after hook (a new dict); raises :class:ToolParamRefused.

The hook gets a copy, so mutating it never reaches the caller's dict. Fails closed on any other exception, an awaitable and a non-mapping result.

run_toolkit_param_hook(hook: ToolkitParamHook, slug: str, params: Mapping[str, Any], subject: 'ToolingSubject') -> dict[str, Any]

Parameter Type Default Description
hook ToolkitParamHook
slug str
params Mapping[str, Any]
subject 'ToolingSubject'

Returns: dict[str, Any]

Function split_exclude_tools

(params without exclude_tools, the forced exclusions).

split_exclude_tools(params: Mapping[str, Any]) -> tuple[dict[str, Any], tuple[str, ...]]

Parameter Type Default Description
params Mapping[str, Any]

Returns: tuple[dict[str, Any], tuple[str, ...]]

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