feat(box): expand agent tool capabilities with files, web, and service ops

This commit is contained in:
operator
2026-10-05 03:51:43 +00:00
parent 581bbfe3b4
commit 2132d15cb4
4 changed files with 379 additions and 1 deletions
+33
View File
@@ -227,6 +227,39 @@ def format_tool_result_for_chat(op, raw_output):
if op == "vars.get" and isinstance(data, dict):
return f"{data.get('name')} = {data.get('value')}"
if op == "files.read" and isinstance(data, dict):
if not data.get("ok"):
return f"Failed to read file: {data.get('error')}"
path = data.get("path")
lines = data.get("lines")
trunc = " (first " + str(data.get("displayed_lines")) + " lines)" if data.get("truncated") else ""
content = data.get("content", "").strip()
return f"File `{path}` ({lines} lines total){trunc}:\n```\n{content}\n```"
if op == "files.write" and isinstance(data, dict):
if not data.get("ok"):
return f"Failed to write file: {data.get('error')}"
return f"File `{data.get('path')}` written successfully ({data.get('bytes_written')} bytes, {data.get('lines')} lines)."
if op == "web.fetch" and isinstance(data, dict):
if not data.get("ok"):
return f"Failed to fetch {data.get('url')}: {data.get('error')}"
status = data.get("status")
url = data.get("url")
trunc = " (truncated to 4KB)" if data.get("truncated") else ""
return f"Web Fetch `{url}` (HTTP {status}){trunc}:\n```\n{data.get('body', '').strip()[:800]}\n```"
if op == "service.status" and isinstance(data, dict):
if not data.get("ok"):
return f"Service check failed: {data.get('error')}"
st = "ACTIVE" if data.get("active") else "INACTIVE"
return f"Service `{data.get('service')}` is {st}.\nStatus: {data.get('status_line')}"
if op == "service.restart" and isinstance(data, dict):
if not data.get("ok"):
return f"Service restart failed for `{data.get('service')}`: {data.get('error')}"
return f"Service `{data.get('service')}` restarted successfully."
# General fallback: compact JSON capped to 400 chars
s = json.dumps(data)
return s[:400] + "..." if len(s) > 400 else s