/ verify_ceo_multiturn.sh
verify_ceo_multiturn.sh
 1  #!/bin/bash
 2  set -euo pipefail
 3  
 4  echo "========================================="
 5  echo " Multi-Turn CEO Session Verification"
 6  echo "========================================="
 7  echo ""
 8  
 9  # Start the CEO agent in the background
10  echo "Starting CEO agent..."
11  ./apps/ceo/ceo > /tmp/ceo_output.log 2>&1 &
12  CEO_PID=$!
13  echo "CEO agent running (PID: $CEO_PID)"
14  sleep 2
15  
16  # Function to send MCP request
17  send_request() {
18      local id=$1
19      local method=$2
20      local params=$3
21      echo "{\"jsonrpc\": \"2.0\", \"id\": $id, \"method\": \"$method\", \"params\": $params}"
22  }
23  
24  # Function to call tool
25  call_tool() {
26      local id=$1
27      local tool=$2
28      local args=$3
29      send_request "$id" "tools/call" "{\"name\": \"$tool\", \"arguments\": $args}"
30  }
31  
32  echo ""
33  echo "Turn 1: Ask about hiring strategy..."
34  echo ""
35  
36  # Initialize
37  send_request 1 "initialize" '{"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}'
38  
39  # First question (creates new session)
40  cat <<'EOF'
41  {"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "session_consult", "arguments": {"question": "Should I hire 5 senior engineers or 10 junior engineers for our expansion?"}}}
42  EOF
43  
44  sleep 25  # Wait for LLM response
45  
46  echo ""
47  echo "Turn 2: Follow-up question (uses same session)..."
48  echo ""
49  
50  # Get the session_id from the database
51  SESSION_ID=$(PGPASSWORD=postgres psql -h 127.0.0.1 -p 5433 -U echo_org -d echo_org -t -c "SELECT session_id FROM llm_sessions WHERE agent_role = 'ceo' ORDER BY created_at DESC LIMIT 1;" | xargs)
52  
53  echo "Using session: $SESSION_ID"
54  
55  # Second question (continues conversation)
56  cat <<EOF
57  {"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "session_consult", "arguments": {"session_id": "$SESSION_ID", "question": "What about the budget implications of each option?"}}}
58  EOF
59  
60  sleep 25  # Wait for LLM response
61  
62  # Clean up
63  kill $CEO_PID 2>/dev/null || true
64  
65  echo ""
66  echo "========================================="
67  echo "Verification Steps:"
68  echo "========================================="
69  echo ""
70  echo "1. Check the database for the session:"
71  echo "   PGPASSWORD=postgres psql -h 127.0.0.1 -p 5433 -U echo_org -d echo_org -c \"SELECT session_id, turn_count FROM llm_sessions WHERE session_id = '$SESSION_ID';\""
72  echo ""
73  echo "2. Verify turn_count increased from 1 to 2"
74  echo ""
75  echo "3. Check conversation history:"
76  echo "   PGPASSWORD=postgres psql -h 127.0.0.1 -p 5433 -U echo_org -d echo_org -c \"SELECT jsonb_array_length(conversation_history) FROM llm_sessions WHERE session_id = '$SESSION_ID';\""
77  echo ""