-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(core): enforce persona tool boundaries #8786
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -817,6 +817,57 @@ async def test_ensure_tools_from_persona(self, mock_event, mock_context): | |||||
|
|
||||||
| assert req.func_tool is not None | ||||||
|
|
||||||
| @pytest.mark.asyncio | ||||||
| async def test_persona_empty_tools_filters_late_builtin_tools( | ||||||
| self, mock_event, mock_context, mock_provider | ||||||
| ): | ||||||
| module = ama | ||||||
| persona = {"name": "locked", "prompt": "No tools.", "tools": []} | ||||||
| mock_context.persona_manager.resolve_selected_persona = AsyncMock( | ||||||
| return_value=("locked", persona, None, False) | ||||||
| ) | ||||||
| mock_context.get_config.return_value = { | ||||||
| "provider_settings": { | ||||||
| "web_search": True, | ||||||
| "websearch_provider": "baidu_ai_search", | ||||||
| } | ||||||
| } | ||||||
| config = module.MainAgentBuildConfig( | ||||||
| tool_call_timeout=60, | ||||||
| provider_settings={ | ||||||
| "web_search": True, | ||||||
| "websearch_provider": "baidu_ai_search", | ||||||
| }, | ||||||
| computer_use_runtime="none", | ||||||
| ) | ||||||
| req = ProviderRequest(prompt="hello") | ||||||
| req.conversation = MagicMock(persona_id="locked", history="[]") | ||||||
|
|
||||||
| with ( | ||||||
| patch("astrbot.core.astr_main_agent.AgentRunner") as mock_runner_cls, | ||||||
| patch("astrbot.core.astr_main_agent.AstrAgentContext"), | ||||||
| ): | ||||||
| mock_runner = MagicMock() | ||||||
| mock_runner.reset = AsyncMock() | ||||||
| mock_runner_cls.return_value = mock_runner | ||||||
|
|
||||||
| result = await module.build_main_agent( | ||||||
| event=mock_event, | ||||||
| plugin_context=mock_context, | ||||||
| config=config, | ||||||
| provider=mock_provider, | ||||||
| req=req, | ||||||
| apply_reset=False, | ||||||
| ) | ||||||
| assert result is not None | ||||||
| try: | ||||||
| assert result.provider_request.func_tool is None or ( | ||||||
| result.provider_request.func_tool.empty() | ||||||
| ) | ||||||
| finally: | ||||||
| if result.reset_coro: | ||||||
|
Contributor
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. If
Suggested change
|
||||||
| result.reset_coro.close() | ||||||
|
|
||||||
| @pytest.mark.asyncio | ||||||
| async def test_subagent_dedupe_uses_default_persona_tools( | ||||||
| self, mock_event, mock_context | ||||||
|
|
||||||
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.
Instead of iterating over the tools and calling$O(N^2)$ complexity), you can filter the $O(N)$ pass.
remove_tool(which performs a list comprehension internally on every call, leading totoolslist in-place in a single