tool-use

tool-use is an agent for Claude Code from cubeplexai/cubepi. It costs 23 tokens per session (2,880 once invoked), scanned A, original, MIT.

A guide to giving an AI agent tools that it can call. It explains how CubePi turns typed Python functions into validated tool descriptions and can run several tool calls at once.

In plain words
What is it for?
Use it to define agent tools with Python, describe their inputs, validate arguments with Pydantic, and handle parallel tool calls.
Why use it?
It removes the need to write separate input schemas and repetitive execution code for each tool. Validation also helps reject arguments that do not match the declared rules.

Agent for Claude Code

Written for Claude Code: a Claude Code subagent (agents/*.md).

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/cubeplexai/cubepi/tool-use
Clone the repo
git clone --depth 1 https://github.com/cubeplexai/cubepi

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for tool-use

README.md
[![agentmods](https://agentmods.dev/badge/agents/cubeplexai/cubepi/tool-use.svg)](https://agentmods.dev/agents/cubeplexai/cubepi/tool-use)
Your own site
<a href="https://agentmods.dev/agents/cubeplexai/cubepi/tool-use"><img src="https://agentmods.dev/badge/agents/cubeplexai/cubepi/tool-use.svg" alt="Measured on agentmods" height="20"></a>
Per session 23 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,880 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00023 $0.02880
Opus 5 $0.00012 $0.01440
Sonnet 5 $0.00005 $0.00576
Haiku 4.5 $0.00002 $0.00288

Measured 6d ago against content hash da6b61b93253, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

tool-use scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

website/docs/guides/agents/tool-use.md · 339 lines

How it starts

The opening of the file, as written. The whole thing — 339 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Tool Use & Parallel Execution

Tools are how an agent acts on the world. CubePi turns each AgentTool into a JSON Schema for the model, validates arguments with Pydantic, runs the work, and feeds the result back as a ToolResultMessage. By default tools run in parallel when the model calls more than one in a single turn.

The @tool decorator

The quickest way to define a tool is to decorate an async function. CubePi generates the input schema from the parameters, so there's no separate model or boilerplate execute signature to write:

from typing import Annotated
from pydantic import Field
from cubepi import tool


@tool
async def search(
    query: Annotated[str, Field(description="The natural-language query")],
    limit: Annotated[int, Field(ge=1, le=100)] = 10,
) -> str:
    "Search the internal knowledge base."
    results = await my_search_backend(query, limit)
    return "\n".join(results)

That's a complete, registrable AgentTool. The decorator infers:

  • name from the function name (override with @tool(name=...));
  • description from the docstring (override with @tool(description=...));
  • the input schema from the typed parameters — Field(...) defaults and metadata are honoured exactly as in a hand-written model.

The return value can be a plain str (wrapped as text, as above), a TextContent, a list of content, or a full AgentToolResult when you need details, is_error, or terminate:

from cubepi import tool, AgentToolResult, TextContent


@tool
async def search(query: str, limit: int = 10) -> AgentToolResult:
    "Search the internal knowledge base."
    results = await my_search_backend(query, limit)
    return AgentToolResult(
        content=[TextContent(text="\n".join(results))],
        details={"raw_results": results},   # passes through to ToolResultMessage.details
    )

To run a tool sequentially, pass @tool(execution_mode="sequential"). If the function needs the loop-supplied arguments, just declare them — any of tool_call_id, signal, or on_update are injected when present and never appear in the schema:

Read the full file on GitHub · 339 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 339 lines · 23 tokens per session scan A da6b61b93253

Subscribe to this mod's changes

tool-use is an agent published in the GitHub repository cubeplexai/cubepi (46 stars, last pushed 3d ago), licensed MIT. It adds 23 tokens to every session and 2,880 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.