Files
buryan-infra/ops/ai/agentgw_service.py
T
architect 15ed2067e8
lint / hygiene (push) Failing after 24s
lint / hygiene (pull_request) Failing after 24s
standard / check (pull_request) Successful in 11s
[STAGE5] Gateway-only production agent service
2026-11-29 18:08:37 +03:00

31 lines
919 B
Python

#!/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()