Skip to main content

fabricatio-tool

MIT License Python Versions PyPI Version PyPI Downloads PyPI Downloads Bindings: PyO3 Build Tool: uv + maturin

Tool execution layer for Fabricatio — wraps Python callables as discoverable tools, lets LLMs generate orchestration code, and executes it with safety validation.


Installation

pip install fabricatio[tool]
# or
uv pip install fabricatio[tool]

For all Fabricatio packages:

pip install fabricatio[full]

Overview

fabricatio-tool enables Fabricatio agents to use arbitrary Python functions as tools. Tools are grouped into toolboxes, discovered by an LLM-driven selection process, composed into execution code (also LLM-generated), and run inside a ToolExecutor with import/call safety checks. Results are collected in a ResultCollector for downstream use.

The package also includes built-in filesystem tools and MCP (Model Context Protocol) client and server integration.

Core concepts

Concept Description
Tool A named, described callable with auto-extracted signature and briefing
ToolBox A named collection of related Tool instances
ToolExecutor Runs LLM-generated code that invokes tools; validates imports and calls
ResultCollector Key-value container for tool execution results and errors
Handle / HandleTask Mixin classes that wire tool discovery, code generation, and execution

Key classes and functions

fabricatio_tool.models.tool

  • Tool(source, name, description) — wraps a callable with metadata. invoke(*args, **kwargs) calls through. .signature and .briefing are auto-generated.
  • ToolBox(name, description) — collects tools. add_tool(func) appends a tool; collect_tool() works as a decorator. get(name) looks up a tool by name. .briefing produces an LLM-friendly description.

fabricatio_tool.models.collector

  • ResultCollector — submit(key, val), revoke(key), take(key) for typed retrieval, error() for retrieving execution errors.
  • ApplicationError — captures exception type, message, traceback, and the generated source for retry.

fabricatio_tool.models.executor

  • ToolExecutor(candidates, data) — execute(source) runs tool-usage code asynchronously. inject_tools(cxt), inject_data(cxt), inject_collector(cxt) prepare the execution context. from_recipe(recipe, toolboxes) constructs an executor by selecting tools by name.

fabricatio_tool.capabilities

  • Handle — draft_tool_usage_code(request, tools, data) generates Python code via LLM. handle(request, data) and handle_fine_grind(request, data) run the full pipeline; on execution failure they re-draft with the partial results, error, and failed source appended to the prompt (max_feedback_rounds, default off).
  • HandleTask — extends Handle with handle_task(task, data) for Fabricatio Task objects.

fabricatio_tool.fs

Filesystem utilities callable as tools:

Function Description
dump_text(path, text) Write text to a file
copy_file(src, dst) Copy a file
move_file(src, dst) Move/rename a file
delete_file(path) Delete a file
create_directory(path) Create a directory
delete_directory(path) Recursively delete a directory
absolute_path(path) Resolve to absolute POSIX path
gather_files(directory, ext) Glob for files by extension
safe_text_read(path) Read file as UTF-8 text
safe_json_read(path) Read and parse JSON file
treeview(path, max_depth) Render a directory tree (Rust)

fabricatio_tool.mcp

  • get_global_mcp_manager(conf) — singleton MCP manager (Rust-backed).
  • mcp_tool_to_function(client_id, tool_name) — converts an MCP tool to an async callable.
  • mcp_to_toolbox(client_id) — converts all tools from an MCP client into a ToolBox.

fabricatio_tool.mcp_server

Exposes native Python functions as an MCP server (Rust-backed; stdio and streamable HTTP transports):

  • get_global_mcp_server() — singleton MCPServer named "fabricatio", versioned with the installed fabricatio-tool.
  • add_tool(func, *, name=None, description=None) — registers a sync or async callable; its JSON input schema is derived from the signature.
  • serve(host="127.0.0.1", port=9847) — starts the HTTP transport and returns the server URL.
  • serve_stdio() — serves over stdin/stdout for clients that spawn the process.
  • ToolBox.to_mcp_server() — exposes an entire toolbox's tools over MCP.

CLI (no console script — use python -m):

python -m fabricatio_tool.mcp_server --stdio mcp_fixture           # stdio transport
python -m fabricatio_tool.mcp_server --http 127.0.0.1 9847 pkg.module[:attr]

Targets are import paths: a bare module defaults to its toolbox attribute, a ToolBox is exported via to_mcp_server(), and any callable is registered directly. Logs go to stderr (stdout belongs to the stdio protocol).

fabricatio_tool.toolboxes

  • fs_toolbox — pre-built ToolBox containing all filesystem tools listed above.

Configuration

All options below are read through the fabricatio configuration chain (see the Configuration Guide at ../../docs/source/configuration.rst). Set them under the [ext.tool] table in fabricatio.toml, equivalently under [tool.fabricatio.ext.tool] in pyproject.toml, or via FABRICATIO_EXT__TOOL__<FIELD_UPPER> environment variables.

# fabricatio.toml
[ext.tool]
draft_tool_usage_code_template = "built-in/draft_tool_usage_code"
logging_on_ops = true
error_key = "__error__"
max_feedback_rounds = 0
feedback_max_chars = 6000
Option Type Default Description
draft_tool_usage_code_template str "built-in/draft_tool_usage_code" The name of the draft tool usage code template which will be used to draft tool usage code.
check_modules CheckConfigModel (see config.py) Modules that are forbidden/allowed to be imported.
check_imports CheckConfigModel (see config.py) Imports that are forbidden/allowed to be used.
check_calls CheckConfigModel (see config.py) Calls that are forbidden/allowed to be used.
mcp_servers Dict[str, ServiceConfig] {} MCP servers that are allowed to be used.
logging_on_ops bool True Whether to log operations before executing them.
max_feedback_rounds int 0 Extra re-drafting rounds when tool code execution fails; results and errors are fed back to the LLM. 0 disables the loop.
feedback_max_chars int 6000 Per-item character cap when summarizing execution results/errors for LLM feedback.

CheckConfigModel fields:

  • targets: Set[str] — set of strings to check; default set()
  • mode: Literal["whitelist", "blacklist"] — check mode; default "whitelist"

ServiceConfig fields:

  • type: Literal["stdio", "sse", "stream", "worker"] — transport protocol; default "stdio"
  • command: Optional[str] — execution command for stdio-type services
  • url: Optional[str] — endpoint URL for SSE/stream/worker-type services
  • args: List[str] — command-line arguments for stdio services
  • env: Dict[str, JsonValue] — environment variables for the service process

Access at runtime: from fabricatio_tool.config import tool_config.

Usage example

from fabricatio_tool.models.tool import Tool, ToolBox
from fabricatio_tool.models.executor import ToolExecutor

# Define a tool
def add(a: int, b: int) -> int:
    """Add two integers."""
    return a + b

# Build a toolbox
box = ToolBox(name="math", description="Math operations")
box.add_tool(add, logging=True)

# Execute LLM-generated tool-usage code
executor = ToolExecutor(candidates=box.tools, data={})
source = """
async def execute(collector):
    result = await add(3, 4)
    collector.submit('sum', result)
"""
await executor.execute(source)
print(executor.collector.take('sum'))  # 7

With filesystem toolbox

from fabricatio_tool.toolboxes import fs_toolbox

# Use the built-in filesystem tools
executor = ToolExecutor(candidates=fs_toolbox.tools, data={})
source = """
async def execute(collector):
    import pathlib
    await dump_text(pathlib.Path('example.txt'), 'Hello, Fabricatio!')
    content = await safe_text_read(pathlib.Path('example.txt'))
    collector.submit('content', content)
"""
await executor.execute(source)
print(executor.collector.take('content'))  # Hello, Fabricatio!

Using capability mixins

from fabricatio_tool.capabilities.handle import Handle

class MyAgent(Handle):
    ...

agent = MyAgent()
result = await agent.handle(
    "Find all Python files and count their total lines",
    data={"dir": "src/"},
    model="default",
)
if result and not result.error():
    print(result.take("output"))

Safety

ToolExecutor validates generated code against configurable whitelists or blacklists for modules, imports, and function calls. By default, only safe builtins (str, int, float, bool, dict, set, list, pathlib.Path, print, len) and math are permitted.

Dependencies

  • fabricatio-core — core interfaces and utilities
  • pydantic>=2.11.7

License

MIT — see LICENSE

Metadata

Release files for fabricatio-tool 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for fabricatio-tool 0.9.0
File
fabricatio_tool-0.9.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
fabricatio_tool-0.9.0-cp314-cp314-manylinux_2_39_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.39+ x86-64 Details
fabricatio_tool-0.9.0-cp314-cp314-manylinux_2_39_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.39+ ARM64 Details
fabricatio_tool-0.9.0-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
fabricatio_tool-0.9.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
fabricatio_tool-0.9.0-cp313-cp313-manylinux_2_39_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.39+ x86-64 Details
fabricatio_tool-0.9.0-cp313-cp313-manylinux_2_39_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.39+ ARM64 Details
fabricatio_tool-0.9.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
fabricatio_tool-0.9.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
fabricatio_tool-0.9.0-cp312-cp312-manylinux_2_39_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.39+ x86-64 Details
fabricatio_tool-0.9.0-cp312-cp312-manylinux_2_39_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.39+ ARM64 Details
fabricatio_tool-0.9.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Total release size: 121.9 MB

Release files / fabricatio_tool-0.9.0-cp314-cp314-win_amd64.whl

Download URL fabricatio_tool-0.9.0-cp314-cp314-win_amd64.whl
Size 9.9 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
5a37eed786762b348b4647a9bc1100382525daa70eac0a441daa6471219245ca
BLAKE2b-256 checksum
How to use checksums
15bc41b1c24d0a4d4c291d6c0f50c904155b5df7b04b705880a80284918b66cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp314-cp314-manylinux_2_39_x86_64.whl

Download URL fabricatio_tool-0.9.0-cp314-cp314-manylinux_2_39_x86_64.whl
Size 11.1 MB
Tags CPython 3.14 Linux glibc 2.39+ x86-64
SHA-256 checksum
How to use checksums
113fb01ba43aeacda42003d86583738746d9918fca775fc2851836917e1b0278
BLAKE2b-256 checksum
How to use checksums
2280ca9ec740a344452a6a17358565636f6166775ddea47cf557a9d521379367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp314-cp314-manylinux_2_39_aarch64.whl

Download URL fabricatio_tool-0.9.0-cp314-cp314-manylinux_2_39_aarch64.whl
Size 9.8 MB
Tags CPython 3.14 Linux glibc 2.39+ ARM64
SHA-256 checksum
How to use checksums
5cdc62247102b0db1a8e674c2b18135b24810294b1fdf4db5f56c21fe829dc68
BLAKE2b-256 checksum
How to use checksums
45e21b780bc2252faf81d18130f8ba2e1223971e8b4f8d5774aa81f1da642180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL fabricatio_tool-0.9.0-cp314-cp314-macosx_11_0_arm64.whl
Size 9.9 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
462d7642a59790c2697bf1289c8a1d0d67290d7b0505ff5e25e23d08ada02b3e
BLAKE2b-256 checksum
How to use checksums
f00cad96a0312c95fb8a809068ffe0951858d963b2cf61f8f2f07adc3e81c74e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp313-cp313-win_amd64.whl

Download URL fabricatio_tool-0.9.0-cp313-cp313-win_amd64.whl
Size 9.9 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
f6524795b559c89e94685df36dbf20a7fc04c9638611bbb02b932834bbee8276
BLAKE2b-256 checksum
How to use checksums
3f92012f22e83c8b02bb7f676dc9d4c53a4d777f3440452de29fdf19ba534d3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp313-cp313-manylinux_2_39_x86_64.whl

Download URL fabricatio_tool-0.9.0-cp313-cp313-manylinux_2_39_x86_64.whl
Size 11.1 MB
Tags CPython 3.13 Linux glibc 2.39+ x86-64
SHA-256 checksum
How to use checksums
3295bdae12a1cb8b79c792658435d0bd1fbddfd5b82e5e9021f4dca4d29f851e
BLAKE2b-256 checksum
How to use checksums
97fac0800088885fde17f7726413aa1d4a9e48ecb50786f2c721a9eff2910baf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp313-cp313-manylinux_2_39_aarch64.whl

Download URL fabricatio_tool-0.9.0-cp313-cp313-manylinux_2_39_aarch64.whl
Size 9.8 MB
Tags CPython 3.13 Linux glibc 2.39+ ARM64
SHA-256 checksum
How to use checksums
6235edf7faa8351a09409393482f1df4cbb733d89a583f4980df75aecec906f9
BLAKE2b-256 checksum
How to use checksums
4f6028108c81cff1017eaf32f6b73679139d50cb9df497c5557369ca1806ff57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL fabricatio_tool-0.9.0-cp313-cp313-macosx_11_0_arm64.whl
Size 9.9 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b51d0bace6676b87c9c5fa2d3a7069b4d1ee2dc97b10a7d847dbde76da691e57
BLAKE2b-256 checksum
How to use checksums
bc4a0d0882e9c49d86a33a59de4594796ae33782ffb3efce49f0b87841f66e07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp312-cp312-win_amd64.whl

Download URL fabricatio_tool-0.9.0-cp312-cp312-win_amd64.whl
Size 9.9 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
6ddcb915a5ba930e629bbc6c0d2d4622df616dcb5b399a27b246add0278751db
BLAKE2b-256 checksum
How to use checksums
0c59e664f28cb808e8f8637656ce7114adcc5cda2c05212f598f5ec18da88bf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp312-cp312-manylinux_2_39_x86_64.whl

Download URL fabricatio_tool-0.9.0-cp312-cp312-manylinux_2_39_x86_64.whl
Size 11.1 MB
Tags CPython 3.12 Linux glibc 2.39+ x86-64
SHA-256 checksum
How to use checksums
59c23a38846192a4a6cf5793879eab2c819fbbfbf2dc3b083d9dddd01045105f
BLAKE2b-256 checksum
How to use checksums
f907ba70a9d291205442c971206dbd1ebbbcc36d0443bbd5c5ea53fb3e858b3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp312-cp312-manylinux_2_39_aarch64.whl

Download URL fabricatio_tool-0.9.0-cp312-cp312-manylinux_2_39_aarch64.whl
Size 9.8 MB
Tags CPython 3.12 Linux glibc 2.39+ ARM64
SHA-256 checksum
How to use checksums
19c57fc0bc8562c76a6240d76d009019ea5447dbe13ad4e081bc3588c1d62636
BLAKE2b-256 checksum
How to use checksums
a906c176eb04e8335d60a27c274701088df832b8798439081bd1d2345a76abb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fabricatio_tool-0.9.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL fabricatio_tool-0.9.0-cp312-cp312-macosx_11_0_arm64.whl
Size 9.9 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e9a9b5003e016d0ffea5714e33b39ed8cfceb7f06a8920b1c52533bdcdc3d8b8
BLAKE2b-256 checksum
How to use checksums
77e25944b9aeeb962c4628eed33cca66bf99d710fadfb9fc9a44126b846cf4a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page