A lightweight tool registry for function metadata management
Project description
Agent Tooling
A lightweight Python package for registering, discovering, and managing function metadata for OpenAI agents. Includes support for tagging, fallback tools, structured schema validation, and streaming.
Installation
pip install agent_tooling
Highlights
- ✅ Register tools with structured metadata and tags
- ✅ Auto-discover tools across packages with
discover_tools() - ✅ Generate OpenAI-compatible tool schemas
- ✅ Call tools with OpenAI's API using
OpenAITooling - ✅ Supports fallback tools and graceful degradation
- ✅ Validates function arguments against schema
- ✅ Smart message passing based on function signature
- ✅ Stream results or return all at once
- ✅ Expose registered agents and their code metadata
- ✅ Register tools with structured metadata and tags
- ✅ List all unique tags with
get_tags()
Quick Start
from agent_tooling import tool, get_tool_function, get_tool_schemas
@tool(tags=["math"])
def add(a: int, b: int) -> int:
"""Adds two numbers."""
return a + b
schemas = get_tool_schemas()
func_dict = get_tool_function("add")
print(func_dict("a": 5, "b": 3)) # 8
Tag Discovery
You can list all unique tags associated with registered tools:
from agent_tooling import get_tags
tags = get_tags()
print(tags) # ['finance', 'math', 'weather']
---
## Example with OpenAITooling
```python
from agent_tooling import tool, OpenAITooling
import os
@tool(tags=["weather"])
def get_weather(location: str, unit: str = "celsius") -> str:
"""Returns mock weather for a location."""
return f"The weather in {location} is sunny and 25°{unit[0].upper()}"
@tool(tags=["finance"])
def calculate_mortgage(principal: float, interest_rate: float, years: int) -> str:
"""Returns estimated monthly mortgage payment."""
p, r, n = principal, interest_rate / 12, years * 12
payment = (p * r * (1 + r) ** n) / ((1 + r) ** n - 1)
return f"Monthly payment: ${payment:.2f}"
openai = OpenAITooling(api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o")
messages = [{"role": "user", "content": "What's the weather in Paris and mortgage for $300,000 at 4.5% for 30 years?"}]
messages = openai.call_tools(messages, tags=["weather", "finance"])
for message in messages:
if message["role"] == "function":
print(f"{message['name']} → {message['content']}")
Fallback Tool Example
result_stream = openai.call_tools(
messages=messages,
api_key=os.getenv("OPENAI_API_KEY"),
model="gpt-4.1",
tool_choice="auto",
tags=["triage"],
fallback_tool="web_search",
)
for response in result_stream:
print(response["content"])
If the tools matching the provided tags cannot handle the message, the fallback tool will be automatically invoked.
Example with OllamaTooling
Agent Tooling now supports the Ollama client! Use your local Ollama models in the same way as with the OpenAI API, including tool routing and fallback logic.
from agent_tooling import tool, OllamaTooling
@tool(tags=["agent", "triage", "ollama", "openai"])
def summarize(text: str) -> str:
"""Short summary of provided text."""
return text[:50] + "..." if len(text) > 50 else text
ollama_tooling_client = OllamaTooling(
model="granite3.3:2b" # Or another Ollama-hosted model
)
messages = [
{"role": "user", "content": "Summarize this news article: <article text>"},
]
result_stream = ollama_tooling_client.call_tools(
messages=messages,
model="granite3.3:2b",
tool_choice="auto",
tags=["agent", "triage", "ollama"],
fallback_tool="web_search",
)
for response in result_stream:
print(response["content"])
This enables full function/tool chaining with models served by your local Ollama instance, and automatic fallback to other tools (like a web search) if required.
API Reference
@tool(tags=None)
Registers a function with introspected JSON schema + optional tags.
get_tool_schemas(tags=None) -> List[Dict[str, Any]]
Returns OpenAI-compatible tool metadata (filtered by tag if provided).
get_tags() -> List[str]
Returns a sorted list of all unique tags used in registered tools.
get_tool_function(name) -> Optional[Callable]
Returns function reference by name.
get_tool(name) -> Tuple[List[Dict[str, Any]], Dict[str, Callable]]
Returns both the tool schema and function reference. Useful for fallback execution.
get_agents() -> List[Agent]
Returns metadata + source code for each registered tool.
discover_tools(folders: list[str])
Recursively imports all modules in specified package folders, auto-registering tools.
clear()
Clears all registered tools and metadata.
OpenAITooling
A helper class for integrating OpenAI tool-calling flows.
OpenAITooling(api_key=None, model=None, tool_choice="auto")
Methods:
-
call_tools(messages, api_key=None, model=None, tool_choice="auto", tags=None, fallback_tool=None)- Yields generator of response messages
- If no tool matched, attempts a fallback if provided
- Validates arguments and handles conditional message passing
OllamaTooling
OllamaTooling(model=None, tool_choice="auto")
Methods:
-
call_tools(messages, model=None, tool_choice="auto", tags=None, fallback_tool=None)- Yields generator of response messages
- If no tool matched, attempts a fallback if provided
- Validates arguments and handles conditional message passing
Manual Integration with OpenAI
from openai import OpenAI
from agent_tooling import tool, get_tool_schemas, get_tool_function
import json
@tool(tags=["weather"])
def get_weather(location: str) -> str:
return f"Weather in {location}: 25°C"
tools, _ = get_tool("get_weather")
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
tools=tools,
tool_choice="auto",
)
for call in response.choices[0].message.tool_calls:
name = call.function.name
args = json.loads(call.function.arguments)
_, funcs = get_tool(name)
func = funcs[name]
print(func(**args))
License
MIT License — see LICENSE for details.
Repo
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 agent_tooling-0.4.6.tar.gz.
File metadata
- Download URL: agent_tooling-0.4.6.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30b59359f14370900b6f2ac56a3c6c9c68eb2c68ccc8c39efe3416c36df0f664
|
|
| MD5 |
1654924cfb9e090f07149ec345e7571f
|
|
| BLAKE2b-256 |
15a9a464859b08f81feea93f9980965eb59b6c1e72550e076e0f907a4aee781e
|
File details
Details for the file agent_tooling-0.4.6-py3-none-any.whl.
File metadata
- Download URL: agent_tooling-0.4.6-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04aa49ecdcbc3251b4fe094096dc81ae8fc0cf76bd4008a2f07ee30914ddcfa0
|
|
| MD5 |
de08ba45a33841c1e69f823019eec162
|
|
| BLAKE2b-256 |
eeb399d2b93f0fb0d0299fe7713080890877917a67cd15a42fbc1cf1fcab8827
|