fix: 修复 subagent 使用 default persona 时查找失败的问题#5672
fix: 修复 subagent 使用 default persona 时查找失败的问题#5672whatevertogo wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
…on logic - Add PersonaManager.get_persona_v3_by_id() to centralize v3 persona resolution - Handle 'default' persona_id mapping to DEFAULT_PERSONALITY in subagent orchestrator - Fix HandoffTool.default_description using agent_name parameter correctly - Add tests for default persona in subagent config and tool deduplication Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在解决 subagent 在配置中使用 "default" persona 时查找失败的问题。通过引入一个统一的 persona 查找方法,并更新相关逻辑以正确处理 "default" 标识符,确保 subagent 能够正确加载默认 persona 的配置,从而避免回退到内联 prompt 导致功能缺失。 Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - 我给出了一些整体性的反馈:
- 新的
get_persona_v3_by_id辅助函数的类型标注为返回Personality,但在使用时却被当作dict(例如persona.get("tools"))来访问,这与现有的personas_v3结构不一致;建议更新返回类型和相关注解,使其反映实际的映射/dict 结构,或者考虑将底层数据封装在一个类似Personality的对象中。 - 既然
get_persona_v3_by_id现在是 v3 personas 的核心查找路径,那么在该方法内部对persona_id做规范化处理(例如str(...).strip(),以及必要时做大小写归一化)可能会更安全,而不是依赖像reload_from_config这样的各个调用方来预清洗这个标识符。
给 AI 代理的提示
Please address the comments from this code review:
## Overall Comments
- The new `get_persona_v3_by_id` helper is annotated to return `Personality` but is used as a `dict` (e.g., `persona.get("tools")`), which is inconsistent with the existing `personas_v3` structure; consider updating the return type and related annotations to reflect the actual mapping/dict shape or wrapping the underlying data in a `Personality`-like object.
- Since `get_persona_v3_by_id` is now the central lookup path for v3 personas, it may be safer to normalize `persona_id` inside this method (e.g., `str(...).strip()` and possibly case normalization) rather than relying on individual callers like `reload_from_config` to pre-clean the identifier.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据这些反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- The new
get_persona_v3_by_idhelper is annotated to returnPersonalitybut is used as adict(e.g.,persona.get("tools")), which is inconsistent with the existingpersonas_v3structure; consider updating the return type and related annotations to reflect the actual mapping/dict shape or wrapping the underlying data in aPersonality-like object. - Since
get_persona_v3_by_idis now the central lookup path for v3 personas, it may be safer to normalizepersona_idinside this method (e.g.,str(...).strip()and possibly case normalization) rather than relying on individual callers likereload_from_configto pre-clean the identifier.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `get_persona_v3_by_id` helper is annotated to return `Personality` but is used as a `dict` (e.g., `persona.get("tools")`), which is inconsistent with the existing `personas_v3` structure; consider updating the return type and related annotations to reflect the actual mapping/dict shape or wrapping the underlying data in a `Personality`-like object.
- Since `get_persona_v3_by_id` is now the central lookup path for v3 personas, it may be safer to normalize `persona_id` inside this method (e.g., `str(...).strip()` and possibly case normalization) rather than relying on individual callers like `reload_from_config` to pre-clean the identifier.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Related Documentation 1 document(s) may need updating based on files changed in this PR: AstrBotTeam's Space pr4697的改动View Suggested Changes@@ -34,6 +34,23 @@
#### 配置说明
SubAgent 的定义与 Persona 配置一致,需在配置文件中指定 tools、skills、name、description 等。
+
+**Persona 引用(PR #5672)**
+
+子代理支持通过 `persona_id` 字段引用现有的 Persona 配置。[PR #5672](https://github.com/AstrBotDevs/AstrBot/pull/5672) 修复了子代理使用 `persona_id: "default"` 时的查找失败问题:
+
+- **`persona_id: "default"`**:现在可正确引用系统内置的 DEFAULT_PERSONALITY,包括其配置的所有工具、begin_dialogs 等设置
+- **自定义 Persona**:使用其他 `persona_id` 值(如自定义人格名称)时,系统会从 `personas_v3` 列表中按名称查找对应的人格配置
+- **空值或未配置**:如果 `persona_id` 为空或未配置,子代理将使用内联的 `system_prompt` 和工具配置
+
+修复前,子代理使用 `persona_id: "default"` 会因查找失败而回退到内联 prompt,丢失 default persona 的完整配置(如 tools、begin_dialogs 等)。修复后,系统新增 `PersonaManager.get_persona_v3_by_id()` 方法,统一了 persona 查找逻辑:
+- `None` 或空字符串返回 `None`
+- `"default"` 映射到内存中的 `DEFAULT_PERSONALITY`
+- 其他值从 `personas_v3` 列表中按 name 查找
+
+`SubAgentOrchestrator.reload_from_config()` 方法现在使用新的查找方法正确解析 persona 引用,确保子代理配置的正确性。
+
+**委派工具参数**
transfer_to_* 工具现支持以下参数:
- `input`:转交给子代理的任务输入(必填)Note: You must be authenticated to accept/decline updates. |
There was a problem hiding this comment.
Code Review
这次的 PR 成功修复了 subagent 使用 persona_id: "default" 时 persona 解析失败的问题。核心改动是引入了 PersonaManager.get_persona_v3_by_id 方法,它统一了 persona 的查找逻辑,正确地处理了 "default" 标识符,这是一个清晰且有效的重构。相关的模块如 SubAgentOrchestrator 和 _ensure_persona_and_skills 也都正确地适配了此新方法。此外,PR 中包含了全面的单元测试和集成测试,很好地覆盖了修复的场景。代码质量很高,没有发现需要修改的问题。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Motivation / 动机
修复 subagent 配置中使用
persona_id: "default"时无法正确解析的问题。此前,SubAgentOrchestrator调用get_persona()查找 persona,但该方法不支持"default"这个特殊标识符,导致 subagent 回退到内联 prompt,丢失了 default persona 的配置(如 tools、begin_dialogs 等)。Modifications / 改动点
新增
PersonaManager.get_persona_v3_by_id()方法,统一 v3 persona 查找逻辑None/空字符串返回None"default"映射到内存中的DEFAULT_PERSONALITYpersonas_v3列表中按 name 查找修复
SubAgentOrchestrator.reload_from_config()使用新方法解析 persona修复
HandoffTool.default_description()参数agent_name未被使用的问题重构
_ensure_persona_and_skills()复用get_persona_v3_by_id()简化代码新增 7 个测试用例覆盖修复场景
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
$ python -m pytest tests/unit/test_subagent_orchestrator.py tests/unit/test_astr_main_agent.py::TestEnsurePersonaAndSkills::test_subagent_dedupe_uses_default_persona_tools tests/test_dashboard.py::test_subagent_config_accepts_default_persona -v tests/unit/test_subagent_orchestrator.py::test_reload_from_config_default_persona_is_resolved PASSED tests/unit/test_subagent_orchestrator.py::test_reload_from_config_missing_persona_falls_back_to_inline_and_warns PASSED tests/unit/test_subagent_orchestrator.py::test_reload_from_config_uses_processed_begin_dialogs_and_deepcopy PASSED tests/unit/test_subagent_orchestrator.py::test_reload_from_config_tool_normalization[None-None] PASSED tests/unit/test_subagent_orchestrator.py::test_reload_from_config_tool_normalization[raw_tools1-expected_tools2] PASSED tests/unit/test_subagent_orchestrator.py::test_reload_from_config_tool_normalization[not-a-list-expected_tools2] PASSED tests/unit/test_astr_main_agent.py::TestEnsurePersonaAndSkills::test_subagent_dedupe_uses_default_persona_tools PASSED tests/test_dashboard.py::test_subagent_config_accepts_default_persona PASSED ======================== 8 passed, 4 warnings in 3.36s ========================Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
修复子代理(subagent)人格(persona)解析逻辑,以正确处理特殊的
"default"人格标识符,并改进子代理配置行为。Bug 修复:
"default"的子代理能够正确解析并应用默认人格配置,而不是回退到内联提示(inline prompts)。HandoffTool.default_description中使用目标代理名称,使生成的交接描述能够引用正确的代理。增强功能:
PersonaManager中通过get_persona_v3_by_id实现 v3 人格查找的集中化,包括对内存中的"default"人格和基于名称查找的支持。SubAgentOrchestrator,在加载子代理配置时使用处理后的 begin dialogs、深度拷贝人格对话定义,并规范化工具列表。测试:
SubAgentOrchestrator.reload_from_config添加单元测试,覆盖默认人格解析、缺失人格时的回退策略、begin_dialogs深拷贝行为以及工具规范化的边界情况。"default"。Original summary in English
Summary by Sourcery
Fix subagent persona resolution to correctly handle the special "default" persona identifier and improve subagent configuration behavior.
Bug Fixes:
Enhancements:
Tests: