fix: pass persona skills to subagents#8121
fix: pass persona skills to subagents#8121he-yufeng wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
Agent.skillsfield is typed aslist[str] | Nonebut usesfield(default_factory=list), which means it will never beNoneby default; consider either changing the type tolist[str]or using aNonedefault to better distinguish betweenNoneand an empty list. - In
_build_handoff_system_prompt, concatenatinginstructionsand the skills prompt with fixed"\n"delimiters can easily produce extra leading/trailing blank lines; consider stripping the inputs or joining non-empty segments to normalize the final system prompt formatting.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `Agent.skills` field is typed as `list[str] | None` but uses `field(default_factory=list)`, which means it will never be `None` by default; consider either changing the type to `list[str]` or using a `None` default to better distinguish between `None` and an empty list.
- In `_build_handoff_system_prompt`, concatenating `instructions` and the skills prompt with fixed `"\n"` delimiters can easily produce extra leading/trailing blank lines; consider stripping the inputs or joining non-empty segments to normalize the final system prompt formatting.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a 'skills' system for sub-agents, allowing them to have specific capabilities beyond basic tools. It updates the Agent model, the handoff execution logic to include skill-based prompts in the system message, and the orchestrator to handle skill configuration. Feedback suggests improving the system prompt construction to avoid formatting issues and refining the skill list normalization to prevent None values from being converted to strings.
| system_prompt = instructions or "" | ||
| skills_prompt = cls._build_handoff_skills_prompt(skill_names, runtime) | ||
| if skills_prompt: | ||
| system_prompt += f"\n{skills_prompt}\n" | ||
| return system_prompt |
There was a problem hiding this comment.
The construction of the system prompt can lead to leading or trailing newlines if instructions is empty or skills_prompt is present. It's generally cleaner to join the prompt parts with double newlines to clearly separate sections for the LLM.
prompt_parts = []
if instructions:
prompt_parts.append(instructions.strip())
skills_prompt = cls._build_handoff_skills_prompt(skill_names, runtime)
if skills_prompt:
prompt_parts.append(skills_prompt.strip())
return "\n\n".join(prompt_parts)| elif not isinstance(skills, list): | ||
| skills = [] | ||
| else: | ||
| skills = [str(s).strip() for s in skills if str(s).strip()] |
There was a problem hiding this comment.
The list comprehension str(s).strip() will convert None values in the skills list to the string "None". It's safer to filter out non-truthy values before converting to string.
| skills = [str(s).strip() for s in skills if str(s).strip()] | |
| skills = [str(s).strip() for s in skills if s and str(s).strip()] |
Summary
Addresses the subagent skill-loading part of #8099. The duplicate-message behavior reported there is separate and not changed here.
To verify
python -m py_compile astrbot\core\agent\agent.py astrbot\core\subagent_orchestrator.py astrbot\core\astr_agent_tool_exec.py tests\unit\test_subagent_orchestrator.py tests\unit\test_astr_agent_tool_exec.pypython -m pytest tests\unit\test_subagent_orchestrator.py tests\unit\test_astr_agent_tool_exec.py::test_build_handoff_skills_prompt_filters_selected_skills tests\unit\test_astr_agent_tool_exec.py::test_execute_handoff_appends_agent_skills_prompt -qpython -m ruff check astrbot\core\agent\agent.py astrbot\core\subagent_orchestrator.py astrbot\core\astr_agent_tool_exec.py tests\unit\test_subagent_orchestrator.py tests\unit\test_astr_agent_tool_exec.pygit diff --checkSummary by Sourcery
Propagate persona-defined skills to subagent handoffs and include the corresponding skills prompt in subagent executions.
New Features:
Bug Fixes:
Tests: