cryogenic22 commited on
Commit
b1e2bae
·
verified ·
1 Parent(s): 5bb5631

Update agents/executor.py

Browse files
Files changed (1) hide show
  1. agents/executor.py +19 -8
agents/executor.py CHANGED
@@ -22,8 +22,8 @@ def executor_agent(anthropic_client, db, state: Dict[str, Any]) -> Dict[str, Any
22
  Updated state
23
  """
24
  # Get current messages and SQL queries
25
- messages = state["messages"]
26
- sql_queries = state["sql_queries"]
27
 
28
  # Add agent-specific instructions
29
  system_message = """
@@ -47,17 +47,28 @@ def executor_agent(anthropic_client, db, state: Dict[str, Any]) -> Dict[str, Any
47
  # Prepare context for Claude
48
  execution_context = json.dumps(execution_results, indent=2)
49
 
50
- # Prepare prompt for Claude
51
- prompt_messages = [
52
- *[MessageParam(role=m["role"], content=m["content"]) for m in messages],
53
- MessageParam(role="user", content=f"Here are the execution results of the SQL queries. Please analyze and report on them.\n\n{execution_context}")
54
- ]
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  # Call Claude API
57
  response = anthropic_client.messages.create(
58
  model="claude-3-7-sonnet-20250219",
59
  system=system_message,
60
- messages=prompt_messages,
61
  max_tokens=2000
62
  )
63
 
 
22
  Updated state
23
  """
24
  # Get current messages and SQL queries
25
+ messages = state.get("messages", [])
26
+ sql_queries = state.get("sql_queries", [])
27
 
28
  # Add agent-specific instructions
29
  system_message = """
 
47
  # Prepare context for Claude
48
  execution_context = json.dumps(execution_results, indent=2)
49
 
50
+ # Convert messages to the format expected by Anthropic API
51
+ anthropic_messages = []
52
+ for msg in messages:
53
+ if isinstance(msg, dict) and "role" in msg and "content" in msg:
54
+ anthropic_messages.append(MessageParam(
55
+ role=msg["role"],
56
+ content=msg["content"]
57
+ ))
58
+
59
+ # Add final user message with context
60
+ anthropic_messages.append(
61
+ MessageParam(
62
+ role="user",
63
+ content=f"Here are the execution results of the SQL queries. Please analyze and report on them.\n\n{execution_context}"
64
+ )
65
+ )
66
 
67
  # Call Claude API
68
  response = anthropic_client.messages.create(
69
  model="claude-3-7-sonnet-20250219",
70
  system=system_message,
71
+ messages=anthropic_messages,
72
  max_tokens=2000
73
  )
74