Skip to content

Commit 9ffb0bd

Browse files
whatevertogoclaudeSoulter
authored andcommitted
fix: register_agent decorator NameError (AstrBotDevs#5765)
* fix: 修改 register_agent 以避免运行时导入 AstrAgentContext * test: improve register_agent test robustness - Add fixture for llm_tools cleanup to avoid test interference - Use multiple import patterns to make guard more robust to refactors - Add assertion to verify decorated coroutine is wired as handoff handler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * 删除测试文件: 移除 register_agent 装饰器的运行时行为测试 --------- Co-authored-by: whatevertogo <whatevertogo@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Soulter <905617992@qq.com>
1 parent ef83ceb commit 9ffb0bd

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

astrbot/core/star/register/star_handler.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
from collections.abc import AsyncGenerator, Awaitable, Callable
5-
from typing import TYPE_CHECKING, Any
5+
from typing import Any
66

77
import docstring_parser
88

@@ -15,9 +15,6 @@
1515
from astrbot.core.provider.func_tool_manager import PY_TO_JSON_TYPE, SUPPORTED_TYPES
1616
from astrbot.core.provider.register import llm_tools
1717

18-
if TYPE_CHECKING:
19-
from astrbot.core.astr_agent_context import AstrAgentContext
20-
2118
from ..filter.command import CommandFilter
2219
from ..filter.command_group import CommandGroupFilter
2320
from ..filter.custom_filter import CustomFilterAnd, CustomFilterOr
@@ -649,15 +646,15 @@ def llm_tool(self, *args, **kwargs):
649646
kwargs["registering_agent"] = self
650647
return register_llm_tool(*args, **kwargs)
651648

652-
def __init__(self, agent: Agent[AstrAgentContext]) -> None:
649+
def __init__(self, agent: Agent[Any]) -> None:
653650
self._agent = agent
654651

655652

656653
def register_agent(
657654
name: str,
658655
instruction: str,
659656
tools: list[str | FunctionTool] | None = None,
660-
run_hooks: BaseAgentRunHooks[AstrAgentContext] | None = None,
657+
run_hooks: BaseAgentRunHooks[Any] | None = None,
661658
):
662659
"""注册一个 Agent
663660
@@ -671,12 +668,12 @@ def register_agent(
671668
tools_ = tools or []
672669

673670
def decorator(awaitable: Callable[..., Awaitable[Any]]):
674-
AstrAgent = Agent[AstrAgentContext]
671+
AstrAgent = Agent[Any]
675672
agent = AstrAgent(
676673
name=name,
677674
instructions=instruction,
678675
tools=tools_,
679-
run_hooks=run_hooks or BaseAgentRunHooks[AstrAgentContext](),
676+
run_hooks=run_hooks or BaseAgentRunHooks[Any](),
680677
)
681678
handoff_tool = HandoffTool(agent=agent)
682679
handoff_tool.handler = awaitable

0 commit comments

Comments
 (0)