Skip to content

Commit 4cb8e98

Browse files
committed
feat: update AI guide with new LLM conversation management methods and remove redundant tips
1 parent a432456 commit 4cb8e98

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

zh/dev/star/guides/ai.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ provider_id = await self.context.get_current_chat_provider_id(umo=umo)
2222
> [!TIP]
2323
> 在 v4.5.7 时加入
2424
25-
2625
```py
2726
llm_resp = await self.context.llm_generate(
2827
chat_provider_id=provider_id, # 聊天模型 ID
@@ -72,7 +71,6 @@ class BilibiliTool(FunctionTool[AstrAgentContext]):
7271
> [!TIP]
7372
> 在 v4.5.7 时加入
7473
75-
7674
Agent 可以被定义为 system_prompt + tools + llm 的结合体,可以实现更复杂的智能体行为。
7775

7876
在上面定义好 Tool 之后,可以通过以下方式调用 Agent:
@@ -96,7 +94,6 @@ llm_resp = await self.context.tool_loop_agent(
9694
> [!TIP]
9795
> 在 v4.5.7 时加入
9896
99-
10097
Multi-Agent(多智能体)系统将复杂应用分解为多个专业化智能体,它们协同解决问题。不同于依赖单个智能体处理每一步,多智能体架构允许将更小、更专注的智能体组合成协调的工作流程。我们使用 `agent-as-tool` 模式来实现多智能体系统。
10198

10299
在下面的例子中,我们定义了一个主智能体(Main Agent),它负责根据用户查询将任务分配给不同的子智能体(Sub-Agents)。每个子智能体专注于特定任务,例如获取天气信息。
@@ -246,7 +243,7 @@ async def test(self, event: AstrMessageEvent):
246243

247244
## 对话管理器
248245

249-
### 获取会话当前的 LLM 对话历史
246+
### 获取会话当前的 LLM 对话历史 `get_conversation`
250247

251248
```py
252249
from astrbot.core.conversation_mgr import Conversation
@@ -284,6 +281,30 @@ class Conversation:
284281

285282
:::
286283

284+
### 快速添加 LLM 记录到对话 `add_message_pair`
285+
286+
```py
287+
from astrbot.core.agent.message import (
288+
AssistantMessageSegment,
289+
UserMessageSegment,
290+
TextPart,
291+
)
292+
293+
curr_cid = await conv_mgr.get_curr_conversation_id(event.unified_msg_origin)
294+
user_msg = UserMessageSegment(content=[TextPart(text="hi")])
295+
llm_resp = await self.context.llm_generate(
296+
chat_provider_id=provider_id, # 聊天模型 ID
297+
contexts=[user_msg], # 当未指定 prompt 时,使用 contexts 作为输入;同时指定 prompt 和 contexts 时,prompt 会被添加到 LLM 输入的最后
298+
)
299+
await conv_mgr.add_message_pair(
300+
cid=curr_cid,
301+
user_message=user_msg,
302+
assistant_message=AssistantMessageSegment(
303+
content=[TextPart(text=llm_resp.completion_text)]
304+
),
305+
)
306+
```
307+
287308
### 主要方法
288309

289310
#### `new_conversation`

0 commit comments

Comments
 (0)