From d7ca6e806531d85a8fc835d3a55f27e210cbd0dd Mon Sep 17 00:00:00 2001 From: chiguyong Date: Mon, 29 Jun 2026 21:58:40 +0800 Subject: [PATCH] fix(review): W1 ServerConfig from_dict wiring, W3 internal kwargs filter, N3 status docstring Code review fixes for Wave 1: - W1: ServerConfig.from_dict now wires prompt_cache/streaming/verification sections from YAML to constructor (previously these params existed but were never read) - W3: Tool._validate_input filters _-prefixed kwargs (e.g. _skip_dangerous_check) before jsonschema.validate, preventing additionalProperties:false schemas from rejecting internal control parameters - N3: ReActResult.status docstring now lists "empty_fallback" and "verify_failed" Added test test_internal_kwargs_underscore_prefixed_skipped_by_validation for W3. --- src/agentkit/core/react.py | 4 +++- src/agentkit/server/config.py | 8 ++++++++ src/agentkit/tools/base.py | 5 ++++- tests/unit/test_tool_schema_validation.py | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/agentkit/core/react.py b/src/agentkit/core/react.py index a5259b6..588bb75 100644 --- a/src/agentkit/core/react.py +++ b/src/agentkit/core/react.py @@ -119,7 +119,9 @@ class ReActResult: trajectory: list[ReActStep] total_steps: int total_tokens: int - status: str = "success" # "success" | "timeout" | "cancelled" | "partial" + status: str = ( + "success" # "success"|"timeout"|"cancelled"|"partial"|"empty_fallback"|"verify_failed" + ) fallback_strategy: str | None = None # e.g. "simplified_rewoo", "react", "direct" diff --git a/src/agentkit/server/config.py b/src/agentkit/server/config.py index b5b33da..1d67cf4 100644 --- a/src/agentkit/server/config.py +++ b/src/agentkit/server/config.py @@ -236,6 +236,11 @@ class ServerConfig: # Board meeting config (max_rounds, default_template, etc.) board_data = data.get("board", {}) + # U2/U3/U4: prompt_cache / streaming / verification 配置(从 YAML 读取) + prompt_cache_data = data.get("prompt_cache", {}) + streaming_data = data.get("streaming", {}) + verification_data = data.get("verification", {}) + return cls( host=server.get("host", "0.0.0.0"), port=server.get("port", 8001), @@ -263,6 +268,9 @@ class ServerConfig: evolution=evolution_data, expert_paths=expert_paths, board=board_data, + prompt_cache=prompt_cache_data, + streaming=streaming_data, + verification=verification_data, ) @staticmethod diff --git a/src/agentkit/tools/base.py b/src/agentkit/tools/base.py index 6829a2b..c54913e 100644 --- a/src/agentkit/tools/base.py +++ b/src/agentkit/tools/base.py @@ -108,8 +108,11 @@ class Tool(ABC): """ if self.input_schema is None: return + # 过滤内部 kwargs(下划线开头,如 _skip_dangerous_check),不参与 schema 校验 + # W3 fix: 防止 additionalProperties:false 的 schema 拒绝内部控制参数 + user_kwargs = {k: v for k, v in kwargs.items() if not k.startswith("_")} try: - jsonschema.validate(instance=kwargs, schema=self.input_schema) + jsonschema.validate(instance=user_kwargs, schema=self.input_schema) except jsonschema.ValidationError as e: field_path = ".".join(str(p) for p in e.absolute_path) or "" # required 缺失走 schema_mismatch;类型不符走 tool_call_invalid diff --git a/tests/unit/test_tool_schema_validation.py b/tests/unit/test_tool_schema_validation.py index f7b9e89..babbb0a 100644 --- a/tests/unit/test_tool_schema_validation.py +++ b/tests/unit/test_tool_schema_validation.py @@ -122,3 +122,19 @@ async def test_structured_error_dict_str_includes_error_code_for_llm_self_correc assert msg["role"] == "tool" assert msg["tool_call_id"] == "t1" assert "tool_call_invalid" in msg["content"] + + +# ---- W3 fix: 内部 kwargs(_前缀)不参与 schema 校验 ---- + + +async def test_internal_kwargs_underscore_prefixed_skipped_by_validation(): + """_skip_dangerous_check 等内部参数不参与 schema 校验。 + + 防止 additionalProperties:false 的 schema 拒绝内部控制参数(W3)。 + """ + tool = _StubTool(schema=_SCHEMA) # additionalProperties: False + # _skip_dangerous_check 是内部参数,不应被 schema 拒绝 + result = await tool.safe_execute(count=5, _skip_dangerous_check=True) + assert result == {"ok": True} + # execute 仍然收到完整 kwargs(内部参数透传给工具) + assert tool.calls == [{"count": 5, "_skip_dangerous_check": True}]