this repo has no description
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 291 lines 10 kB view raw
1#!/bin/bash 2# Quick agent switcher for Jetstream-Letta bridge 3# Usage: ./run_agent.sh [agent_name] [additional_options...] 4 5set -e # Exit on error 6 7SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8AGENTS_DIR="${SCRIPT_DIR}/agents" 9BRIDGE_SCRIPT="${SCRIPT_DIR}/src/jetstream_letta_bridge.py" 10LISTENER_SCRIPT="${SCRIPT_DIR}/src/letta_listener.py" 11 12# Colors for output 13RED='\033[0;31m' 14GREEN='\033[0;32m' 15BLUE='\033[0;34m' 16YELLOW='\033[1;33m' 17NC='\033[0m' # No Color 18 19# Print usage 20usage() { 21 echo "🤖 Agent Runner for Jetstream-Letta Bridge" 22 echo "" 23 echo "Usage: $0 [agent_name...] [additional_options...]" 24 echo " $0 listen [agent_name...] [additional_options...]" 25 echo "" 26 echo "Examples:" 27 echo " $0 technical # Run technical agent (bridge mode)" 28 echo " $0 creative --verbose # Run creative agent with verbose output" 29 echo " $0 grunk kaleidoscope herald # Run multiple agents in parallel" 30 echo " $0 analytical --batch-size 10 # Run analytical agent with custom batch size" 31 echo " $0 listen grunk # Run grunk agent in listener mode (periodic messaging)" 32 echo " $0 listen grunk kaleidoscope # Run multiple agents in listener mode" 33 echo " $0 listen grunk --mode poll # Run with periodic polling" 34 echo "" 35 echo "Available agents:" 36 if [ -d "$AGENTS_DIR" ]; then 37 for config in "$AGENTS_DIR"/*.yaml; do 38 if [ -f "$config" ]; then 39 basename=$(basename "$config" .yaml) 40 echo " - $basename" 41 fi 42 done 43 else 44 echo " (No agents directory found at $AGENTS_DIR)" 45 fi 46 echo "" 47 echo "You can also use:" 48 echo " $0 list # List available agents with details" 49 echo " $0 setup # Run interactive setup wizard" 50 echo " $0 listen [agent] # Run agent in listener mode (periodic messaging)" 51 echo " $0 help # Show this help" 52} 53 54# List agents with details 55list_agents() { 56 echo -e "${BLUE}🤖 Listing available agents...${NC}" 57 if [ -f "$BRIDGE_SCRIPT" ]; then 58 python3 "$BRIDGE_SCRIPT" --list-agents "$AGENTS_DIR" 59 else 60 echo -e "${RED}❌ Bridge script not found at: $BRIDGE_SCRIPT${NC}" 61 exit 1 62 fi 63} 64 65# Main logic 66main() { 67 # Check if Python script exists 68 if [ ! -f "$BRIDGE_SCRIPT" ]; then 69 echo -e "${RED}❌ Bridge script not found at: $BRIDGE_SCRIPT${NC}" 70 echo "Make sure you're running this from the thought.stream directory" 71 exit 1 72 fi 73 74 # Check if agents directory exists 75 if [ ! -d "$AGENTS_DIR" ]; then 76 echo -e "${RED}❌ Agents directory not found at: $AGENTS_DIR${NC}" 77 echo "Create the agents directory and add some agent configuration files" 78 exit 1 79 fi 80 81 # Handle special commands 82 if [ $# -eq 0 ] || [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then 83 usage 84 exit 0 85 fi 86 87 if [ "$1" = "list" ]; then 88 list_agents 89 exit 0 90 fi 91 92 if [ "$1" = "setup" ]; then 93 echo -e "${BLUE}🧙 Starting setup wizard...${NC}" 94 if [ -f "$BRIDGE_SCRIPT" ]; then 95 python3 "$BRIDGE_SCRIPT" --setup 96 else 97 echo -e "${RED}❌ Bridge script not found at: $BRIDGE_SCRIPT${NC}" 98 exit 1 99 fi 100 exit 0 101 fi 102 103 # Handle listen mode (periodic messaging) 104 if [ "$1" = "listen" ]; then 105 shift # Remove 'listen' from arguments 106 107 if [ $# -eq 0 ]; then 108 echo -e "${RED}❌ Please specify one or more agent names${NC}" 109 echo "Usage: $0 listen [agent_name...] [options...]" 110 exit 1 111 fi 112 113 # Check if listener script exists 114 if [ ! -f "$LISTENER_SCRIPT" ]; then 115 echo -e "${RED}❌ Listener script not found at: $LISTENER_SCRIPT${NC}" 116 exit 1 117 fi 118 119 # Collect agent names and separate additional args 120 AGENT_NAMES=() 121 ADDITIONAL_ARGS="" 122 123 for arg in "$@"; do 124 # If argument starts with '--' or '-', treat as option 125 if [[ "$arg" == -* ]]; then 126 ADDITIONAL_ARGS="$ADDITIONAL_ARGS $arg" 127 else 128 # Check if this could be an agent name 129 AGENT_CONFIG="${AGENTS_DIR}/${arg}.yaml" 130 if [ -f "$AGENT_CONFIG" ]; then 131 AGENT_NAMES+=("$arg") 132 else 133 # If config doesn't exist, treat as additional arg 134 ADDITIONAL_ARGS="$ADDITIONAL_ARGS $arg" 135 fi 136 fi 137 done 138 139 if [ ${#AGENT_NAMES[@]} -eq 0 ]; then 140 echo -e "${RED}❌ No valid agent names provided${NC}" 141 echo "" 142 echo "Available agents:" 143 for config in "$AGENTS_DIR"/*.yaml; do 144 if [ -f "$config" ]; then 145 basename=$(basename "$config" .yaml) 146 echo " - $basename" 147 fi 148 done 149 exit 1 150 fi 151 152 # Run multiple agents if specified 153 if [ ${#AGENT_NAMES[@]} -eq 1 ]; then 154 AGENT_NAME="${AGENT_NAMES[0]}" 155 AGENT_CONFIG="${AGENTS_DIR}/${AGENT_NAME}.yaml" 156 157 echo -e "${GREEN}🔄 Starting agent listener (periodic mode): $AGENT_NAME${NC}" 158 echo -e "${BLUE}📄 Config: $AGENT_CONFIG${NC}" 159 if [ -n "$ADDITIONAL_ARGS" ]; then 160 echo -e "${YELLOW}⚙️ Additional options: $ADDITIONAL_ARGS${NC}" 161 fi 162 echo "" 163 164 # Execute the listener 165 exec python3 "$LISTENER_SCRIPT" --config "$AGENT_CONFIG" $ADDITIONAL_ARGS 166 else 167 # Multiple agents - run in parallel 168 echo -e "${GREEN}🔄 Starting ${#AGENT_NAMES[@]} agent listeners in parallel${NC}" 169 PIDS=() 170 171 # Set up trap to kill all background processes on exit 172 cleanup() { 173 echo -e "\n${YELLOW}🛑 Stopping all agents...${NC}" 174 for pid in "${PIDS[@]}"; do 175 if kill -0 $pid 2>/dev/null; then 176 kill $pid 2>/dev/null 177 fi 178 done 179 wait 180 echo -e "${GREEN}✓ All agents stopped${NC}" 181 exit 0 182 } 183 trap cleanup SIGINT SIGTERM 184 185 for AGENT_NAME in "${AGENT_NAMES[@]}"; do 186 AGENT_CONFIG="${AGENTS_DIR}/${AGENT_NAME}.yaml" 187 echo -e "${BLUE}📄 Starting $AGENT_NAME: $AGENT_CONFIG${NC}" 188 189 python3 "$LISTENER_SCRIPT" --config "$AGENT_CONFIG" $ADDITIONAL_ARGS & 190 PIDS+=($!) 191 done 192 193 if [ -n "$ADDITIONAL_ARGS" ]; then 194 echo -e "${YELLOW}⚙️ Additional options: $ADDITIONAL_ARGS${NC}" 195 fi 196 echo "" 197 echo -e "${GREEN}✓ All agents started. Press Ctrl+C to stop all.${NC}" 198 199 # Wait for all background processes 200 wait 201 fi 202 exit 0 203 fi 204 205 # Collect agent names and separate additional args 206 AGENT_NAMES=() 207 ADDITIONAL_ARGS="" 208 209 for arg in "$@"; do 210 # If argument starts with '--' or '-', treat as option 211 if [[ "$arg" == -* ]]; then 212 ADDITIONAL_ARGS="$ADDITIONAL_ARGS $arg" 213 else 214 # Check if this could be an agent name 215 AGENT_CONFIG="${AGENTS_DIR}/${arg}.yaml" 216 if [ -f "$AGENT_CONFIG" ]; then 217 AGENT_NAMES+=("$arg") 218 else 219 # If config doesn't exist, treat as additional arg 220 ADDITIONAL_ARGS="$ADDITIONAL_ARGS $arg" 221 fi 222 fi 223 done 224 225 if [ ${#AGENT_NAMES[@]} -eq 0 ]; then 226 echo -e "${RED}❌ No valid agent names provided${NC}" 227 echo "" 228 echo "Available agents:" 229 for config in "$AGENTS_DIR"/*.yaml; do 230 if [ -f "$config" ]; then 231 basename=$(basename "$config" .yaml) 232 echo " - $basename" 233 fi 234 done 235 exit 1 236 fi 237 238 # Run single agent 239 if [ ${#AGENT_NAMES[@]} -eq 1 ]; then 240 AGENT_NAME="${AGENT_NAMES[0]}" 241 AGENT_CONFIG="${AGENTS_DIR}/${AGENT_NAME}.yaml" 242 243 echo -e "${GREEN}🚀 Starting agent: $AGENT_NAME${NC}" 244 echo -e "${BLUE}📄 Config: $AGENT_CONFIG${NC}" 245 if [ -n "$ADDITIONAL_ARGS" ]; then 246 echo -e "${YELLOW}⚙️ Additional options: $ADDITIONAL_ARGS${NC}" 247 fi 248 echo "" 249 250 # Execute the bridge 251 exec python3 "$BRIDGE_SCRIPT" --agent "$AGENT_CONFIG" $ADDITIONAL_ARGS 252 else 253 # Multiple agents - run in parallel 254 echo -e "${GREEN}🚀 Starting ${#AGENT_NAMES[@]} agents in parallel${NC}" 255 PIDS=() 256 257 # Set up trap to kill all background processes on exit 258 cleanup() { 259 echo -e "\n${YELLOW}🛑 Stopping all agents...${NC}" 260 for pid in "${PIDS[@]}"; do 261 if kill -0 $pid 2>/dev/null; then 262 kill $pid 2>/dev/null 263 fi 264 done 265 wait 266 echo -e "${GREEN}✓ All agents stopped${NC}" 267 exit 0 268 } 269 trap cleanup SIGINT SIGTERM 270 271 for AGENT_NAME in "${AGENT_NAMES[@]}"; do 272 AGENT_CONFIG="${AGENTS_DIR}/${AGENT_NAME}.yaml" 273 echo -e "${BLUE}📄 Starting $AGENT_NAME: $AGENT_CONFIG${NC}" 274 275 python3 "$BRIDGE_SCRIPT" --agent "$AGENT_CONFIG" $ADDITIONAL_ARGS & 276 PIDS+=($!) 277 done 278 279 if [ -n "$ADDITIONAL_ARGS" ]; then 280 echo -e "${YELLOW}⚙️ Additional options: $ADDITIONAL_ARGS${NC}" 281 fi 282 echo "" 283 echo -e "${GREEN}✓ All agents started. Press Ctrl+C to stop all.${NC}" 284 285 # Wait for all background processes 286 wait 287 fi 288} 289 290# Run main function with all arguments 291main "$@"