Skip to content
AstrBot
Main Navigation HomeBlogRoadmapHTTP API

English

简体中文

English

简体中文

Toggle dark mode

Intro & DeployMessaging PlatformsAI IntegrationUsageDevelopment
Sidebar Navigation

Introduction

What is AstrBot

Community

FAQ

Deployment

Script Deployment

Desktop Client

One-click Launcher

Docker

Kubernetes

BT Panel

1Panel

Source Deployment

Other Deployments

CasaOS

Compshare GPU

Community-provided Deployment

Support Us

Messaging Platforms

Quick Start

QQ Official Bot

Websockets

Webhook

OneBot v11

WeCom Application

WeCom AI Bot

WeChat Official Account

Personal WeChat

Lark

DingTalk

Telegram

LINE

Slack

Mattermost

Misskey

Discord

KOOK

Satori

Connect Satori

Using server-satori

Community-provided

Matrix

VoceChat

AI Integration

✨ Model Providers

MiraRouter

NewAPI

ShengSuanYun

AIHubMix

PPIO Cloud

SiliconFlow

TokenPony

302.AI

DeepSeek TTS

DeepSeek STT

Ollama

LMStudio

⚙️ Agent Runners

Built-in Agent Runner

Dify

Coze

Alibaba Bailian

DeerFlow

Usage

WebUI

AstrBot CLI

Built-in Commands

Plugins

Plugins

MCP

Skills

AstrBot Built-in AI

Agent Sandbox

SubAgent Orchestration

Proactive Capabilities

Web Search

SerpApi

DeepSeek Search API

Knowledge Base

Context Compression

Custom Rules

Agent Execution Mode

Unified Webhook Mode

Development

Plugin Development

🌠 Getting Started

Minimal Example

Listen to Message Events

Send Messages

Plugin Configuration

Plugin Views

Overview

Standalone plugin page

Interactive message component

Workbench page

Shared Bridge API

Backend Web APIs

Plugin Internationalization

AI

Models

Agents

Tools

Sessions and Conversations

Other APIs

Storage

HTML to Image

Session Control

Publish Plugin

Plugin Market Specification

Versions

2026-11-25

2026-06-27

Platform Adapter Integration

AstrBot HTTP API

API Scope–Endpoint Reference

AstrBot Configuration File

Others

Diagnostics

Self-hosted HTML to Image

Open Source Summer

OSPP 2025

On this page

Tools ​

Defining Tools ​

Tools enable large language models to invoke external capabilities.

py
from pydantic import Field
from pydantic.dataclasses import dataclass

# Before AstrBot v4.30.0:
# from astrbot.core.agent.run_context import ContextWrapper
# from astrbot.core.agent.tool import FunctionTool, ToolExecResult
# from astrbot.core.astr_agent_context import AstrAgentContext
from astrbot.api import FunctionTool, ToolExecResult
from astrbot.api.agents import AstrAgentContext, ContextWrapper


@dataclass
class BilibiliTool(FunctionTool[AstrAgentContext]):
    name: str = "bilibili_videos"  # Tool name
    description: str = "A tool to fetch Bilibili videos."  # Tool description
    parameters: dict = Field(
        default_factory=lambda: {
            "type": "object",
            "properties": {
                "keywords": {
                    "type": "string",
                    "description": "Keywords to search for Bilibili videos.",
                },
            },
            "required": ["keywords"],
        }
    )

    async def call(
        self, context: ContextWrapper[AstrAgentContext], **kwargs
    ) -> ToolExecResult:
        return "1. Video Title: How to Use AstrBot\nVideo Link: xxxxxx"

Registering Tools with AstrBot ​

Once a Tool is defined, if you want it to be automatically invoked during user conversations, register it in your plugin's __init__ method:

py
class MyPlugin(Star):
    def __init__(self, context: Context):
        super().__init__(context)
        # >= v4.5.1:
        self.context.add_llm_tools(BilibiliTool(), SecondTool(), ...)

        # < v4.5.1:
        tool_mgr = self.context.provider_manager.llm_tools
        tool_mgr.func_list.append(BilibiliTool())

WARNING

context.register_llm_tool() is deprecated. Do not use it in new plugins.

If you must use it for legacy compatibility, func_args must be a list of dicts in this format:

py
func_args = [{"type": "string", "name": "arg_name", "description": "..."}, ...]

Passing a list of strings or any other format will raise AttributeError: 'str' object has no attribute 'pop'.

Registering Tools via Decorator ​

Alternatively, you can use the @filter.llm_tool decorator to define and register a tool in one step. Make sure to follow the exact format below, including the docstring — AstrBot parses the docstring to generate the parameter schema:

py
@filter.llm_tool(name="get_weather")  # If name is omitted, the function name is used
async def get_weather(
    self, event: AstrMessageEvent, location: str
) -> MessageEventResult:
    """Get weather information.

    Args:
        location(string): The location to query
    """
    resp = self.get_weather_from_api(location)
    yield event.plain_result("Weather: " + resp)

In location(string): The location to query, location is the parameter name, string is the type, and the remainder is the description.

Supported types: string, number, object, boolean, array. Since v4.5.7, array subtypes are supported, e.g. array[string].

WARNING

The Args: block is required and must be formatted correctly.

The @filter.llm_tool decorator generates the parameter schema by parsing the function's docstring — it does not read Python type annotations. If the docstring is missing an Args: block, or the format does not follow param_name(type): description, the generated schema will be empty. Any arguments passed by the LLM will be silently dropped, causing the function to fail with a missing-argument error.

Additionally, passing parameters=... directly to the decorator is not supported and will be silently ignored. If you need manual control over the schema, use the @dataclass + add_llm_tools() approach above.

Edit this page on GitHub

Last updated:

Pager
PreviousAgents
NextSessions and Conversations

Deployed on Rainyun Logo