The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): block pruned content before effectful dispatch
Kevin Rajance2a747be972
diff --git a/agent/tool_executor.py b/agent/tool_executor.pyindex 7265d18a244..fe3430b2ab4 100644--- a/agent/tool_executor.py+++ b/agent/tool_executor.py@@ -44,6 +44,7 @@ from agent.tool_dispatch_helpers import (_is_multimodal_tool_result,_multimodal_text_summary,_append_subdir_hint_to_multimodal,+ _context_pruned_argument_paths,_plan_tool_batch_segments,make_tool_result_message,)@@ -635,11 +636,38 @@ def _run_with_activity_heartbeat(agent, function_name: str, fn):thread.join(timeout=2.0)-def _blocked_tool_result(agent, ref: _ToolCallRef, *, block_message: Optional[str], block_error_type: str, guardrail_decision) -> str:- """Synthesize the result for a call blocked by scope/plugin (``block_message``) or by- guardrail policy (``guardrail_decision``) and emit its terminal post_tool_call."""+_PRUNED_TOOL_ARGUMENTS_ERROR = "suspected_pruned_tool_arguments"+_PRUNED_TOOL_ARGUMENTS_MESSAGE = (+ "Tool was not executed because effect-capable arguments contain a Hermes context-compression artifact. "+ "Recover the exact content from its durable source or re-read it, then issue a complete new call; "+ "do not retry these arguments."+)+++def _pruned_tool_arguments_block(function_name: str, function_args: dict[str, Any]) -> dict[str, Any] | None:+ paths = _context_pruned_argument_paths(function_name, function_args)+ if not paths:+ return None+ return {+ "error": _PRUNED_TOOL_ARGUMENTS_ERROR,+ "message": _PRUNED_TOOL_ARGUMENTS_MESSAGE,+ "argument_paths": paths,+ }+++def _blocked_tool_result(+ agent,+ ref: _ToolCallRef,+ *,+ block_message: Optional[str],+ block_error_type: str,+ guardrail_decision,+ block_payload: dict[str, Any] | None = None,+) -> str:+ """Synthesize a blocked tool result and emit its terminal post_tool_call."""if block_message is not None:- result, error_type, error_message = json.dumps({"error": block_message}, ensure_ascii=False), block_error_type, block_message+ result = json.dumps(block_payload or {"error": block_message}, ensure_ascii=False)+ error_type, error_message = block_error_type, block_messageelse:result = agent._guardrail_block_result(guardrail_decision)error_type = "guardrail_block"@@ -689,12 +717,27 @@ def _dispatch_authorized_once(callback()block_message, block_error_type = scope_block, "tool_scope_block"+ block_payload = None+ if block_message is None:+ block_payload = _pruned_tool_arguments_block(ref.name, ref.args)+ if block_payload is not None:+ block_message = block_payload["message"]+ block_error_type = _PRUNED_TOOL_ARGUMENTS_ERROR+if block_message is None:block_error_type = "plugin_block"resolve = lambda: _pre_tool_block(agent, ref) # noqa: E731block_message, ref.args = resolve() if authorization_gate is None else authorization_gate.run(resolve)state.args = ref.args+ # Plugin modify hooks are allowed to replace arguments, so enforce the same+ # provenance boundary on their output before guardrails or real dispatch.+ if block_message is None:+ block_payload = _pruned_tool_arguments_block(ref.name, ref.args)+ if block_payload is not None:+ block_message = block_payload["message"]+ block_error_type = _PRUNED_TOOL_ARGUMENTS_ERROR+guardrail_decision = Noneif block_message is None:guardrail_decision = agent._tool_guardrails.before_call(ref.name, ref.args)@@ -705,8 +748,12 @@ def _dispatch_authorized_once(_advance_start_order()state.blocked = Truereturn _blocked_tool_result(- agent, ref,- block_message=block_message, block_error_type=block_error_type, guardrail_decision=guardrail_decision,+ agent,+ ref,+ block_message=block_message,+ block_error_type=block_error_type,+ guardrail_decision=guardrail_decision,+ block_payload=block_payload,)if ref.name == "memory":