mechaharness.tools.base

Tool protocol and in-process tool registry.

class mechaharness.tools.base.Tool(name: str, handler: Callable[[...], str | Awaitable[str]], *, description: str = '', parameters: dict[str, Any] | None = None, grants: Sequence[object] | None = None, ability: Ability = Ability.SIMPLE)[source]

Bases: object

A named callable exposed to harnesses as a ToolDefinition.

__init__(name: str, handler: Callable[[...], str | Awaitable[str]], *, description: str = '', parameters: dict[str, Any] | None = None, grants: Sequence[object] | None = None, ability: Ability = Ability.SIMPLE) → None[source]
definition() → ToolDefinition[source]
async invoke(arguments: dict[str, Any], tool_call_id: str) → ToolResult[source]
class mechaharness.tools.base.ToolRegistry[source]

Bases: object

In-process map of tool name → Tool for harness tool calling.

__init__() → None[source]
definitions() → list[ToolDefinition][source]

Provider-agnostic schemas for the current tool set.

async execute(name: str, arguments: dict[str, Any], tool_call_id: str) → ToolResult[source]
get(name: str) → Tool[source]

Return a registered tool or raise KeyError.

register(tool: Tool) → None[source]

Add or replace a tool by name.

tool(name: str | None = None, *, description: str = '', parameters: dict[str, Any] | None = None, grants: Sequence[object] | None = None, ability: Ability = Ability.SIMPLE) → Callable[[Callable[[...], str | Awaitable[str]]], Callable[[...], str | Awaitable[str]]][source]

Decorator that registers the wrapped function as a tool.