fix: preserve tool failures under noisy output
This commit is contained in:
@@ -19,6 +19,7 @@ from docker.errors import ImageNotFound, NotFound
|
||||
import docker
|
||||
from agent_platform.config import Settings
|
||||
from agent_platform.gateway.schemas import ToolResult, WorkspaceListing, WorkspaceStatus
|
||||
from agent_platform.text import truncate_middle
|
||||
|
||||
|
||||
def normalize_workspace_path(raw_path: str) -> PurePosixPath:
|
||||
@@ -208,7 +209,7 @@ class DockerExecutionProvider:
|
||||
output = ((stdout or b"") + (stderr or b"")).decode("utf-8", errors="replace")
|
||||
truncated = len(output) > max_output
|
||||
if truncated:
|
||||
output = output[:max_output] + "\n… output truncated …"
|
||||
output = truncate_middle(output, max_output, "\n… output truncated; middle omitted …\n")
|
||||
return ToolResult(
|
||||
ok=result.exit_code == 0,
|
||||
output=output,
|
||||
|
||||
@@ -77,6 +77,7 @@ VERIFICATION_TOOLS = {"read_file", "git_status", "git_diff", "exec", "poll_proce
|
||||
EXECUTION_TOOLS = {"exec", "start_process", "poll_process"}
|
||||
REPEAT_GUARDED_EXECUTION_TOOLS = {"exec", "start_process"}
|
||||
MAX_CONSECUTIVE_CHECKPOINT_REJECTIONS = 3
|
||||
MAX_TOOL_CALLS_PER_ITERATION = 8
|
||||
CODE_FILE_SUFFIXES = {
|
||||
".c",
|
||||
".cc",
|
||||
@@ -568,6 +569,17 @@ class AgentLoop:
|
||||
)
|
||||
return candidate
|
||||
|
||||
if len(tool_calls) > MAX_TOOL_CALLS_PER_ITERATION:
|
||||
await recorder.emit(
|
||||
"tool.batch_limited",
|
||||
{
|
||||
"requested": len(tool_calls),
|
||||
"accepted": MAX_TOOL_CALLS_PER_ITERATION,
|
||||
"iteration": iteration + 1,
|
||||
"depth": depth,
|
||||
},
|
||||
)
|
||||
tool_calls = tool_calls[:MAX_TOOL_CALLS_PER_ITERATION]
|
||||
consecutive_checkpoint_rejections = 0
|
||||
assistant_message = {
|
||||
"role": "assistant",
|
||||
|
||||
@@ -10,6 +10,7 @@ from agent_platform.auth import UserIdentity
|
||||
from agent_platform.config import Settings
|
||||
from agent_platform.runtime.schemas import PlanItem
|
||||
from agent_platform.store import RuntimeStore
|
||||
from agent_platform.text import truncate_middle
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@@ -337,6 +338,4 @@ class ToolRegistry:
|
||||
|
||||
def tool_result_text(result: Any, limit: int) -> str:
|
||||
text = json.dumps(result, ensure_ascii=False, separators=(",", ":"), default=str)
|
||||
if len(text) <= limit:
|
||||
return text
|
||||
return text[:limit] + "…"
|
||||
return truncate_middle(text, limit)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def truncate_middle(text: str, limit: int, marker: str = "\n… middle omitted …\n") -> str:
|
||||
if limit <= 0:
|
||||
return ""
|
||||
if len(text) <= limit:
|
||||
return text
|
||||
if limit <= len(marker):
|
||||
return text[:limit]
|
||||
remaining = limit - len(marker)
|
||||
head = (remaining + 1) // 2
|
||||
tail = remaining - head
|
||||
suffix = text[-tail:] if tail else ""
|
||||
return text[:head] + marker + suffix
|
||||
Reference in New Issue
Block a user