/ scripts / testing / test_agent_conversation.sh
test_agent_conversation.sh
  1  #!/bin/bash
  2  
  3  set -e
  4  
  5  echo "=========================================="
  6  echo "ECHO Agent Communication Test"
  7  echo "=========================================="
  8  echo ""
  9  
 10  # Colors for output
 11  GREEN='\033[0;32m'
 12  YELLOW='\033[1;33m'
 13  RED='\033[0;31m'
 14  NC='\033[0m' # No Color
 15  
 16  DB_CMD="PGPASSWORD=postgres psql -U postgres -h localhost -p 5433 -d echo_org -t -c"
 17  
 18  echo "Step 1: Send test message to Senior Developer"
 19  echo "----------------------------------------------"
 20  ./send_message.sh senior_developer request what_do_you_do '{"question": "What do you do as a Senior Developer?"}'
 21  echo ""
 22  echo "${YELLOW}Waiting 15 seconds for LLM processing (deepseek-coder:6.7b)...${NC}"
 23  sleep 15
 24  echo ""
 25  
 26  echo "Step 2: Check Redis pub/sub delivery"
 27  echo "--------------------------------------"
 28  SUBSCRIBERS=$(redis-cli -p 6383 PUBSUB NUMSUB messages:senior_developer | awk '{print $2}')
 29  if [ "$SUBSCRIBERS" -gt 0 ]; then
 30      echo "${GREEN}✓ Senior Developer is subscribed to Redis (${SUBSCRIBERS} subscriber)${NC}"
 31  else
 32      echo "${RED}✗ Senior Developer NOT subscribed to Redis${NC}"
 33  fi
 34  echo ""
 35  
 36  echo "Step 3: Check PostgreSQL message storage"
 37  echo "------------------------------------------"
 38  MSG_COUNT=$($DB_CMD "SELECT COUNT(*) FROM messages WHERE to_role='senior_developer' AND subject='what_do_you_do'")
 39  echo "Messages in DB: $MSG_COUNT"
 40  if [ "$MSG_COUNT" -gt 0 ]; then
 41      echo "${GREEN}✓ Message stored in PostgreSQL${NC}"
 42      echo ""
 43      echo "Last message details:"
 44      $DB_CMD "SELECT from_role, to_role, subject, inserted_at FROM messages WHERE to_role='senior_developer' ORDER BY inserted_at DESC LIMIT 1"
 45  else
 46      echo "${RED}✗ No messages found in PostgreSQL${NC}"
 47  fi
 48  echo ""
 49  
 50  echo "Step 4: Check if Senior Developer sent response"
 51  echo "------------------------------------------------"
 52  RESPONSE_COUNT=$($DB_CMD "SELECT COUNT(*) FROM messages WHERE from_role='senior_developer' AND content->>'from_llm'='true' AND inserted_at > NOW() - INTERVAL '2 minutes'")
 53  echo "LLM responses from Senior Developer: $RESPONSE_COUNT"
 54  if [ "$RESPONSE_COUNT" -gt 0 ]; then
 55      echo "${GREEN}✓ Senior Developer responded with LLM${NC}"
 56      echo ""
 57      echo "Response preview:"
 58      $DB_CMD "SELECT substring(content->>'response', 1, 200) || '...' as response FROM messages WHERE from_role='senior_developer' AND content->>'from_llm'='true' ORDER BY inserted_at DESC LIMIT 1"
 59  else
 60      echo "${YELLOW}⚠ No LLM response found yet${NC}"
 61  fi
 62  echo ""
 63  
 64  echo "Step 5: Senior Developer asks Product Manager about login system"
 65  echo "-----------------------------------------------------------------"
 66  ./send_message.sh product_manager request design_login_system '{
 67    "from": "senior_developer",
 68    "feature": "User login system",
 69    "requirements": "JWT authentication, OAuth2 support, password reset flow",
 70    "question": "What are the product requirements and priority for the login system?",
 71    "blocking": true
 72  }'
 73  echo ""
 74  echo "${YELLOW}Waiting 15 seconds for Product Manager LLM response (llama3.1:8b)...${NC}"
 75  sleep 15
 76  echo ""
 77  
 78  echo "Step 6: Check Product Manager received message"
 79  echo "----------------------------------------------"
 80  PM_MSG_COUNT=$($DB_CMD "SELECT COUNT(*) FROM messages WHERE to_role='product_manager' AND subject='design_login_system'")
 81  echo "Messages to Product Manager: $PM_MSG_COUNT"
 82  if [ "$PM_MSG_COUNT" -gt 0 ]; then
 83      echo "${GREEN}✓ Product Manager received message${NC}"
 84  else
 85      echo "${RED}✗ Product Manager did not receive message${NC}"
 86  fi
 87  echo ""
 88  
 89  echo "Step 7: Check if Product Manager responded"
 90  echo "-------------------------------------------"
 91  PM_RESPONSE_COUNT=$($DB_CMD "SELECT COUNT(*) FROM messages WHERE from_role='product_manager' AND content->>'from_llm'='true' AND inserted_at > NOW() - INTERVAL '2 minutes'")
 92  echo "LLM responses from Product Manager: $PM_RESPONSE_COUNT"
 93  if [ "$PM_RESPONSE_COUNT" -gt 0 ]; then
 94      echo "${GREEN}✓ Product Manager responded with LLM${NC}"
 95      echo ""
 96      echo "Response preview:"
 97      $DB_CMD "SELECT substring(content->>'response', 1, 200) || '...' as response FROM messages WHERE from_role='product_manager' AND content->>'from_llm'='true' ORDER BY inserted_at DESC LIMIT 1"
 98      echo ""
 99      echo "Response to agent:"
100      $DB_CMD "SELECT to_role FROM messages WHERE from_role='product_manager' AND content->>'from_llm'='true' ORDER BY inserted_at DESC LIMIT 1"
101  else
102      echo "${YELLOW}⚠ No LLM response from Product Manager yet${NC}"
103  fi
104  echo ""
105  
106  echo "Step 8: Check Redis message flow"
107  echo "---------------------------------"
108  echo "Recent Redis publishes:"
109  redis-cli -p 6383 --csv INFO stats | grep -E "total_commands_processed|pubsub"
110  echo ""
111  
112  echo "Step 9: Summary - All Messages in Last 5 Minutes"
113  echo "-------------------------------------------------"
114  $DB_CMD "SELECT 
115    from_role || ' → ' || to_role as conversation,
116    subject,
117    CASE WHEN content->>'from_llm' = 'true' THEN '🤖 LLM' ELSE '👤 User' END as source,
118    inserted_at
119  FROM messages 
120  WHERE inserted_at > NOW() - INTERVAL '5 minutes'
121  ORDER BY inserted_at ASC"
122  
123  echo ""
124  echo "=========================================="
125  echo "Test Complete!"
126  echo "=========================================="