diff --git a/docs/architecture/TOOL-GATEWAY-ENFORCEMENT.md b/docs/architecture/TOOL-GATEWAY-ENFORCEMENT.md index dafda56..11a238c 100644 --- a/docs/architecture/TOOL-GATEWAY-ENFORCEMENT.md +++ b/docs/architecture/TOOL-GATEWAY-ENFORCEMENT.md @@ -10,14 +10,23 @@ - остальное — `REJECT`; - агент запускается как `agent-gw` и ходит только через Tool Gateway. -## Проверка +## Production-style agent ```text -runuser -u agent-gw -- python3 /opt/agent-gw/agent.py -gateway_agent_ok catalog.read 6884 +agent-gw.service +User=agent-gw +catalog.read every 5 min via 127.0.0.1:9137 +log: /var/lib/agent-gw/agent.log +``` + +Проверка: + +```text +systemctl is-active agent-gw → active +{"tool":"catalog.read","bytes":6884} runuser -u agent-gw -- curl http://127.0.0.1:9120/catalog -connect failed / direct=000 +direct=000 ``` ## Ограничение diff --git a/ops/ai/agent-gw.service b/ops/ai/agent-gw.service new file mode 100644 index 0000000..f3b7710 --- /dev/null +++ b/ops/ai/agent-gw.service @@ -0,0 +1,17 @@ +[Unit] +Description=Buryans gateway-only agent +After=network.target hub-tools.service +Wants=hub-tools.service + +[Service] +Type=simple +User=agent-gw +Group=agent-gw +ExecStart=/usr/bin/python3 /opt/agent-gw/service.py +Restart=always +RestartSec=10 +NoNewPrivileges=true +PrivateTmp=true + +[Install] +WantedBy=multi-user.target diff --git a/ops/ai/agentgw_service.py b/ops/ai/agentgw_service.py new file mode 100644 index 0000000..3b56d73 --- /dev/null +++ b/ops/ai/agentgw_service.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +"""Production-style gateway-only agent: catalog read every 5 minutes.""" +import json, time, urllib.request +from pathlib import Path + +BASE = "http://127.0.0.1:9137" +LOG = Path("/var/lib/agent-gw/agent.log") + + +def call(tool): + with urllib.request.urlopen(BASE + "/v1/call?tool=" + tool, timeout=10) as r: + return json.loads(r.read().decode()) + + +def main(): + LOG.parent.mkdir(parents=True, exist_ok=True) + while True: + try: + d = call("catalog.read") + with LOG.open("a") as f: + f.write(json.dumps({"ts": time.time(), "tool": "catalog.read", + "bytes": len(d.get("body") or "")}) + "\n") + except Exception as e: + with LOG.open("a") as f: + f.write(json.dumps({"ts": time.time(), "error": str(e)[:200]}) + "\n") + time.sleep(300) + + +if __name__ == "__main__": + main()