-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_all_agents.sh
More file actions
executable file
·121 lines (100 loc) · 3.04 KB
/
start_all_agents.sh
File metadata and controls
executable file
·121 lines (100 loc) · 3.04 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
#!/bin/bash
# A2A Ruby Samples - Start All Agents
# This script starts all three sample agents on different ports
set -e
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[✓]${NC} $1"
}
print_warn() {
echo -e "${YELLOW}[!]${NC} $1"
}
# Function to wait for server to start
wait_for_server() {
local port=$1
local name=$2
local timeout=30
local count=0
while [ $count -lt $timeout ]; do
if curl -s "http://localhost:$port/health" > /dev/null 2>&1; then
print_success "$name is ready on port $port"
return 0
fi
sleep 1
((count++))
done
print_warn "$name failed to start on port $port"
return 1
}
# Function to stop all background processes
cleanup() {
if [ "${CLEANUP_STARTED:-}" != "true" ]; then
CLEANUP_STARTED=true
print_info "Stopping all agents..."
local pids=$(jobs -p 2>/dev/null || true)
if [ -n "$pids" ]; then
echo "$pids" | xargs kill 2>/dev/null || true
wait 2>/dev/null || true
fi
print_info "All agents stopped."
fi
}
# Set up cleanup on exit
trap cleanup EXIT
print_info "Starting A2A Ruby Sample Agents"
print_info "================================"
cd "$(dirname "$0")"
# Update bundles for all agents
print_info "Updating bundles..."
for agent in helloworld-agent weather-agent dice-agent; do
(cd "samples/$agent" && bundle install --quiet)
done
# Start all three agents
print_info "Starting agents..."
# Hello World Agent - Port 9999
print_info "Starting Hello World Agent on port 9999..."
(cd samples/helloworld-agent && PORT=9999 ruby server.rb) &
# Weather Agent - Port 10000
print_info "Starting Weather Agent on port 10000..."
(cd samples/weather-agent && PORT=10000 ruby server.rb) &
# Dice Agent - Port 10001
print_info "Starting Dice Agent on port 10001..."
(cd samples/dice-agent && PORT=10001 ruby server.rb) &
# Wait for all servers to start
print_info "Waiting for servers to start..."
sleep 3
wait_for_server 9999 "Hello World Agent"
wait_for_server 10000 "Weather Agent"
wait_for_server 10001 "Dice Agent"
print_success "All agents are running!"
print_info ""
print_info "Agent URLs:"
print_info "==========="
print_info "Hello World Agent: http://localhost:9999"
print_info "Weather Agent: http://localhost:10000"
print_info "Dice Agent: http://localhost:10001"
print_info ""
print_info "Health Checks:"
print_info "=============="
print_info "curl http://localhost:9999/health"
print_info "curl http://localhost:10000/health"
print_info "curl http://localhost:10001/health"
print_info ""
print_info "Agent Cards:"
print_info "============"
print_info "curl http://localhost:9999/a2a/agent-card"
print_info "curl http://localhost:10000/a2a/agent-card"
print_info "curl http://localhost:10001/a2a/agent-card"
print_info ""
print_info "Press Ctrl+C to stop all agents"
# Keep the script running
while true; do
sleep 1
done