forked from aaronjmars/aeon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-a2a
More file actions
executable file
·193 lines (162 loc) · 7.46 KB
/
Copy pathadd-a2a
File metadata and controls
executable file
·193 lines (162 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env bash
# add-a2a — Build and start the Aeon A2A Gateway so any AI agent framework
# (LangChain, AutoGen, CrewAI, OpenAI Agents SDK, Vertex AI) can invoke Aeon
# skills directly via Google's Agent-to-Agent protocol.
#
# Usage:
# ./add-a2a Build and start the gateway (port 41241)
# ./add-a2a --port 8080 Use a custom port
# ./add-a2a --build-only Build without starting
# ./add-a2a --print-config Print agent card URL and sample client code
# ./add-a2a --help Show this help
#
# The gateway runs in the foreground. For production, run it under a process
# manager (pm2, systemd, Docker) or expose it with ngrok for external access.
#
# Agent card URL: http://localhost:41241/.well-known/agent.json
# JSON-RPC: POST http://localhost:41241/
# SSE streaming: POST http://localhost:41241/tasks/sendSubscribe
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
A2A_DIR="$DIR/apps/a2a-server"
PORT=41241
usage() {
sed -n '3,14p' "$0" | sed 's/^# //'
exit 0
}
err() { printf '\033[0;31mError: %s\033[0m\n' "$*" >&2; exit 1; }
info() { printf '\033[0;34m%s\033[0m\n' "$*"; }
ok() { printf '\033[0;32m✓ %s\033[0m\n' "$*"; }
warn() { printf '\033[0;33m⚠ %s\033[0m\n' "$*"; }
BUILD_ONLY=false
PRINT_CONFIG=false
while [[ $# -gt 0 ]]; do
case "$1" in
--port) PORT="${2:?--port requires a value}"; shift 2 ;;
--build-only) BUILD_ONLY=true; shift ;;
--print-config) PRINT_CONFIG=true; shift ;;
--help|-h) usage ;;
*) err "Unknown option: $1" ;;
esac
done
# ── Pre-flight ────────────────────────────────────────────────────────────────
info "Checking prerequisites..."
if ! command -v node &>/dev/null; then
err "Node.js not found. Install it from https://nodejs.org (v18 or later required)"
fi
NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
if [[ "$NODE_VERSION" -lt 18 ]]; then
err "Node.js v18 or later required (found v$NODE_VERSION)"
fi
ok "Node.js $(node --version)"
if ! command -v npm &>/dev/null; then
err "npm not found. It should come with Node.js."
fi
ok "npm $(npm --version)"
if [[ ! -d "$A2A_DIR" ]]; then
err "apps/a2a-server/ directory not found at $A2A_DIR"
fi
if [[ ! -f "$DIR/skills.json" ]]; then
err "skills.json not found at $DIR/skills.json. Run this from the repo root."
fi
# ── Build ─────────────────────────────────────────────────────────────────────
info "Installing dependencies..."
(cd "$A2A_DIR" && npm install --silent)
ok "Dependencies installed"
info "Building TypeScript..."
(cd "$A2A_DIR" && npm run build)
ok "Build complete → apps/a2a-server/dist/index.js"
SERVER_PATH="$A2A_DIR/dist/index.js"
if [[ ! -f "$SERVER_PATH" ]]; then
err "Build failed: $SERVER_PATH not found"
fi
if [[ "$BUILD_ONLY" == "true" ]]; then
ok "Build complete (--build-only: skipping server start)"
exit 0
fi
# ── Skill count ───────────────────────────────────────────────────────────────
SKILL_COUNT=$(node -e \
"const s=JSON.parse(require('fs').readFileSync('$DIR/skills.json','utf8')); \
console.log(s.skills.length);" 2>/dev/null || echo "?")
URL="http://localhost:${PORT}"
echo ""
echo "┌──────────────────────────────────────────────────────────┐"
echo "│ ⚡ Aeon A2A Gateway │"
echo "│ │"
printf "│ %d skills available to any A2A-compliant agent │\n" "$SKILL_COUNT"
echo "│ │"
echo "│ Agent card: /.well-known/agent.json │"
echo "│ JSON-RPC: POST / │"
echo "│ SSE stream: POST /tasks/sendSubscribe │"
echo "│ │"
printf "│ Running at: %s │\n" "$URL"
echo "│ │"
echo "│ Ctrl+C to stop │"
echo "└──────────────────────────────────────────────────────────┘"
echo ""
# ── Print sample config ───────────────────────────────────────────────────────
if [[ "$PRINT_CONFIG" == "true" ]]; then
echo "── Plain HTTP (works with any language/framework) ──────────"
cat <<EOF
# No SDK required — A2A is just HTTP + JSON-RPC.
# Use requests, httpx, fetch, curl, or any HTTP client.
import requests, uuid
task_id = str(uuid.uuid4())
resp = requests.post("${URL}/", json={
"jsonrpc": "2.0", "id": 1, "method": "tasks/send",
"params": {
"id": task_id,
"skillId": "aeon-deep-research",
"var": "AI agent frameworks 2025",
"message": {"role": "user", "parts": [{"type": "text", "text": "Run aeon-deep-research"}]}
}
}).json()
# Poll for completion:
import time
for _ in range(120):
time.sleep(5)
status = requests.post("${URL}/", json={
"jsonrpc": "2.0", "id": 2, "method": "tasks/get",
"params": {"id": task_id}
}).json()
if status["result"]["status"]["state"] == "completed":
print(status["result"]["artifacts"][0]["parts"][0]["text"])
break
EOF
echo "── LangChain Tool wrapper ───────────────────────────────────"
cat <<EOF
from langchain.tools import Tool
import requests, time, uuid
def call_aeon(skill_id: str, var: str = "") -> str:
task_id = str(uuid.uuid4())
resp = requests.post("${URL}/", json={
"jsonrpc": "2.0", "id": 1, "method": "tasks/send",
"params": {"id": task_id, "skillId": skill_id, "var": var,
"message": {"role": "user", "parts": [{"type": "text",
"text": f"Run {skill_id} var={var}"}]}}
}).json()
# Poll until complete
for _ in range(120):
time.sleep(5)
status = requests.post("${URL}/", json={
"jsonrpc": "2.0", "id": 2, "method": "tasks/get",
"params": {"id": task_id}
}).json()
state = status["result"]["status"]["state"]
if state == "completed":
return status["result"]["artifacts"][0]["parts"][0]["text"]
if state in ("failed", "canceled"):
raise RuntimeError(f"Skill failed: {status}")
raise TimeoutError("Skill timed out after 10 minutes")
aeon_research = Tool(
name="aeon_deep_research",
func=lambda q: call_aeon("aeon-deep-research", q),
description="Exhaustive multi-source research on any topic (30-50 sources)"
)
EOF
echo ""
fi
# ── Start server ──────────────────────────────────────────────────────────────
export A2A_PORT="$PORT"
export A2A_URL="$URL"
exec node "$SERVER_PATH"