rath.flow.tool#
Model-visible tool interface, built-in tools, tool table merging, and backend payload factories.
Source#
Module |
Source |
|---|---|
|
|
|
|
|
|
|
|
Public contract#
FlowToolCall#
Member |
Type |
Description |
|---|---|---|
|
|
OpenAI function tool name. |
|
|
Optional tool description. |
|
|
JSON Schema object. |
|
|
Whether the default async scheduler may run this tool beside another call of the same tool name. |
|
|
Runtime execution entrypoint. |
|
|
Concurrency grouping key. Calls with the same key run serially; distinct keys may run concurrently. |
By default, tools are conservative: parallel_safe=False groups calls under ("global",). Tools that are safe to run concurrently can set parallel_safe=True or override resource_key(...) to group by file path, remote resource id, account id, or another domain-specific lock key.
Built-in tools#
Tool |
Name |
Arguments |
Behavior |
|---|---|---|---|
|
|
|
Calls |
|
|
|
Calls |
FlowToolCommandRun rejects multiline commands and commands longer than 2048 characters. FlowToolFilesWrite requires content to be text.
Tool table#
Function |
Returns |
Behavior |
|---|---|---|
|
|
Returns the in-process singleton built-in tool table. |
|
|
Merges built-in tools and user tools. |
|
|
Converts to OpenAI-style function tool schemas. |
When a user tool name conflicts with a built-in tool name, merge_tools_for_loop(...) raises ToolNameConflictError.
MCP stdio adapter#
The MCP adapter discovers stdio server tools and exposes each one as a normal
FlowToolCall for the OpenRath session loop.#
API |
Returns |
Behavior |
|---|---|---|
|
client |
Synchronous wrapper around a stdio MCP server. |
|
list |
Opens a subprocess, initializes MCP, and returns raw tool definitions. |
|
raw result |
Opens a subprocess and calls one MCP tool. |
|
|
Wraps one MCP tool as a model-visible OpenRath tool. |
|
tuple |
Discovers all tools from a stdio server. |
|
tuple |
Reads one MCP server entry from |
The adapter currently supports stdio transport only. Each list/call opens a fresh subprocess on a shared dedicated event loop, so tool lifecycle is simple and there is no explicit close step.
Backend tool factories#
Function |
Returns |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Autodoc#
- class rath.flow.tool.FlowToolCall[source]#
User- or system-defined tool for the session loop (distinct from
BackendTool).Concurrency contract (used by the async session loop):
parallel_safe: class attribute.Truemeans the runtime mayawaitthis tool concurrently with otherparallel_safetools sharing a differentresource_key().Falsemeans the runtime must run this tool serially with respect to every other tool in the same round. Built-in exec/code tools default toFalse; filesystem reads and writes default toTrue; user tools default toFalseand must opt in explicitly.resource_key(): keys the runtime uses to serialize tools that touch the same resource. Same key → serial; different key → parallel. Default returns("global",)for non-parallel-safe tools so they pile up on one queue;("safe", name)for parallel-safe tools so they fan out freely.
- resource_key(arguments: Mapping[str, Any]) tuple[str, ...][source]#
Return the resource-key the async runtime serializes on.
Override for fs/exec tools to expose a meaningful key (path, sandbox handle, …). Default partitions tools into one global serial lane for non-parallel-safe tools and a per-name lane for parallel-safe tools.
- class rath.flow.tool.FlowToolCommandRun[source]#
Built-in LLM tool: run one shell command in the active sandbox.
- resource_key(arguments: Mapping[str, Any]) tuple[str, ...][source]#
Return the resource-key the async runtime serializes on.
Override for fs/exec tools to expose a meaningful key (path, sandbox handle, …). Default partitions tools into one global serial lane for non-parallel-safe tools and a per-name lane for parallel-safe tools.
- class rath.flow.tool.FlowToolFilesWrite[source]#
Built-in LLM tool: write UTF-8 text into the sandbox workspace.
- resource_key(arguments: Mapping[str, Any]) tuple[str, ...][source]#
Return the resource-key the async runtime serializes on.
Override for fs/exec tools to expose a meaningful key (path, sandbox handle, …). Default partitions tools into one global serial lane for non-parallel-safe tools and a per-name lane for parallel-safe tools.
- rath.flow.tool.global_system_tools() Mapping[str, FlowToolCall][source]#
Process-wide built-in tools (singleton instances per name, immutable view).
Returns a
types.MappingProxyTypeover the internal registry so callers cannot accidentally mutate the global state via the returned object. Callers that need a mutable working copy can still dodict(global_system_tools()); that explicit copy is local and does not touch the underlying registry.
- rath.flow.tool.merge_tools_for_loop(user_tools: list[FlowToolCall] | None) dict[str, FlowToolCall][source]#
Merge user tools with
global_system_tools().Built-in names cannot be shadowed; duplicates raise
ToolNameConflictError.
- rath.flow.tool.tools_dict_to_schemas(table: Mapping[str, FlowToolCall]) tuple[RathLLMFunctionTool, ...][source]#
Convert a name-to-tool map into sorted OpenAI-style function specs.
- rath.flow.tool.flow_tool_command_run(session: Session, cmd: str | Sequence[str], *, env: Mapping[str, str] | None = None, cwd: str | None = None, stdin: bytes | None = None, timeout: float | None = None) Any[source]#
- rath.flow.tool.flow_tool_files_read(session: Session, path: str, *, encoding: str | None = 'utf-8') Any[source]#
- rath.flow.tool.flow_tool_files_write(session: Session, path: str, data: bytes | str, *, mode: int = 420) Any[source]#
- rath.flow.tool.flow_tool_code_run(session: Session, code: str, *, language: str = 'python', timeout: float | None = None) Any[source]#
- exception rath.flow.tool.ToolNameConflictError[source]#
Raised when a user tool name collides with a built-in system tool.
MCP adapter APIs are documented manually above because importing the third-party
mcp package during a docs build can depend on the installed Pydantic minor
version. Runtime users should import them from rath.flow.tool.mcp_adapter.