Skip to main content
Before writing a tool, ask yourself: should this be a skill instead?
Built-in Core Tools OnlyThis page is for adding a built-in Mibyan tool to the repository itself. If you want a personal, project-local, or otherwise custom tool without modifying Mibyan core, use the plugin route instead:Default to plugins for most custom tool creation. Only follow this page when you explicitly want to ship a new built-in tool in tools/ and toolsets.py.
Make it a Skill when the capability can be expressed as instructions + shell commands + existing tools (arXiv search, git workflows, Docker management, PDF processing). Make it a Tool when it requires end-to-end integration with API keys, custom processing logic, binary data handling, or streaming (browser automation, TTS, vision analysis).

Overview

Adding a tool touches 2 files:
  1. tools/your_tool.py — handler, schema, check function, registry.register() call
  2. toolsets.py — add tool name to _mibyan_CORE_TOOLS (or a specific toolset)
Any tools/*.py file with a top-level registry.register() call is auto-discovered at startup — no manual import list required.

Step 1: Create the Built-in Tool File

Every tool file follows the same structure:

Key Rules

Important
  • Handlers MUST return a JSON string (via json.dumps()), never raw dicts
  • Errors MUST be returned as {"error": "message"}, never raised as exceptions
  • The check_fn is called when building tool definitions — if it returns False, the tool is silently excluded
  • The handler receives (args: dict, **kwargs) where args is the LLM’s tool call arguments

Step 2: Add the Built-in Tool to a Toolset

In toolsets.py, add the tool name:

Step 3: Add Discovery Import (No longer needed)

Tool modules with a top-level registry.register() call are auto-discovered by discover_builtin_tools() in tools/registry.py. No manual import list to maintain — just create your file in tools/ and it’s picked up at startup.

Async Handlers

If your handler needs async code, mark it with is_async=True:
The registry handles async bridging transparently — you never call asyncio.run() yourself.

Handlers That Need task_id

Tools that manage per-session state receive task_id via **kwargs:

Agent-Loop Intercepted Tools

Some tools (todo_list, memory, session_search, delegate_task) need access to per-session agent state. These are intercepted by the agent loop (agent/tool_executor.py, called from agent/conversation_loop.py) before reaching the registry. The registry still holds their schemas, but dispatch() returns a fallback error if the intercept is bypassed.

Optional: Setup Wizard Integration

If your tool requires an API key, add it to mibyan_cli/config.py:

Checklist

  • Tool file created with handler, schema, check function, and registration
  • Added to appropriate toolset in toolsets.py
  • Confirmed this really should be a built-in/core tool and not a plugin
  • Handler returns JSON strings, errors returned as {"error": "..."}
  • Optional: API key added to OPTIONAL_ENV_VARS in mibyan_cli/config.py
  • Optional: Added to toolset_distributions.py for batch processing
  • Tested with mibyan chat -q "Use the weather tool for London"