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"]("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.1.tar.gz (13.1 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.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toolregistry-0.3.1.tar.gz
  • Upload date:
  • Size: 13.1 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.1.tar.gz
Algorithm Hash digest
SHA256 f194f06ac52ba5c9abcffd2c65ad3affa4f48909e94f328919c2a683c27e5a00
MD5 c46e203c62fc53462c959941b2b362ac
BLAKE2b-256 ad53f69ae28f1cfc740e86fb0eb0e33a13b9cdfbed2433ea8acdbe86943036b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toolregistry-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 14.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6537577193cdc34733f505498e687d3a8565065f462405148846a5505e3c825
MD5 8f3559a2ee209329d4c8d54ed7f6dcea
BLAKE2b-256 d86ee774c3590b9c4da75d1e7d3cfeeea9262c94d542a02e73bb5966d39eb7e7

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