Tool framework for LLM agents -- routing, execution, and builtin tools
Project description
3tears Agent Tools
Tool framework for LLM agents. Provides tool routing, execution, context management, MCP integration, and a set of builtin tools.
Part of the 3tears framework.
ToolServer baseline audit
ToolServer.handle_call stamps every dispatch with a unified AuditEvent envelope (event_type='tool.call') via threetears.agent.audit.publish_audit. The baseline emission fires in a finally block so success, failure (tool returned success=False), and error (tool raised) outcomes all produce a row. Identity axes carry from the active ToolCallScope (actor_user_id, calling_agent_id, owner_agent_id, customer_id, correlation_id); resource_namespace_id / resource_namespace_type stay None at the baseline layer since the tool resolves its target inside execute. Per-tool additive events (e.g. workspace.fs_write) still publish via publish_audit and ride alongside the baseline row under the same correlation_id. The (correlation_id, event_type) partial unique index on platform_audit.audit_events keeps them distinct. Emission is fire-and-forget: NATS publish failures log WARN and never taint the tool's response.
Tool-as-namespace emission
Tool namespace materialization is platform-owned. ToolServer.publish_registration writes the RegistrationManifest (carrying pod_id + tools + the owner_agent_id / customer_id envelope fields), and a platform-side namespace emitter subscribes to {ns}.tools.register and upserts one platform.namespaces row of type tool per tool. This is the sole writer in the platform.
Agent-spun ToolServers stamp agent_id + customer_id on the RegistrationManifest so the emitter lands rows with the right owner scope; platform-built-in pods (admin tool server, datasource tool pod) leave both None and the row lands with NULL owner columns (admitted under the widened namespaces_row_scope_customer_ck carve-out for tool type alongside system / model).
The canonical name shape is tools.<sanitized-mcp>.<sanitized-version> (per build_namespace_name); metadata carries the pre-sanitized natural-identity fields mcp_name / mcp_version / pod_id so downstream pattern matching (platform access materializer agent.yaml access.tools patterns + registry authorizer canonical-name lookup) does not need to reverse the sanitization rules. Deterministic uuid5 derived from (mcp_name, version, owner_agent_id_hex) keeps concurrent emitters race-safe via ON CONFLICT (id) DO UPDATE.
The ToolServer.register_tool / deregister_tool helpers still emit through an injected namespace_collection for callers that wire one explicitly, but in production deployments the platform-side emitter is the source of truth and the in-process emission is redundant.
Installation
pip install 3tears-agent-tools
# Optional extras for builtin tools
pip install "3tears-agent-tools[calculator]" # simpleeval
pip install "3tears-agent-tools[units]" # pint
pip install "3tears-agent-tools[fetch]" # trafilatura
pip install "3tears-agent-tools[document]" # PyMuPDF, python-docx, openpyxl
pip install "3tears-agent-tools[all]" # everything
Components
ToolRouter
Routes user messages to the appropriate tool using a lightweight LLM call. Includes recall-intent detection to avoid re-invoking tools when users ask about previous results.
from threetears.agent.tools import ToolRouter, is_recall_intent
# Quick check -- no LLM call needed
if is_recall_intent("show me what the calculator said"):
# User wants to recall, not invoke
# Full routing with LLM
router = ToolRouter(chat_model)
decision = await router.route(user_message, tool_descriptions)
# decision.tool_name, decision.reasoning
ToolExecutor
Invokes a tool-LLM: sends the user message to a secondary model configured for a specific task.
from threetears.agent.tools import ToolExecutor
executor = ToolExecutor()
result = await executor.invoke_with_tools(
chat_model=tool_model,
user_message="What is 42 * 17?",
tools=[calculator_tool],
tool_name="calculator",
)
# result.content, result.tool_calls
ToolContextManager
Tracks tool invocations and results across a conversation for recall support.
from threetears.agent.tools import ToolContextManager
ctx = ToolContextManager()
await ctx.record_invocation("calculator", "42 * 17", "714")
await ctx.get_recall_context("calculator") # Returns formatted recall string
McpClient
MCP (Model Context Protocol) integration for connecting to external tool servers.
from threetears.agent.tools import McpClient
async with McpClient(server_config) as client:
tools = await client.list_tools()
result = await client.invoke_tool("tool_name", {"param": "value"})
Builtin Tools
Register all builtin tools at once:
from threetears.agent.tools import register_builtins, ToolRegistry
registry = ToolRegistry()
register_builtins(registry)
# Registers: calculator, unit_converter, dice_roller, date_time,
# random_number, web_fetch, text_transform, parse_document
Todo Tools
Todo list management behind a storage protocol:
from threetears.agent.tools import TodoStorage, load_todo_tools_from_storage
class MyTodoStorage(TodoStorage):
async def add(self, conv_id, user_id, title, list_name, msg_id) -> dict: ...
async def list_all(self, conv_id) -> list[dict]: ...
# ... other methods
tools = load_todo_tools_from_storage(my_storage, snapshot_callback=on_snapshot)
Protocols
For media-related capabilities, implement these protocols:
from threetears.agent.tools import (
ImageGenerationBackend,
MediaStorage,
VisionProvider,
TranscriptionProvider,
)
Document Parsing
Parse PDF, DOCX, XLSX, and plain text with optional OCR:
from threetears.agent.tools import parse_document, OcrConfig
result = await parse_document(
file_bytes=data,
filename="report.pdf",
ocr_config=OcrConfig(enabled=True),
)
# result.sections -- list of DocumentSection with title, content, page numbers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file 3tears_agent_tools-0.18.0.tar.gz.
File metadata
- Download URL: 3tears_agent_tools-0.18.0.tar.gz
- Upload date:
- Size: 308.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63ff3328b1a17deba5890f96be88b4c1b3c777ee1e918eacf56ca962db88eb59
|
|
| MD5 |
0796032265383517ad08a4f3e9ee983a
|
|
| BLAKE2b-256 |
e95d408829a78371dcec7648a387ac476ea3b8528d6db3f788b7d8d515656221
|
Provenance
The following attestation bundles were made for 3tears_agent_tools-0.18.0.tar.gz:
Publisher:
release.yml on pacepace/3tears
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
3tears_agent_tools-0.18.0.tar.gz -
Subject digest:
63ff3328b1a17deba5890f96be88b4c1b3c777ee1e918eacf56ca962db88eb59 - Sigstore transparency entry: 2239366702
- Sigstore integration time:
-
Permalink:
pacepace/3tears@eae3abb5147a258c68cca867df18e536c9fa43a2 -
Branch / Tag:
refs/tags/v0.18.0 - Owner: https://github.com/pacepace
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@eae3abb5147a258c68cca867df18e536c9fa43a2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file 3tears_agent_tools-0.18.0-py3-none-any.whl.
File metadata
- Download URL: 3tears_agent_tools-0.18.0-py3-none-any.whl
- Upload date:
- Size: 222.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10f4b4e5807aec6c6a5ee216b43277b8f1fcc23a1222fb979f5a6dc3b682c62f
|
|
| MD5 |
8a8b8da3dbc8142faa984456a5eaed53
|
|
| BLAKE2b-256 |
6d69e498aea7f4fd01fa1ee53e7d41c3c75d74c2ae53fdb2ecbb8fb0f71e9862
|
Provenance
The following attestation bundles were made for 3tears_agent_tools-0.18.0-py3-none-any.whl:
Publisher:
release.yml on pacepace/3tears
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
3tears_agent_tools-0.18.0-py3-none-any.whl -
Subject digest:
10f4b4e5807aec6c6a5ee216b43277b8f1fcc23a1222fb979f5a6dc3b682c62f - Sigstore transparency entry: 2239370902
- Sigstore integration time:
-
Permalink:
pacepace/3tears@eae3abb5147a258c68cca867df18e536c9fa43a2 -
Branch / Tag:
refs/tags/v0.18.0 - Owner: https://github.com/pacepace
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@eae3abb5147a258c68cca867df18e536c9fa43a2 -
Trigger Event:
push
-
Statement type: