tool-prune
Calibrated tool selection and schema pruning for AI agents. Zero dependencies.
pip install tool-prune
export TYPESAFE_API_KEY="apikey_..."
Quick start
from tool_prune import prune
tools = {
"read_file": "Read raw text from local filesystem path",
"run_query": "Execute SQL queries against database",
"web_search": "Search public web for documentation or articles"
}
match = prune("what tables exist in the db?", tools)
print(match.tool) # 'run_query'
print(match.confidence) # 1.0
prune() narrows schemas to Top-K candidates or identifies direct matches in ~140ms. dispatch() runs immediate tool execution if confidence clears the threshold. That's the whole API.
Schema pruning for LLMs
from tool_prune import ToolPrune
router = ToolPrune(tools)
top_tools = router.filter(user_prompt, k=3)
response = llm.chat(
tools=top_tools,
messages=[{"role": "user", "content": user_prompt}]
)
Drops prompt tokens by 75-85% and eliminates context distraction without losing tools.
Fast-path direct dispatch
result = router.dispatch("read ./pyproject.toml", {
"read_file": lambda q, m: open("pyproject.toml").read(),
"run_query": lambda q, m: db.query(q),
"fallback": lambda q, m: call_llm(q)
})
Runs deterministic handlers in under 160ms with zero token cost.
Config
Set TYPESAFE_API_KEY in your environment, or pass options directly:
router = ToolPrune(tools,
api_key="apikey_...", # defaults to os.getenv("TYPESAFE_API_KEY")
threshold=0.85, # confidence ceiling for fast-path dispatch
top_k=3 # candidate schemas to retain
)
Demo
python examples/quickstart.py
Runs live quickstart routing with your TYPESAFE_API_KEY.
License
MIT © Hemanth.HM
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tool_prune-0.1.1.tar.gz.
File metadata
- Download URL: tool_prune-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c841a0c6e93cb9a13e13f5337a8dc270f47f2113fbdb70168c25ad8970bc24d4
|
|
| MD5 |
d914507c54f5f76f30655ded8adfcf7b
|
|
| BLAKE2b-256 |
e3c9a7b5a9a24618832d0c07e3790df3b659758e967f089123252bd9ba24c565
|
File details
Details for the file tool_prune-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tool_prune-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22a5d584dedccc4b97f06fddc41b69975526d6c7cd1481bafa241b19dd3aea29
|
|
| MD5 |
9cdd1e0bc9eabbdb422b6fa26110e7d2
|
|
| BLAKE2b-256 |
d29ae116be105b9a89956b6d362d9e4fc4fcbc00b3ebcec3b820a92e7eb5baaf
|