mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 17:38:35 +00:00
权限错误要打断循环
This commit is contained in:
parent
2b455b1e14
commit
f19d767b0f
@ -791,6 +791,17 @@ class AgentRunner:
|
|||||||
"status": "error",
|
"status": "error",
|
||||||
"detail": result.replace("\n", " ").strip()[:120],
|
"detail": result.replace("\n", " ").strip()[:120],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# check the outside workspace error and break loop
|
||||||
|
if self._is_workspace_violation(result):
|
||||||
|
logger.warning(
|
||||||
|
"Tool {} blocked by workspace/safety guard; aborting turn: {}",
|
||||||
|
tool_call.name,
|
||||||
|
result.replace("\n", " ").strip()[:200],
|
||||||
|
)
|
||||||
|
event["detail"] = ("workspace_violation: "
|
||||||
|
+ result.replace("\n", " ").strip())[:160]
|
||||||
|
return result, event, RuntimeError(result)
|
||||||
if spec.fail_on_tool_error:
|
if spec.fail_on_tool_error:
|
||||||
return result + hint, event, RuntimeError(result)
|
return result + hint, event, RuntimeError(result)
|
||||||
return result + hint, event, None
|
return result + hint, event, None
|
||||||
@ -803,6 +814,24 @@ class AgentRunner:
|
|||||||
detail = detail[:120] + "..."
|
detail = detail[:120] + "..."
|
||||||
return result, {"name": tool_call.name, "status": "ok", "detail": detail}, None
|
return result, {"name": tool_call.name, "status": "ok", "detail": detail}, None
|
||||||
|
|
||||||
|
# Markers identifying tool results that represent a workspace / safety boundary rejection.
|
||||||
|
_WORKSPACE_BLOCK_MARKERS: tuple[str, ...] = (
|
||||||
|
"blocked by safety guard",
|
||||||
|
"outside the configured workspace",
|
||||||
|
"outside allowed directory",
|
||||||
|
"working_dir is outside",
|
||||||
|
"working_dir could not be resolved",
|
||||||
|
"path traversal detected",
|
||||||
|
"path outside working dir",
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _is_workspace_violation(cls, text: str) -> bool:
|
||||||
|
if not text:
|
||||||
|
return False
|
||||||
|
lowered = text.lower()
|
||||||
|
return any(marker in lowered for marker in cls._WORKSPACE_BLOCK_MARKERS)
|
||||||
|
|
||||||
async def _emit_checkpoint(
|
async def _emit_checkpoint(
|
||||||
self,
|
self,
|
||||||
spec: AgentRunSpec,
|
spec: AgentRunSpec,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user