0

Creating Custom Tools and Toolkits

Creating Custom Tools and Toolkits explains the tools layer of MTPX with practical guidance for building inspectable, tool-using agents.

Cr
Creating Custom Tools and Toolkits
Chapter 005Core runtimeToolsIndex
01Orientation

Creating Custom Tools and Toolkits belongs to the core runtime track. The page breaks the idea into responsibilities, implementation rules, failure modes, and the signals you should expose in a product UI.

Use this when

Use this when you need to understand how creating custom tools and toolkits affects a real MTPX agent before you wire it into an application.

  • What creating custom tools and toolkits owns in the runtime.
  • How it connects to planning, tool execution, events, providers, or storage.
  • What to log, test, and expose to users when this layer is active.
  • Common mistakes that make agent systems hard to inspect.
02 / syntax starter
@Agent.mtp_tool(description="Add two integers.")
def add(a: int, b: int) -> int:
    return a + b

registry.register_toolkit_loader("custom", Agent.toolkit_from_functions("custom", add))
03 / manual

Read the system

The complete source manual—syntax, examples, linked references, edge cases, and implementation notes.

Documentation index ↗

MTP supports custom tools via plain Python functions and toolkit loaders.

This guide mirrors common patterns used in agent frameworks:

  • Python functions as tools
  • Grouping tools into a toolkit
  • Registering toolkit into a ToolRegistry

1) Python functions as tools

Use @mtp_tool to attach metadata and keep definitions explicit:

pythonfrom mtp import Agent

@Agent.mtp_tool(
    description="Add two integers.",
    risk_level=Agent.ToolRiskLevel.READ_ONLY,
    cache_ttl_seconds=60,
)
def add(a: int, b: int) -> int:
    return a + b

If you omit input_schema, MTP infers a schema from function signatures/type hints.

2) Build a toolkit from functions

pythonfrom mtp import Agent

toolkit = Agent.toolkit_from_functions("custom", add)

This produces tool names like:

  • custom.add

3) Register toolkit in registry

pythonfrom mtp import Agent

registry = Agent.ToolRegistry()
registry.register_toolkit_loader("custom", toolkit)

4) Use with agent

pythonfrom mtp import Agent
from mtp.providers import Groq

provider = Groq(model="llama-3.3-70b-versatile")
agent = Agent.MTPAgent(provider=provider, tools=registry)
print(agent.run("Use custom.add with a=20 and b=22"))

Manual ToolSpec generation (advanced)

If you need explicit control:

pythonfrom mtp import Agent

spec = Agent.tool_spec_from_callable(add, namespace="custom")

Notes for robust tools

  • Write precise docstrings/descriptions. The model reads them.
  • Keep parameter names explicit and stable.
  • Mark risk level correctly (read_only, write, destructive).
  • For side effects, prefer explicit user confirmation policy.

Related:

01

Read

Understand where Creating Custom Tools and Toolkits sits in the agent loop before adding abstractions.

02

Wire

Connect the smallest useful provider, registry, store, or event stream first.

03

Observe

Expose events, logs, results, and failure states while the runtime is still moving.

04

Harden

Add policy, tests, retries, and audit traces after the behavior is visible.

Next docEvent Stream Contract