Skip to main content

A tool routing AI package using embeddings and FAISS

Project description

Capability Tool Router

An AI-driven tool routing library that uses semantic embeddings and FAISS to choose the best tool for a user query.

Features

  • Semantic Tool Routing: Routes queries based on tool descriptions and semantic similarity
  • Tool Registry: Register and manage tools in a central registry
  • Async Embeddings: Pluggable async embedder for custom embedding providers
  • FAISS Vector Search: Uses FAISS to build an index over tool descriptions
  • Caching: Simple result caching with deterministic keys
  • Feedback Tracking: Record success/failure rates for tools

Installation

Install the package in your environment:

pip install tool-router-ai

If you are using the local repository, build and install from source:

python3 setup.py sdist bdist_wheel
pip install dist/tool_router_ai-0.1.0-py3-none-any.whl

Quick Start

import asyncio
from tool_router_ai.models import Tool
from tool_router_ai.registry import ToolRegistry
from tool_router_ai.embedder import Embedder
from tool_router_ai.router import ToolRouter

# Example embedding function that produces dummy embeddings.
# Replace this with your own async embedder, e.g. OpenAI, cohere, etc.
async def dummy_embed(texts):
    return [[0.0] * 1536 for _ in texts]

async def main():
    registry = ToolRegistry()

    registry.register(Tool(
        name="weather",
        description="Get weather information for any city.",
        input_schema={"city": "string"},
        func=lambda city: f"Weather for {city}"
    ))

    registry.register(Tool(
        name="stocks",
        description="Get stock market prices for a symbol.",
        input_schema={"symbol": "string"},
        func=lambda symbol: f"Stock price for {symbol}"
    ))

    embedder = Embedder(dummy_embed)
    router = ToolRouter(registry, embedder)

    await router.build_index()

    selected_tools = await router.route("What is the weather in San Francisco?", top_k=1)
    print(selected_tools[0].name)

asyncio.run(main())

Package Overview

tool_router_ai.models.Tool

A simple dataclass for tool metadata:

  • name
  • description
  • input_schema
  • func
  • endpoint

tool_router_ai.registry.ToolRegistry

Register and retrieve tools.

Methods:

  • register(tool)
  • register_many(tools)
  • list_tools()
  • get(name)

tool_router_ai.embedder.Embedder

Wraps an async embedding function.

Methods:

  • embed_batch(texts)
  • embed(text)

tool_router_ai.router.ToolRouter

Builds a FAISS index from tool descriptions and routes queries.

Methods:

  • build_index()
  • route(query, top_k=3)

tool_router_ai.cache.ToolCache

Caches results with deterministic keys based on tool name and params.

Methods:

  • get(tool_name, params)
  • set(tool_name, params, result)

tool_router_ai.feedback_store.FeedbackStore

Tracks tool successes and failures.

Methods:

  • record_success(tool_name)
  • record_failure(tool_name)
  • score(tool_name)

Usage Notes

  • The package does not include a specific OpenAI client implementation.
  • Provide your own async embedder function when creating Embedder.
  • Tool routing is based on FAISS nearest-neighbor search over the tool description embeddings.

Dependencies

  • faiss-cpu
  • numpy

Contributing

  1. Fork the repository
  2. Create a branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

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

tool_router_ai-0.3.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

tool_router_ai-0.3.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tool_router_ai-0.3.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for tool_router_ai-0.3.0.tar.gz
Algorithm Hash digest
SHA256 37385f0770e08fc420db6745dad633a37ef25818b73cbe378021385bc377c96e
MD5 107a7d9acb26187f2689a07be87f9b7c
BLAKE2b-256 17ef0476ec34e9be9ddbddab92db0784692c141630d69347edbf05c0ae497f78

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tool_router_ai-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for tool_router_ai-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19d6333468211aae1323aa59d5f6ae6e9d7508be6ba2ee8341906af7fb6807a0
MD5 fbe6e38ca3363ae0af831962639deffd
BLAKE2b-256 67a3351a581128b46498d178a0b6d43dd1bc768b55678c1afe581629c3bb6feb

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