Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
969ef22f99 | ||
|
|
4674889c0f |
@@ -1,29 +0,0 @@
|
||||
# Phase 3: Poka-yoke Integration & Fleet Verification
|
||||
|
||||
Epic #967. Morning review packet for Hermes harness features.
|
||||
|
||||
## Poka-yoke Features Implemented
|
||||
|
||||
| Feature | Module | PR | Status |
|
||||
|---------|--------|-----|--------|
|
||||
| Token budget tracker | agent/token_budget.py | #930 | MERGED |
|
||||
| Provider preflight validation | agent/provider_preflight.py | #932 | MERGED |
|
||||
| Atomic skill editing | tools/skill_edit_guard.py | #933 | MERGED |
|
||||
| Config debt fixes | gateway/config.py | #437 | MERGED |
|
||||
| Test collection fixes | tests/acp/conftest.py | #794 | MERGED |
|
||||
| Context-faithful prompting | agent/context_faithful.py | #786 | MERGED |
|
||||
|
||||
## Fleet Verification
|
||||
|
||||
- Unit tests pass on all modules
|
||||
- Collection: 11,472 tests, 0 errors (was 6 errors)
|
||||
- ACP tests: cleanly skipped when acp extra missing
|
||||
- Provider validation: catches missing/short keys
|
||||
- Skill editing: atomic with auto-revert
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. Wire token_budget into run_agent.py conversation loop
|
||||
2. Wire provider_preflight into session start
|
||||
3. Wire skill_edit_guard into skill_manage tool
|
||||
4. Fleet-wide deployment verification
|
||||
@@ -26,6 +26,28 @@ class TestHandleFunctionCall:
|
||||
assert "error" in result
|
||||
assert "agent loop" in result["error"].lower()
|
||||
|
||||
def test_invalid_tool_returns_structured_pokayoke_error_with_suggestion(self):
|
||||
result = json.loads(handle_function_call("broswer_type", {"ref": "@e1"}))
|
||||
assert result["pokayoke"] is True
|
||||
assert result["tool_name"] == "broswer_type"
|
||||
assert "Did you mean" in result["error"]
|
||||
|
||||
def test_parameter_typo_is_autocorrected_before_dispatch(self, monkeypatch):
|
||||
captured = {}
|
||||
|
||||
def fake_dispatch(name, args, **kwargs):
|
||||
captured["name"] = name
|
||||
captured["args"] = args
|
||||
return json.dumps({"ok": True})
|
||||
|
||||
monkeypatch.setattr("model_tools.registry.dispatch", fake_dispatch)
|
||||
|
||||
result = json.loads(handle_function_call("read_file", {"pathe": "test.txt"}))
|
||||
assert result == {"ok": True}
|
||||
assert captured["name"] == "read_file"
|
||||
assert captured["args"]["path"] == "test.txt"
|
||||
assert "pathe" not in captured["args"]
|
||||
|
||||
def test_unknown_tool_returns_error(self):
|
||||
result = json.loads(handle_function_call("totally_fake_tool_xyz", {}))
|
||||
assert "error" in result
|
||||
|
||||
@@ -114,8 +114,9 @@ class TestToolCallValidator:
|
||||
assert len(msgs) == 0
|
||||
|
||||
def test_invalid_tool_suggests(self, validator):
|
||||
is_valid, corrected, params, msgs = validator.validate("browser_typo", {"ref": "@e1"})
|
||||
is_valid, corrected, params, msgs = validator.validate("broswer_type", {"ref": "@e1"})
|
||||
assert is_valid is False
|
||||
assert corrected is None
|
||||
assert "browser_type" in str(msgs)
|
||||
|
||||
def test_auto_correct_tool_name(self, validator):
|
||||
@@ -130,12 +131,10 @@ class TestToolCallValidator:
|
||||
assert "ref" in params
|
||||
assert any("reff" in m and "ref" in m for m in msgs)
|
||||
|
||||
def test_circuit_breaker(self, validator):
|
||||
# Fail 3 times
|
||||
for _ in range(3):
|
||||
validator.validate("nonexistent_tool", {})
|
||||
|
||||
# 4th attempt should trigger circuit breaker
|
||||
def test_circuit_breaker_triggers_on_third_consecutive_failure(self, validator):
|
||||
validator.validate("nonexistent_tool", {})
|
||||
validator.validate("nonexistent_tool", {})
|
||||
|
||||
is_valid, corrected, params, msgs = validator.validate("nonexistent_tool", {})
|
||||
assert is_valid is False
|
||||
assert any("CIRCUIT BREAKER" in m for m in msgs)
|
||||
|
||||
@@ -182,7 +182,10 @@ class ToolCallValidator:
|
||||
name_valid, corrected_name, name_messages = self.validate_tool_name(tool_name)
|
||||
|
||||
if not name_valid:
|
||||
self._record_failure(tool_name)
|
||||
failure_count = self._record_failure(tool_name)
|
||||
if failure_count >= self.failure_threshold:
|
||||
_, _, breaker_messages = self.validate_tool_name(tool_name)
|
||||
return False, None, params, breaker_messages
|
||||
return False, None, params, name_messages
|
||||
|
||||
# Use corrected name if provided
|
||||
@@ -199,8 +202,8 @@ class ToolCallValidator:
|
||||
all_messages = name_messages + param_warnings
|
||||
return True, corrected_name, corrected_params, all_messages
|
||||
|
||||
def _record_failure(self, tool_name: str):
|
||||
"""Record a failure for circuit breaker."""
|
||||
def _record_failure(self, tool_name: str) -> int:
|
||||
"""Record a failure for circuit breaker and return the new count."""
|
||||
self.consecutive_failures[tool_name] = self.consecutive_failures.get(tool_name, 0) + 1
|
||||
count = self.consecutive_failures[tool_name]
|
||||
|
||||
@@ -209,10 +212,12 @@ class ToolCallValidator:
|
||||
f"Poka-yoke circuit breaker triggered for '{tool_name}': "
|
||||
f"{count} consecutive failures"
|
||||
)
|
||||
return count
|
||||
|
||||
def _record_success(self, tool_name: str):
|
||||
"""Record a success (reset failure counter)."""
|
||||
self.consecutive_failures.pop(tool_name, None)
|
||||
"""Record a success (reset consecutive failure streaks)."""
|
||||
if self.consecutive_failures:
|
||||
self.consecutive_failures.clear()
|
||||
|
||||
def get_diagnostic_message(self, tool_name: str) -> str:
|
||||
"""Generate diagnostic message for circuit breaker."""
|
||||
|
||||
Reference in New Issue
Block a user