Skip to main content

toolbridge

toolbridge is a developer-facing Python library for defining tools once with type-annotated Python functions and Pydantic v2 validation, then translating and running those tools across OpenAI, Anthropic, or Gemini. It gives agent loops a small canonical tool model, strict provider schemas, concurrent tool execution, streaming argument reassembly, structured output retries, and explicit refusal handling without bringing in a larger orchestration framework.

Installation

pip install toolbridge

Provider clients are optional:

pip install "toolbridge[openai]"
pip install "toolbridge[anthropic]"
pip install "toolbridge[gemini]"

Minimal Example

from toolbridge import Agent, tool

@tool("Use when adding two numbers. Do not use for non-arithmetic tasks.")
def add(left: int, right: int) -> int:
    return left + right

provider = YourProvider()
agent = Agent(provider=provider, tools=[add])
run = agent.run("What is 2 + 3?")
print(run.output)

Provider Shape Comparison

Provider Tool wire shape
OpenAI {type:"function", function:{name, description, parameters, strict:true}}
Anthropic {name, description, input_schema}
Gemini {functionDeclarations:[{name, description, parameters}]}

Parallel Calls

When a model response contains multiple tool calls, toolbridge fans them out with ThreadPoolExecutor, then correlates results by tool call id before the next model turn.

model response
  |-- call id=a -> tool A --\
  |-- call id=b -> tool B ----> {a: result_a, b: result_b, c: result_c}
  |-- call id=c -> tool C --/
                         next model turn

Refusal Handling

Structured output accepts a Pydantic BaseModel. Parse errors and schema violations retry up to three times with the typed error injected for the next attempt. Refusals return immediately as Refusal.

from pydantic import BaseModel
from toolbridge import Agent, Refusal

class Answer(BaseModel):
    value: int

agent = Agent(provider=provider, tools=[], output_schema=Answer)
result = agent.run("Return a number")

if isinstance(result.output, Refusal):
    print(result.output.reason)
else:
    print(result.output.value)

Provider API Key Demo

The repository includes a simple smoke-test app at examples/provider_demo.py. It defines two tools once with @tool, translates them to the selected provider's tool schema, asks the model to call tools, executes returned calls in parallel, and prints correlated results by tool call id.

Install the package and provider extras:

python3 -m pip install -e ".[openai]"
python3 -m pip install -e ".[anthropic]"
python3 -m pip install -e ".[gemini]"

Run with OpenAI:

export OPENAI_API_KEY="sk-..."
python3 examples/provider_demo.py --provider openai

Run with Anthropic:

export ANTHROPIC_API_KEY="sk-ant-..."
python3 examples/provider_demo.py --provider anthropic

Run with Gemini:

export GEMINI_API_KEY="..."
python3 examples/provider_demo.py --provider gemini

Optional model overrides:

export OPENAI_MODEL="gpt-4o-mini"
export ANTHROPIC_MODEL="claude-3-5-haiku-latest"
export GEMINI_MODEL="gemini-1.5-flash"

Deploying to PyPI

  1. Create PyPI and TestPyPI API tokens.
  2. Install release tools:
python3 -m pip install --upgrade build twine
  1. Build the package:
python3 -m build
  1. Check the artifacts:
python3 -m twine check dist/*
  1. Rehearse on TestPyPI:
python3 -m twine upload --repository testpypi dist/*
  1. Install from TestPyPI in a clean environment:
python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ toolbridge
  1. Publish to PyPI:
python3 -m twine upload dist/*

Use __token__ as the username when twine prompts for credentials, and paste the API token as the password. Before publishing, make sure pyproject.toml has the intended version and that dist/ only contains artifacts for that version.

Metadata

Release files for toolbroidge 0.1.0

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

Source distribution (sdist)

Source distribution for toolbroidge 0.1.0
File Size Uploaded Provenance
toolbroidge-0.1.0.tar.gz 9.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for toolbroidge 0.1.0
File Interpreter ABI Platform
toolbroidge-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / toolbroidge-0.1.0.tar.gz

Download URL toolbroidge-0.1.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8529b6fdace9cb63825faef8ecb30528758e8faef1ce3d40a38e8cc887f443f9
BLAKE2b-256 checksum
How to use checksums
5fd1359af39fdfcb08dcfd7e53c3413c59b149e2db3d1c0f294c79b90752bf10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / toolbroidge-0.1.0-py3-none-any.whl

Download URL toolbroidge-0.1.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9e4d2e881179c48586c349ff70cff5e346e10d5ede27b57945214ed74c9f472
BLAKE2b-256 checksum
How to use checksums
41ed33d2e042567f883c2227c95dec6a805f71112c35c4606faa6144de43d56c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for toolbroidge 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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