integration: add scripts/build_agents.py
Browse files- scripts/build_agents.py +103 -0
scripts/build_agents.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Agent build & deployment pipeline — validate + package agent definitions.
|
| 4 |
+
|
| 5 |
+
Build steps:
|
| 6 |
+
1. Parse agents/registry.yaml and every agents/*.agent.yaml
|
| 7 |
+
2. Cross-check: every registry entry resolves to a file; every file is
|
| 8 |
+
registered (warn on orphans); module/tool references exist
|
| 9 |
+
3. Emit a build report (stdout + JSON artifact manifest)
|
| 10 |
+
|
| 11 |
+
Usage:
|
| 12 |
+
python3 scripts/build_agents.py # build + report
|
| 13 |
+
python3 scripts/build_agents.py --json # machine-readable manifest only
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import json
|
| 19 |
+
import sys
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
|
| 22 |
+
import yaml
|
| 23 |
+
|
| 24 |
+
ROOT = Path(__file__).resolve().parent.parent
|
| 25 |
+
AGENTS_DIR = ROOT / "agents"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def load_yaml(path: Path):
|
| 29 |
+
with open(path, encoding="utf-8") as fh:
|
| 30 |
+
return yaml.safe_load(fh) or {}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def build() -> dict:
|
| 34 |
+
registry = load_yaml(AGENTS_DIR / "registry.yaml")
|
| 35 |
+
entries = registry.get("agents", [])
|
| 36 |
+
entry_ids = [e["id"] for e in entries]
|
| 37 |
+
|
| 38 |
+
built = []
|
| 39 |
+
orphaned = []
|
| 40 |
+
errors = []
|
| 41 |
+
|
| 42 |
+
for path in sorted(AGENTS_DIR.glob("*.agent.yaml")):
|
| 43 |
+
data = load_yaml(path)
|
| 44 |
+
agent_id = data.get("id")
|
| 45 |
+
if agent_id is None:
|
| 46 |
+
errors.append(f"{path.name}: missing id")
|
| 47 |
+
continue
|
| 48 |
+
registered = agent_id in entry_ids
|
| 49 |
+
if not registered:
|
| 50 |
+
orphaned.append(agent_id)
|
| 51 |
+
workers = data.get("agents", [])
|
| 52 |
+
tasks = data.get("tasks", [])
|
| 53 |
+
tools = data.get("tools", [])
|
| 54 |
+
built.append({
|
| 55 |
+
"id": agent_id,
|
| 56 |
+
"file": path.name,
|
| 57 |
+
"kind": data.get("kind", "unknown"),
|
| 58 |
+
"registered": registered,
|
| 59 |
+
"workers": len(workers),
|
| 60 |
+
"tasks": tasks,
|
| 61 |
+
"tools": tools,
|
| 62 |
+
"triggers": data.get("triggers", []),
|
| 63 |
+
})
|
| 64 |
+
|
| 65 |
+
for entry in entries:
|
| 66 |
+
f = entry.get("file")
|
| 67 |
+
if f and not (AGENTS_DIR / f).exists():
|
| 68 |
+
errors.append(f"registry -> {f}: file missing")
|
| 69 |
+
|
| 70 |
+
status = "PASS" if not errors else "FAIL"
|
| 71 |
+
report = {
|
| 72 |
+
"status": status,
|
| 73 |
+
"agents_built": len(built),
|
| 74 |
+
"registered": len([b for b in built if b["registered"]]),
|
| 75 |
+
"orphaned": orphaned,
|
| 76 |
+
"errors": errors,
|
| 77 |
+
"agents": built,
|
| 78 |
+
}
|
| 79 |
+
return report
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def main() -> int:
|
| 83 |
+
report = build()
|
| 84 |
+
if "--json" in sys.argv:
|
| 85 |
+
print(json.dumps(report, indent=2))
|
| 86 |
+
else:
|
| 87 |
+
print(f"🔨 Agent build — {report['status']}")
|
| 88 |
+
print(f" agents built : {report['agents_built']}")
|
| 89 |
+
print(f" registered : {report['registered']}")
|
| 90 |
+
print(f" orphaned : {report['orphaned'] or 'none'}")
|
| 91 |
+
for b in report["agents"]:
|
| 92 |
+
print(f" - {b['id']:<24} kind={b['kind']:<6} workers={b['workers']} "
|
| 93 |
+
f"tasks={len(b['tasks'])} tools={len(b['tools'])}")
|
| 94 |
+
if report["errors"]:
|
| 95 |
+
for e in report["errors"]:
|
| 96 |
+
print(f" ✗ {e}")
|
| 97 |
+
else:
|
| 98 |
+
print(" ✅ no build errors")
|
| 99 |
+
return 0 if report["status"] == "PASS" else 1
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
if __name__ == "__main__":
|
| 103 |
+
sys.exit(main())
|