Merged
Conversation
Contributor
Reviewer's Guide调整用于聊天交互的提示词构建和系统 schema,修复配置使用引用,对工具观察消息进行条件发送,简化与管理员相关的配置和检查,并将包的补丁版本号向上调整。 run_tools 中条件工具观察消息的时序图sequenceDiagram
participant Caller
participant run_tools
participant Bot
participant LLM
Caller->>run_tools: call run_tools(msg_list, event, call_count, original_msg)
loop for each tool_result
run_tools->>Bot: send(nonebot_event, message) when message_mode == show
Bot-->>run_tools: ack
end
alt result_msg_list is not empty
run_tools->>run_tools: build observation_msg from result_msg_list
run_tools->>run_tools: append Message(role user, content observation_block) to msg_list
run_tools->>LLM: send updated msg_list for next reasoning
LLM-->>run_tools: tool-aware response
else result_msg_list is empty
run_tools->>LLM: send msg_list without observation_msg
LLM-->>run_tools: response without new observations
end
run_tools-->>Caller: recursive processing continues
更新后的聊天配置和管理员 API 类图classDiagram
class Config {
+FunctionConfig function
+ExtendConfig extended
+LLM_Config llm_config
+UsageLimitConfig usage_limit
+dict~str,Any~ extra
}
class FunctionConfig {
}
class ExtendConfig {
}
class LLM_Config {
+bool enable_memory_abstract
}
class UsageLimitConfig {
+bool enable_usage_limit
+int group_daily_limit
+int user_daily_limit
}
class Admin {
+Config config
+Bot bot
+Event event
+async send_error(msg str) Admin
}
%% 本 PR 中移除的类
class AdminConfig_removed {
+bool allow_send_to_admin
+list~int~ admins
+int admin_group
}
Config *-- FunctionConfig
Config *-- ExtendConfig
Config *-- LLM_Config
Config *-- UsageLimitConfig
Admin *-- Config
文件级变更
提示与命令与 Sourcery 交互
自定义你的体验访问你的 dashboard 以:
获取帮助Original review guide in EnglishReviewer's GuideAdjusts prompt construction and system schema for chat interactions, fixes config usage references, conditions tool observation messages, simplifies admin-related configuration and checks, and bumps the package patch version. Sequence diagram for conditional tool observation message in run_toolssequenceDiagram
participant Caller
participant run_tools
participant Bot
participant LLM
Caller->>run_tools: call run_tools(msg_list, event, call_count, original_msg)
loop for each tool_result
run_tools->>Bot: send(nonebot_event, message) when message_mode == show
Bot-->>run_tools: ack
end
alt result_msg_list is not empty
run_tools->>run_tools: build observation_msg from result_msg_list
run_tools->>run_tools: append Message(role user, content observation_block) to msg_list
run_tools->>LLM: send updated msg_list for next reasoning
LLM-->>run_tools: tool-aware response
else result_msg_list is empty
run_tools->>LLM: send msg_list without observation_msg
LLM-->>run_tools: response without new observations
end
run_tools-->>Caller: recursive processing continues
Class diagram for updated chat configuration and admin APIclassDiagram
class Config {
+FunctionConfig function
+ExtendConfig extended
+LLM_Config llm_config
+UsageLimitConfig usage_limit
+dict~str,Any~ extra
}
class FunctionConfig {
}
class ExtendConfig {
}
class LLM_Config {
+bool enable_memory_abstract
}
class UsageLimitConfig {
+bool enable_usage_limit
+int group_daily_limit
+int user_daily_limit
}
class Admin {
+Config config
+Bot bot
+Event event
+async send_error(msg str) Admin
}
%% Removed class in this PR
class AdminConfig_removed {
+bool allow_send_to_admin
+list~int~ admins
+int admin_group
}
Config *-- FunctionConfig
Config *-- ExtendConfig
Config *-- LLM_Config
Config *-- UsageLimitConfig
Admin *-- Config
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - 我发现了两个问题,并给出了一些整体性的反馈:
- 新的摘要
content构造方式("消息列表:\n```text".join([...]) + "```")会在每个条目之间都插入这一行头部,而不是只在开头插入一次,而且在text 之后缺少一个换行符;建议显式构造,例如:`"消息列表:\ntext\n" + "".join(...) + "```"`。 - 在
self.train["content"]中新加入的<SUMMARY>段落缺少对应的闭合标签</SUMMARY>,但 schema 文本表明它应该是成对标签;将摘要内容同时包裹在起始和结束标签中会更清晰、更安全。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- 新的摘要 `content` 构造方式(`"消息列表:\n```text".join([...]) + "```"`)会在每个条目之间都插入这一行头部,而不是只在开头插入一次,而且在 ```text 之后缺少一个换行符;建议显式构造,例如:`"消息列表:\n```text\n" + "".join(...) + "```"`。
- 在 `self.train["content"]` 中新加入的 `<SUMMARY>` 段落缺少对应的闭合标签 `</SUMMARY>`,但 schema 文本表明它应该是成对标签;将摘要内容同时包裹在起始和结束标签中会更清晰、更安全。
## Individual Comments
### Comment 1
<location> `amrita/plugins/chat/handlers/chat.py:205-206` </location>
<code_context>
- self._dropped_messages + dropped_part, split_role=True
- )
- ]
+ content=(
+ "消息列表:\n```text".join(
+ [
+ f"{it}\n"
</code_context>
<issue_to_address>
**issue (bug_risk):** 使用 `"消息列表:\n```text".join(...)` 会导致在每条消息之间重复这一行头部,而不是只在最前面加上它。
由于头部字符串被用作 `join` 的分隔符,结果会是 `seg1 + header + seg2 + ...`,而不是在完整内容前只有一个头部。如果你希望只有一个头部和一对代码块标记,建议先把所有条目拼接,再整体包一层,比如:
```python
content = (
"消息列表:\n```text\n"
+ "".join(
f"{it}\n" for it in text_generator(
self._dropped_messages + dropped_part, split_role=True
)
)
+ "```"
)
```
</issue_to_address>
### Comment 2
<location> `amrita/plugins/chat/handlers/chat.py:477` </location>
<code_context>
.replace("{user_name}", str(event.sender.nickname))
)
+ "\n</SYSTEM_PROMPT>"
+ + f"\n<SUMMARY>{data.memory_abstract if config.llm_config.enable_memory_abstract else ''}"
)
async with MemoryLimiter(self.data, self.train) as lim:
</code_context>
<issue_to_address>
**issue (bug_risk):** `<SUMMARY>` 标签被打开但从未关闭,这与 schema 描述不一致,也可能导致后续解析出错。
在 schema 中 `<SUMMARY>` 被视为成对标签,但这里只输出了起始标签,没有对应的 `</SUMMARY>` 闭合标签。这可能会破坏期望结构良好的标签的下游消费者。建议将内容包裹为完整的一对标签:
```python
summary = data.memory_abstract if config.llm_config.enable_memory_abstract else ""
self.train["content"] = (
...
+ "\n</SYSTEM_PROMPT>"
+ f"\n<SUMMARY>{summary}</SUMMARY>"
)
```
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- The new
contentconstruction for the abstract ("消息列表:\n```text".join([...]) + "```") will insert the header between every item instead of once at the beginning and also omits a newline aftertext; consider building it explicitly, e.g. `"消息列表:\ntext\n" + "".join(...) + "```"`. - The newly added
<SUMMARY>section inself.train["content"]is missing a closing</SUMMARY>tag even though the schema text implies a tag pair; it would be clearer and safer to wrap the summary content with both opening and closing tags.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `content` construction for the abstract (`"消息列表:\n```text".join([...]) + "```"`) will insert the header between every item instead of once at the beginning and also omits a newline after ```text; consider building it explicitly, e.g. `"消息列表:\n```text\n" + "".join(...) + "```"`.
- The newly added `<SUMMARY>` section in `self.train["content"]` is missing a closing `</SUMMARY>` tag even though the schema text implies a tag pair; it would be clearer and safer to wrap the summary content with both opening and closing tags.
## Individual Comments
### Comment 1
<location> `amrita/plugins/chat/handlers/chat.py:205-206` </location>
<code_context>
- self._dropped_messages + dropped_part, split_role=True
- )
- ]
+ content=(
+ "消息列表:\n```text".join(
+ [
+ f"{it}\n"
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `"消息列表:\n```text".join(...)` will repeat the header between every message instead of prefixing it once.
Because the header string is used as the `join` separator, you get `seg1 + header + seg2 + ...` rather than a single header before the full content. If you want one header and one code block wrapper, build the string once around the concatenated items, e.g.:
```python
content = (
"消息列表:\n```text\n"
+ "".join(
f"{it}\n" for it in text_generator(
self._dropped_messages + dropped_part, split_role=True
)
)
+ "```"
)
```
</issue_to_address>
### Comment 2
<location> `amrita/plugins/chat/handlers/chat.py:477` </location>
<code_context>
.replace("{user_name}", str(event.sender.nickname))
)
+ "\n</SYSTEM_PROMPT>"
+ + f"\n<SUMMARY>{data.memory_abstract if config.llm_config.enable_memory_abstract else ''}"
)
async with MemoryLimiter(self.data, self.train) as lim:
</code_context>
<issue_to_address>
**issue (bug_risk):** The `<SUMMARY>` tag is opened but never closed, which contradicts the schema description and may confuse downstream parsing.
Here `<SUMMARY>` is treated as a paired tag in the schema, but only the opening tag is emitted and no closing `</SUMMARY>` is added. This can break consumers expecting well-formed tags. Consider wrapping the content as a full pair:
```python
summary = data.memory_abstract if config.llm_config.enable_memory_abstract else ""
self.train["content"] = (
...
+ "\n</SYSTEM_PROMPT>"
+ f"\n<SUMMARY>{summary}</SUMMARY>"
)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
在优化工具观察消息并升级软件包版本的同时,改进聊天提示词构造、配置使用方式和管理员处理逻辑。
新特性:
漏洞修复:
增强:
is_lp_admin辅助函数,并移除未使用的管理员配置和辅助 API,来简化管理员授权逻辑。构建:
Original summary in English
Summary by Sourcery
Refine chat prompt construction, configuration usage, and admin handling while tightening tool observation messaging and bumping the package version.
New Features:
Bug Fixes:
Enhancements:
Build: