Skip to main content

A library for managing tool registries

Project description

ToolRegistry

中文版

A Python library for managing and executing tools in a structured way.

Features

  • Tool registration and management
  • JSON Schema generation for tool parameters
  • Tool execution and result handling
  • Support for both synchronous and asynchronous tools

Installation

Basic Installation

Install the core package (requires Python >= 3.8):

pip install toolregistry

Installing with Extra Support Modules

Extra modules can be installed by specifying extras in brackets. For example, to install specific extra supports:

pip install toolregistry[mcp,openapi]

Below is a table summarizing available extra modules:

Extra Module Python Requirement Example Command
mcp Python >= 3.10 pip install toolregistry[mcp]
openapi Python >= 3.8 pip install toolregistry[openapi]

Examples

OpenAI Implementation

The openai_tool_usage_example.py shows how to integrate ToolRegistry with OpenAI's API.

Cicada Implementation

The cicada_tool_usage_example.py demonstrates how to use ToolRegistry with the Cicada MultiModalModel.

OpenAI Integration

The ToolRegistry also integrates seamlessly with OpenAI's API. Here are some common usage patterns:

Getting Tools JSON for OpenAI

tools_json = registry.get_tools_json()
# Use this with OpenAI's API to provide available tools

Executing Tool Calls

# Assuming tool_calls is received from OpenAI's API
tool_responses = registry.execute_tool_calls(tool_calls)

Recovering Assistant Messages

# After executing tool calls
messages = registry.recover_tool_call_assistant_message(tool_calls, tool_responses)
# Use these messages to continue the conversation

Manual Tool Execution

# Get a callable function
add_fn = registry.get_callable("add")
result = add_fn(a=1, b=2)  # Output: 3

MCP Integration

The ToolRegistry provides first-class support for MCP (Model Context Protocol) tools:

Basic Usage

from toolregistry import ToolRegistry

# Create registry and register MCP tools
registry = ToolRegistry()
registry.register_mcp_tools("http://localhost:8000/mcp/sse")

# Get all tools JSON including MCP tools
tools_json = registry.get_tools_json()

Calling MCP Tools

# Sync call using registry
result = registry["echo_tool"]("test sync message")

# Sync call using tool directly
echo_tool = registry.get_callable("echo_tool")
result = echo_tool.run({"message": "test sync message"})

# Async call using registry (requires await and asyncio.run)
result = await registry["echo_tool"]("test message")

# Async call using tool directly (requires await and asyncio.run)
result = await echo_tool.arun({"message": "test sync message"})

Documentation

Full documentation is available at https://toolregistry.lab.oaklight.cn

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toolregistry-0.4.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

toolregistry-0.4.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file toolregistry-0.4.0.tar.gz.

File metadata

  • Download URL: toolregistry-0.4.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for toolregistry-0.4.0.tar.gz
Algorithm Hash digest
SHA256 93e10a5335366ece9d7f29d9737a4528655106be8478d8c2ff28e77c716d0327
MD5 a4629fb69c92210999eb0182e588a3b4
BLAKE2b-256 a944228d783968ce0de3786c08a4e5509f252e063b054ad983b541b068b7650f

See more details on using hashes here.

File details

Details for the file toolregistry-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: toolregistry-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for toolregistry-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 453b3dde775189cd107e9f72fb9092179c87568642b368519f20fbcc8962401c
MD5 4e6599aecefacbfb6753cae3b290ee0f
BLAKE2b-256 c6ac0bcfc8bc62e35142712fa9d1a7f8162cd4a558ff65d3a6fb70e977e0ed13

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page