openai-resptools
Lightweight tool-calling runner for the OpenAI Responses API.
What it is
openai-resptools is a small Python helper library that:
- Registers Python callables as OpenAI function tools
- Generates OpenAI-compatible tool schemas from Python signatures
- Runs the Responses API tool-calling loop until the model returns final text
Features
- Simple
ToolRegistrywith a@registry.tool()decorator - Optional “registry as a class” pattern (public methods auto-registered)
ToolRunnerthat round-trips model output items back into input- Configurable
max_iters,max_retry,parallel_tool_calls, andon_eventcallback
Install
pip install openai-resptools
Quickstart
Set your API key:
export OPENAI_API_KEY="..."
Then run a tool-calling loop:
import os
from typing import Dict
from openai import OpenAI
from openai_resptools import ToolRegistry, ToolRunner
store: Dict[str, str] = {}
registry = ToolRegistry()
@registry.tool()
def write(key: str, text: str) -> dict:
"""Save text under a key and return a small status payload."""
store[key] = text
return {"ok": True, "key": key, "length": len(text)}
@registry.tool()
def read(key: str) -> dict:
"""Read text by key. Returns null text if missing."""
return {"key": key, "text": store.get(key)}
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
model = os.getenv("OPENAI_MODEL", "gpt-4o-mini")
runner = ToolRunner(
client,
model=model,
registry=registry,
max_iters=6,
parallel_tool_calls=False,
)
prompt = (
"Do the following steps using tools:\n"
"1) Call write to save the text 'Hello from tools!' under key 'greeting'.\n"
"2) Call read for key 'greeting'.\n"
"3) Reply with ONLY the value of the text you read.\n"
)
result = runner.run(prompt)
print(result.text)
Patterns
Registry as a class
Subclass ToolRegistry and expose public methods as tools:
from openai_resptools import ToolRegistry
class MyServiceTools(ToolRegistry):
def __init__(self, db_conn: str) -> None:
super().__init__()
self.db_conn = db_conn
def get_user_status(self, user_id: int) -> str:
return f"User {user_id} is active (DB: {self.db_conn})"
service = MyServiceTools(db_conn="postgres://localhost:5432")
print(service.names())
Manual dispatch (no runner)
You can generate tool schemas and call tools yourself:
import json
from openai_resptools import ToolRegistry
registry = ToolRegistry()
@registry.tool()
def calculator(a: int, b: int, op: str) -> int:
if op == "+":
return a + b
if op == "-":
return a - b
raise ValueError(f"Unsupported operation: {op!r}")
tools_payload = registry.as_openai_tools()
mock_call = {"name": "calculator", "arguments": '{"a": 10, "b": 5, "op": "+"}'}
args = json.loads(mock_call["arguments"])
output = registry.get(mock_call["name"]).call(args)
print(output)
Development
pip install -e ".[dev]"
pytest
ruff check .
License
Apache 2.0 License. See LICENSE.
Release files for openai-resptools 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openai_resptools-0.1.0.tar.gz | 581.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openai_resptools-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 597.5 kB
Release files / openai_resptools-0.1.0.tar.gz
| Download URL | openai_resptools-0.1.0.tar.gz |
|---|---|
| Size | 581.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa26b20543fdded7907ff58e27f94f63d21a591275ce56ae950da4548c6b1b7c
|
|
BLAKE2b-256 checksum How to use checksums |
31ee7f4a44af2dff1f1b3b3169a13246f0e2b6064761da8eacb991f92efb2e27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.14
|
Release files / openai_resptools-0.1.0-py3-none-any.whl
| Download URL | openai_resptools-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc2ae7e22b0d6cc01a9ce652562cdf9390e2c7423cff3ebec05b81a671004979
|
|
BLAKE2b-256 checksum How to use checksums |
809c184a24d59f1172f2100a414a4508b904c229ff42629309ac25877ed86e06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.14
|