Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 155 additions & 90 deletions ai/Agent/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -686,61 +686,81 @@ if PKG_USING_AGENT
endmenu

menu "Agent Skills Configuration"
config PKG_AGENT_SKILL_ENABLE
bool "Enable built-in skills"
default y

choice PKG_AGENT_SKILL_MODE_SEL
prompt "Built-in skills"
default PKG_AGENT_SKILL_DISABLE
help
Compile the skill registry, the skill tool, and the embedded
Markdown catalog into firmware. Turn this off on MCUs without
room for the skill module; the sources are excluded entirely
and the system prompt gets no skill catalog.
Markdown catalog into firmware. Disabled by default so a fresh
configuration builds only the minimal core; the two options
below only show up after this is enabled.

The two options below are ignored when this is disabled.
config PKG_AGENT_SKILL_DISABLE
bool "Disable built-in skills"

config PKG_AGENT_SKILL_DIR
depends on PKG_AGENT_SKILL_ENABLE
string "Markdown skill directory"
default "skills"
help
Recursively embed .md files as const C strings at build time.
Relative paths are resolved from the Agent package directory;
absolute paths are also supported. Use UTF-8 Markdown files.
The relative path without .md is the skill name.
Override for one build with scons agent_skill_dir=<directory>.
Changes require rebuilding firmware; no runtime filesystem is needed.

config PKG_AGENT_SKILL_EMBED
depends on PKG_AGENT_SKILL_ENABLE
string "Skills to embed"
default "*"
help
Selects which Markdown skills are compiled into firmware.
An asterisk (default) embeds every .md file found under the
skill directory. A comma-separated list embeds only those
names, for example "device,math". "none" or an empty value
embeds no skill content.

Trimmed skills take no Flash space and are absent from the
skill catalog in the system prompt. A listed name that does
not exist stops the build, so typos do not silently drop a
skill. Rebuild firmware after changing this value.
config PKG_AGENT_SKILL_ENABLE
bool "Enable built-in skills"
help
Compile the skill registry, the skill tool, and the
embedded Markdown catalog into firmware. Turn this off on
MCUs without room for the skill module; the sources are
excluded entirely and the system prompt gets no skill
catalog.
endchoice

if PKG_AGENT_SKILL_ENABLE

config PKG_AGENT_SKILL_DIR
string "Markdown skill directory"
default "skills"
help
Recursively embed .md files as const C strings at build time.
Relative paths are resolved from the Agent package directory;
absolute paths are also supported. Use UTF-8 Markdown files.
The relative path without .md is the skill name.
Override for one build with scons agent_skill_dir=<directory>.
Changes require rebuilding firmware; no runtime filesystem is needed.

config PKG_AGENT_SKILL_EMBED
string "Skills to embed"
default "*"
help
Selects which Markdown skills are compiled into firmware.
An asterisk (default) embeds every .md file found under the
skill directory. A comma-separated list embeds only those
names, for example "device,math". "none" or an empty value
embeds no skill content.

Trimmed skills take no Flash space and are absent from the
skill catalog in the system prompt. A listed name that does
not exist stops the build, so typos do not silently drop a
skill. Rebuild firmware after changing this value.
endif
endmenu

menu "Agent Memory"

config PKG_AGENT_MEMORY_ENABLE
bool "Enable layered memory"
default n
choice PKG_AGENT_MEMORY_MODE_SEL
prompt "Layered memory"
default PKG_AGENT_MEMORY_DISABLE
help
MemGPT-style memory on top of the conversation context.
Core memory is injected into every model request. Recall
memory is searched with keywords from the latest user
message and the top matches are appended after it.

The pool is static, no heap is used. Default sizes cost
about 8 KB of RAM: 8 core items and 32 recall items of
192 bytes, plus a 1 KB injection buffer. When disabled
the module compiles out and all call sites become no-ops.
config PKG_AGENT_MEMORY_DISABLE
bool "Disable layered memory"

config PKG_AGENT_MEMORY_ENABLE
bool "Enable layered memory"
help
The pool is static, no heap is used. Default sizes cost
about 8 KB of RAM: 8 core items and 32 recall items of
192 bytes, plus a 1 KB injection buffer. When disabled
the module compiles out and all call sites become no-ops.
endchoice

if PKG_AGENT_MEMORY_ENABLE

Expand Down Expand Up @@ -831,6 +851,22 @@ if PKG_USING_AGENT

menu "Agent Tools Configuration"

choice PKG_AGENT_TOOL_CALC_MODE_SEL
prompt "Arithmetic tools"
default PKG_AGENT_TOOL_CALC_DISABLE
help
Compile the three demo arithmetic tools: add, mul and
compare. They are only examples; a minimal build keeps
them out of firmware. Turn this on for smoke tests or when
the model should do simple calculations.

config PKG_AGENT_TOOL_CALC_DISABLE
bool "Disable arithmetic tools"

config PKG_AGENT_TOOL_CALC_ENABLE
bool "Enable arithmetic tools"
endchoice

config PKG_AGENT_TOOL_LOOP_MAX
int "Max tool call rounds per request"
default 6
Expand All @@ -849,44 +885,54 @@ if PKG_USING_AGENT

menu "Agent Tool: Mqtt Client"

config PKG_AGENT_TOOL_MQTT_ENABLE
bool "Enable MQTT client tool"
select PKG_USING_PAHOMQTT
# 工具依赖 paho 的 pipe 模式(UDP 模式不提供 publish/subscribe 接口)。
# 注意:PAHOMQTT_PIPE_MODE / PAHOMQTT_UDP_MODE 在 paho 的 Kconfig 里是
# 同一个 choice 的成员,select 对 choice 成员无效(kconfiglib 会报
# "select/imply has no effect on choice symbols"),所以这里不能 select,
# 原来那句 select PAHOMQTT_PIPE_MODE 实际不起作用。请在 paho menuconfig
# 里手动确认 "MQTT mode" 选的是 Pipe mode;若选成 UDP,
# tool_mqtt.h 会在编译期直接 #error 提示。
default n
choice PKG_AGENT_TOOL_MQTT_MODE_SEL
prompt "MQTT client tool"
default PKG_AGENT_TOOL_MQTT_DISABLE
help
Enable the MQTT tool set for the agent:
* mqtt_connect : connect to the broker (idempotent)
* mqtt_disconnect : disconnect from the broker, keeping the
subscription table so a later connect
re-subscribes automatically
* mqtt_publish : publish a command to a topic
(checks the connection first)
* mqtt_subscribe : subscribe/unsubscribe topics at runtime
(delivery mode: filter/auto/poll)
* mqtt_rule : threshold rules, only wake the agent when out of range
* mqtt_history : summarize recent messages/payloads + numeric
min/max/avg, so the agent can assess the recent
situation (read-only)
* mqtt_receive : consume buffered messages on demand

Requires paho-mqtt in PIPE mode: select it manually in the
paho menuconfig ("MQTT mode" -> Pipe mode), it cannot be
selected from here because it is a choice member.

IMPORTANT (paho side, must be set in the paho menuconfig):
* PKG_PAHOMQTT_SUBSCRIBE_HANDLERS >= PKG_AGENT_TOOL_MQTT_MAX_SUB_TOPICS
(default 4; with the paho default of 1 only one topic can be subscribed)
* RT_PKG_MQTT_THREAD_STACK_SIZE >= 8192
(the paho worker opens "/dev/MQTTn" through DFS, whose path
resolution allocates ~12KB and needs stack; a 4KB stack
overflows it, corrupts heap metadata and hangs the system)
Let the agent talk to an MQTT broker through paho. The sub
menus below only show up after this is enabled.

config PKG_AGENT_TOOL_MQTT_DISABLE
bool "Disable MQTT client tool"

config PKG_AGENT_TOOL_MQTT_ENABLE
bool "Enable MQTT client tool"
select PKG_USING_PAHOMQTT
help
Enable the MQTT tool set for the agent:
* mqtt_connect : connect to the broker (idempotent)
* mqtt_disconnect : disconnect from the broker, keeping the
subscription table so a later connect
re-subscribes automatically
* mqtt_publish : publish a command to a topic
(checks the connection first)
* mqtt_subscribe : subscribe/unsubscribe topics at runtime
(delivery mode: filter/auto/poll)
* mqtt_rule : threshold rules, only wake the agent when out of range
* mqtt_history : summarize recent messages/payloads + numeric
min/max/avg, so the agent can assess the recent
situation (read-only)
* mqtt_receive : consume buffered messages on demand

Requires paho-mqtt in PIPE mode: select it manually in the
paho menuconfig ("MQTT mode" -> Pipe mode), it cannot be
selected from here because it is a choice member.

IMPORTANT (paho side, must be set in the paho menuconfig):
* PKG_PAHOMQTT_SUBSCRIBE_HANDLERS >= PKG_AGENT_TOOL_MQTT_MAX_SUB_TOPICS
(default 4; with the paho default of 1 only one topic can be subscribed)
* RT_PKG_MQTT_THREAD_STACK_SIZE >= 8192
(the paho worker opens "/dev/MQTTn" through DFS, whose path
resolution allocates ~12KB and needs stack; a 4KB stack
overflows it, corrupts heap metadata and hangs the system)
endchoice

if PKG_AGENT_TOOL_MQTT_ENABLE

Expand Down Expand Up @@ -1138,15 +1184,22 @@ if PKG_USING_AGENT
# 每个模块文件自己用 #ifdef PKG_AGENT_TOOL_DEVICE_XXX 包住全文,并用
# AGENT_TOOL_MODULE_EXPORT 登记到模块表,所以关掉某个模块 = 不编译该文件,
# 注册表和工具列表里自然没有它,不需要改中心文件。
config PKG_AGENT_TOOL_DEVICE
bool "Enable device framework tools"
choice PKG_AGENT_TOOL_DEVICE_MODE_SEL
prompt "Device framework tools"
depends on RT_USING_DEVICE
default n
default PKG_AGENT_TOOL_DEVICE_DISABLE
help
Let the agent drive peripherals through the RT-Thread device framework.
Turn on the generic layer (core) first, then pick the device classes the
project actually has drivers for.

config PKG_AGENT_TOOL_DEVICE_DISABLE
bool "Disable device framework tools"

config PKG_AGENT_TOOL_DEVICE
bool "Enable device framework tools"
endchoice

if PKG_AGENT_TOOL_DEVICE

config PKG_AGENT_TOOL_DEVICE_CORE
Expand Down Expand Up @@ -1234,24 +1287,36 @@ if PKG_USING_AGENT

menu "Agent Tool: MCP Client"

config PKG_AGENT_TOOL_MCP_ENABLE
bool "Enable MCP client tools"
default n
choice PKG_AGENT_TOOL_MCP_MODE_SEL
prompt "MCP client tools"
default PKG_AGENT_TOOL_MCP_DISABLE
help
Let the agent talk to one MCP (Model Context Protocol) server
over Streamable HTTP. At agent startup the client runs the
initialize / notifications/initialized / tools/list handshake
and registers every remote tool into the agent tool table with
an "mcp_" prefix, so the model can call them like local tools.

The server side lives in the package mcp/ directory: a bundled
HTTP server plus a stdio-to-HTTP bridge for the servers Windows
registers through the On-Device Registry (odr.exe list) and for
servers started from the command line, such as Windows-MCP
(CursorTouch/Windows-MCP), which drives the local desktop.

If the server cannot be reached the agent still starts, just
without the remote tools.
over Streamable HTTP. The options below only show up after
this is enabled.

config PKG_AGENT_TOOL_MCP_DISABLE
bool "Disable MCP client tools"

config PKG_AGENT_TOOL_MCP_ENABLE
bool "Enable MCP client tools"
help
At agent startup the client runs the
initialize / notifications/initialized / tools/list
handshake and registers every remote tool into the agent
tool table with an "mcp_" prefix, so the model can call
them like local tools.

The server side lives in the package mcp/ directory: a
bundled HTTP server plus a stdio-to-HTTP bridge for the
servers Windows registers through the On-Device Registry
(odr.exe list) and for servers started from the command
line, such as Windows-MCP (CursorTouch/Windows-MCP),
which drives the local desktop.

If the server cannot be reached the agent still starts,
just without the remote tools.
endchoice

if PKG_AGENT_TOOL_MCP_ENABLE

Expand Down