cryogenic22 commited on
Commit
120e648
·
verified ·
1 Parent(s): 99c722d

Update agents/sql_generator.py

Browse files
Files changed (1) hide show
  1. agents/sql_generator.py +21 -9
agents/sql_generator.py CHANGED
@@ -23,7 +23,7 @@ def sql_generator_agent(anthropic_client, state: Dict[str, Any]) -> Dict[str, An
23
  messages = state.get("messages", [])
24
  pipeline_plan = state.get("pipeline_plan", {})
25
 
26
- # Add agent-specific instructions
27
  system_message = """
28
  You are an AI assistant specializing in generating SQL for pharmaceutical data pipelines.
29
  Your job is to transform the pipeline plan into executable SQL queries.
@@ -48,17 +48,29 @@ def sql_generator_agent(anthropic_client, state: Dict[str, Any]) -> Dict[str, An
48
  - Data products: DP_SALES_DASHBOARD, DP_HCP_TARGETING
49
  """
50
 
51
- # Prepare prompt for Claude
52
- prompt_messages = [
53
- MessageParam(role="system", content=system_message),
54
- *[MessageParam(role=m["role"], content=m["content"]) for m in messages],
55
- MessageParam(role="user", content=f"Based on this pipeline plan, generate the SQL queries needed. {context}")
56
- ]
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- # Call Claude API
59
  response = anthropic_client.messages.create(
60
  model="claude-3-7-sonnet-20250219",
61
- messages=prompt_messages,
 
62
  max_tokens=3000
63
  )
64
 
 
23
  messages = state.get("messages", [])
24
  pipeline_plan = state.get("pipeline_plan", {})
25
 
26
+ # Add agent-specific instructions as system parameter
27
  system_message = """
28
  You are an AI assistant specializing in generating SQL for pharmaceutical data pipelines.
29
  Your job is to transform the pipeline plan into executable SQL queries.
 
48
  - Data products: DP_SALES_DASHBOARD, DP_HCP_TARGETING
49
  """
50
 
51
+ # Convert state messages to the format expected by Anthropic API
52
+ # Excluding any messages with role "system"
53
+ anthropic_messages = []
54
+ for msg in messages:
55
+ if msg["role"] != "system": # Skip system messages
56
+ anthropic_messages.append(MessageParam(
57
+ role=msg["role"],
58
+ content=msg["content"]
59
+ ))
60
+
61
+ # Add final user message with context
62
+ anthropic_messages.append(
63
+ MessageParam(
64
+ role="user",
65
+ content=f"Based on this pipeline plan, generate the SQL queries needed. {context}"
66
+ )
67
+ )
68
 
69
+ # Call Claude API with system message as separate parameter
70
  response = anthropic_client.messages.create(
71
  model="claude-3-7-sonnet-20250219",
72
+ system=system_message,
73
+ messages=anthropic_messages,
74
  max_tokens=3000
75
  )
76