Repository navigation
fix(agent): 让 BaseAgent 的构图契约在实例化期生效 - #1141
Merged
xerrors merged 1 commit intoNov 3, 2026
Merged
Conversation
BaseAgent 未继承 ABC,@AbstractMethod 只写入 __isabstractmethod__, 没有 ABCMeta 在实例化时检查;漏实现 get_graph 的子类仍能创建, 失败被推迟到构图后访问 None.astream_events。 改为继承 ABC,与模型、知识库、解析器等基类保持一致;新增负向测试 断言不完整子类在实例化时抛出 TypeError,并记录对应决策。
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
变更说明
bug-fixBaseAgent上的@abstractmethod get_graph在实例化期真正生效,漏实现的后端类无法被创建。get_graph的返回值契约,不改变AGENT_BACKENDS的注册方式,不把构图错误转换成领域错误。TypeError提前暴露”的取舍,按implemented决策记录直接落地,不需要 proposal 阶段。工程主张与 Owner
get_graph的BaseAgent子类无法实例化;错误出现在get_agent_backend/list_agent_backend_info的创建点(TypeError),而不是构图后访问None.astream_events。get_graph的后端(当前只有ChatbotAgent)与全部测试后端行为不变。backend/yuxi/modules/agents/runtime/base.py拥有,检查由ABCMeta在实例化时触发。本变更不写持久状态,没有 commit point。docs/develop-guides/decisions/implemented/2026-11-03-base-agent-abstract-contract.md)验证情况
漏实现 get_graph 的子类无法实例化
BaseAgent仍是普通类时装饰器不生效,子类可以实例化,错误推迟到构图backend/yuxi/modules/agents/runtime/base.pypytest test/unit/agents/test_base_agent_contract.py -q→ 1 passedclass BaseAgent(ABC)还原为class BaseAgent:后,同一测试以DID NOT RAISE失败(Reviewer 用真实源码在容器内复现)已有后端与测试后端不受影响
ABC后误伤合法子类backend/yuxi/modules/agents/runtime/agent_backends/__init__.pypytest test/unit -m "not slow" -q→ 3530 passed, 126 skipped, 0 failedChatbotAgent无法实例化,test_builtin_discovery.py、test_base_agent_langfuse_config.py会失败仓库其它抽象基类没有同类遗漏
@abstractmethod@abstractmethod,其余 5 处均继承ABC工程契约与格式检查:
简化 / 删除验收
不涉及。
独立语义 Review
由不继承实现上下文的全新 Reviewer 覆盖需求、完整 diff、
base.py的全部子类与 consumer、负向测试变异路径、文档与测试证据。结论为 Approve with changes:阻塞项是缺少 decision record(已补),非阻塞建议是收紧测试断言(已改为match=r"abstract method 'get_graph'")。无未解决项。未验证范围与风险
os.O_DIRECTORY、fcntl等 POSIX 接口),后端测试全部在 Linux 容器ghcr.io/astral-sh/uv:python3.13-bookworm中执行,未在docker compose的 api 镜像内重跑。get_graph,升级后会在实例化或后端信息查询阶段提前抛出TypeError;该错误不会映射为AgentBackendNotFoundError。ABC只保证get_graph存在,不保证返回已编译的图;返回None的子类仍会在构图调用处失败。pnpm run build通过(vitepress 1.6.4,build complete in 27.20s)。事故反馈
不涉及。该缺陷未造成高影响逃逸,未达到 postmortem 门槛。
界面变更
不涉及。
关联事项
无。
补充说明
BaseAgent自身不再可实例化,这是有意的契约表达。