Skip to content

fix: pass persona skills to subagents#8121

Open
he-yufeng wants to merge 2 commits intoAstrBotDevs:masterfrom
he-yufeng:fix/subagent-persona-skills
Open

fix: pass persona skills to subagents#8121
he-yufeng wants to merge 2 commits intoAstrBotDevs:masterfrom
he-yufeng:fix/subagent-persona-skills

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

@he-yufeng he-yufeng commented May 9, 2026

Summary

  • carry persona skill selections into subagent handoff definitions
  • append the selected skill prompt when running the subagent handoff
  • keep inline subagents without selected skills unchanged

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.py
  • python -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 -q
  • python -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.py
  • git diff --check

Summary by Sourcery

Propagate persona-defined skills to subagent handoffs and include the corresponding skills prompt in subagent executions.

New Features:

  • Support associating skills with agents and subagents via the Agent model and subagent orchestrator configuration.
  • Generate and append a skills-based system prompt segment when executing subagent handoffs, based on the subagent's selected skills.

Bug Fixes:

  • Ensure subagent persona skills are correctly carried through from persona configuration into handoff agent definitions.

Tests:

  • Add unit tests covering subagent skill normalization from config, skills propagation into handoff agents, and skills prompt construction and usage during handoff execution.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. feature:persona The bug / feature is about astrbot AI persona system (system prompt) labels May 9, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread astrbot/core/astr_agent_tool_exec.py Outdated
Comment on lines +303 to +307
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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()]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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()]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. feature:persona The bug / feature is about astrbot AI persona system (system prompt) size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant