-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat:增加用户在webui创建和配置subagent的功能 #4697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
advent259141
wants to merge
7
commits into
AstrBotDevs:master
Choose a base branch
from
advent259141:Astrbot_skill
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6b39717
增加subagent编排功能
advent259141 6d47663
修复了一些已知问题
advent259141 3cf0880
修复bug,优化前端页面
advent259141 c3e4a52
修复格式
advent259141 b3a1f4c
再次修复格式
advent259141 1bd8eae
按照comment进行一些小改动
advent259141 053c4e9
优化tool选择的下拉框:根据插件分组
advent259141 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感觉相关逻辑可以直接放到 tool_manager 里面,用一个方法代替。 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from astrbot import logger | ||
| from astrbot.core.agent.agent import Agent | ||
| from astrbot.core.agent.handoff import HandoffTool | ||
| from astrbot.core.astr_agent_context import AstrAgentContext | ||
| from astrbot.core.provider.func_tool_manager import FunctionToolManager | ||
|
|
||
|
|
||
| class SubAgentOrchestrator: | ||
| """Loads subagent definitions from config and registers handoff tools. | ||
|
|
||
| This is intentionally lightweight: it does not execute agents itself. | ||
| Execution happens via HandoffTool in FunctionToolExecutor. | ||
| """ | ||
|
|
||
| def __init__(self, tool_mgr: FunctionToolManager): | ||
| self._tool_mgr = tool_mgr | ||
|
|
||
| def reload_from_config(self, cfg: dict[str, Any]) -> None: | ||
| enabled = bool(cfg.get("main_enable", False)) | ||
|
|
||
| if not enabled: | ||
| # Ensure any previous dynamic handoff tools are cleared. | ||
| self._tool_mgr.sync_dynamic_handoff_tools( | ||
| [], | ||
| handler_module_path="core.subagent_orchestrator", | ||
| ) | ||
| return | ||
|
|
||
| agents = cfg.get("agents", []) | ||
| if not isinstance(agents, list): | ||
| logger.warning("subagent_orchestrator.agents must be a list") | ||
| return | ||
|
|
||
| handoffs: list[HandoffTool] = [] | ||
| for item in agents: | ||
| if not isinstance(item, dict): | ||
| continue | ||
| if not item.get("enabled", True): | ||
| continue | ||
|
|
||
| name = str(item.get("name", "")).strip() | ||
| if not name: | ||
| continue | ||
|
|
||
| instructions = str(item.get("system_prompt", "")).strip() | ||
| public_description = str(item.get("public_description", "")).strip() | ||
| provider_id = item.get("provider_id") | ||
| if provider_id is not None: | ||
| provider_id = str(provider_id).strip() or None | ||
| tools = item.get("tools", []) | ||
| if not isinstance(tools, list): | ||
| tools = [] | ||
| tools = [str(t).strip() for t in tools if str(t).strip()] | ||
|
|
||
| agent = Agent[AstrAgentContext]( | ||
| name=name, | ||
| instructions=instructions, | ||
| tools=tools, | ||
| ) | ||
| # The tool description should be a short description for the main LLM, | ||
| # while the subagent system prompt can be longer/more specific. | ||
| handoff = HandoffTool( | ||
| agent=agent, | ||
| tool_description=public_description or None, | ||
| ) | ||
|
|
||
| # Optional per-subagent chat provider override. | ||
| handoff.provider_id = provider_id | ||
|
|
||
| handoffs.append(handoff) | ||
|
|
||
| self._tool_mgr.sync_dynamic_handoff_tools( | ||
| handoffs, | ||
| handler_module_path="core.subagent_orchestrator", | ||
| ) | ||
|
|
||
| for handoff in handoffs: | ||
| logger.info(f"Registered subagent handoff tool: {handoff.name}") |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里直接这样改吧: