cryogenic22 commited on
Commit
21aa8e8
·
verified ·
1 Parent(s): 120e648

Update agents/executor.py

Browse files
Files changed (1) hide show
  1. agents/executor.py +21 -9
agents/executor.py CHANGED
@@ -25,7 +25,7 @@ def executor_agent(anthropic_client, db, state: Dict[str, Any]) -> Dict[str, Any
25
  messages = state.get("messages", [])
26
  sql_queries = state.get("sql_queries", [])
27
 
28
- # Add agent-specific instructions
29
  system_message = """
30
  You are an AI assistant specializing in executing and validating pharmaceutical data pipelines.
31
  Your job is to execute the SQL queries and report on the results.
@@ -47,17 +47,29 @@ 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="system", content=system_message),
53
- *[MessageParam(role=m["role"], content=m["content"]) for m in messages],
54
- MessageParam(role="user", content=f"Here are the execution results of the SQL queries. Please analyze and report on them.\n\n{execution_context}")
55
- ]
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- # Call Claude API
58
  response = anthropic_client.messages.create(
59
  model="claude-3-7-sonnet-20250219",
60
- messages=prompt_messages,
 
61
  max_tokens=2000
62
  )
63
 
 
25
  messages = state.get("messages", [])
26
  sql_queries = state.get("sql_queries", [])
27
 
28
+ # Add agent-specific instructions as system parameter
29
  system_message = """
30
  You are an AI assistant specializing in executing and validating pharmaceutical data pipelines.
31
  Your job is to execute the SQL queries and report on the results.
 
47
  # Prepare context for Claude
48
  execution_context = json.dumps(execution_results, indent=2)
49
 
50
+ # Convert state messages to the format expected by Anthropic API
51
+ # Excluding any messages with role "system"
52
+ anthropic_messages = []
53
+ for msg in messages:
54
+ if msg["role"] != "system": # Skip system messages
55
+ anthropic_messages.append(MessageParam(
56
+ role=msg["role"],
57
+ content=msg["content"]
58
+ ))
59
+
60
+ # Add final user message with context
61
+ anthropic_messages.append(
62
+ MessageParam(
63
+ role="user",
64
+ content=f"Here are the execution results of the SQL queries. Please analyze and report on them.\n\n{execution_context}"
65
+ )
66
+ )
67
 
68
+ # Call Claude API with system message as separate parameter
69
  response = anthropic_client.messages.create(
70
  model="claude-3-7-sonnet-20250219",
71
+ system=system_message,
72
+ messages=anthropic_messages,
73
  max_tokens=2000
74
  )
75