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 (requires Python >= 3.8):

pip install toolregistry

With MCP extension (requires Python >= 3.10):

pip install "toolregistry[mcp]"

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"].__acall__("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.3.0.tar.gz (11.0 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.3.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for toolregistry-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c868110461e17514c69edd82d427dc69823c1f2f163bad9c7b78bcbf2327e6fa
MD5 4e51401aa5c1c5d55e5ae8f587b66df8
BLAKE2b-256 9733619b9b9e6e03ec864d30ea5ee148d463a9da79b09ceae509ac0413dee594

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toolregistry-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0238664cf6623116d7562aeba1bfdb5b3bd41062222fb192a627eff4cc8a8e90
MD5 8e7b59a8373071cab9975dd1db30e9fc
BLAKE2b-256 12db9084cedb28efde7a64160e466b56a4c02ff12f000c99b4ff1dc434102c7d

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