mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-25 11:37:13 +00:00
fix(agent): harden runner delivery validation
This commit is contained in:
@@ -3,6 +3,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
|
||||
_INVALID_TOOL_ARGUMENT_PATTERN = re.compile(
|
||||
r"invalid json arguments|\b\d+\s+validation errors?\s+for\s+[A-Za-z_][A-Za-z0-9_]*Args\b",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
def load_ledger_json(value: str | None, *, field: str, failures: list[dict]) -> object:
|
||||
@@ -16,6 +23,12 @@ def load_ledger_json(value: str | None, *, field: str, failures: list[dict]) ->
|
||||
return {}
|
||||
|
||||
|
||||
def invalid_tool_argument_error_signal(value: str) -> str:
|
||||
"""Return the persisted signal for malformed model-supplied tool arguments."""
|
||||
match = _INVALID_TOOL_ARGUMENT_PATTERN.search(value)
|
||||
return match.group(0) if match else ""
|
||||
|
||||
|
||||
def classify_invalid_tool_argument_errors(
|
||||
events: list[dict],
|
||||
*,
|
||||
@@ -41,3 +54,25 @@ def classify_invalid_tool_argument_errors(
|
||||
else:
|
||||
failures.append(event)
|
||||
return failures, warnings
|
||||
|
||||
|
||||
def classify_tool_authorization(
|
||||
calls: list[dict],
|
||||
*,
|
||||
authorization_mode: str,
|
||||
) -> tuple[list[dict], list[dict]]:
|
||||
"""Classify tool names absent from the Host authorization snapshot."""
|
||||
if not calls:
|
||||
return [], []
|
||||
if authorization_mode == "runner-native":
|
||||
return [], [
|
||||
{
|
||||
"kind": "runner_native_tool_calls",
|
||||
"calls": calls,
|
||||
"reason": (
|
||||
"External runner tool telemetry is not a LangBot Host tool call; "
|
||||
"the runner's own permission system governs it."
|
||||
),
|
||||
}
|
||||
]
|
||||
return [{"kind": "unauthorized_tool_calls", "calls": calls}], []
|
||||
|
||||
Reference in New Issue
Block a user