Spaces:
Runtime error
Runtime error
Update agents/planning.py
Browse files- agents/planning.py +21 -9
agents/planning.py
CHANGED
|
@@ -23,7 +23,7 @@ def planning_agent(anthropic_client, state: Dict[str, Any]) -> Dict[str, Any]:
|
|
| 23 |
messages = state.get("messages", [])
|
| 24 |
user_intent = state.get("user_intent", {})
|
| 25 |
|
| 26 |
-
# Add agent-specific instructions
|
| 27 |
system_message = """
|
| 28 |
You are an AI assistant specializing in pharmaceutical data pipeline planning.
|
| 29 |
Your job is to create a comprehensive ETL pipeline plan based on the user's intent.
|
|
@@ -50,17 +50,29 @@ def planning_agent(anthropic_client, state: Dict[str, Any]) -> Dict[str, Any]:
|
|
| 50 |
- Data products: DP_SALES_DASHBOARD, DP_HCP_TARGETING
|
| 51 |
"""
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
response = anthropic_client.messages.create(
|
| 62 |
model="claude-3-7-sonnet-20250219",
|
| 63 |
-
|
|
|
|
| 64 |
max_tokens=3000
|
| 65 |
)
|
| 66 |
|
|
|
|
| 23 |
messages = state.get("messages", [])
|
| 24 |
user_intent = state.get("user_intent", {})
|
| 25 |
|
| 26 |
+
# Add agent-specific instructions as system parameter
|
| 27 |
system_message = """
|
| 28 |
You are an AI assistant specializing in pharmaceutical data pipeline planning.
|
| 29 |
Your job is to create a comprehensive ETL pipeline plan based on the user's intent.
|
|
|
|
| 50 |
- Data products: DP_SALES_DASHBOARD, DP_HCP_TARGETING
|
| 51 |
"""
|
| 52 |
|
| 53 |
+
# Convert state messages to the format expected by Anthropic API
|
| 54 |
+
# Excluding any messages with role "system"
|
| 55 |
+
anthropic_messages = []
|
| 56 |
+
for msg in messages:
|
| 57 |
+
if msg["role"] != "system": # Skip system messages
|
| 58 |
+
anthropic_messages.append(MessageParam(
|
| 59 |
+
role=msg["role"],
|
| 60 |
+
content=msg["content"]
|
| 61 |
+
))
|
| 62 |
|
| 63 |
+
# Add final user message with context
|
| 64 |
+
anthropic_messages.append(
|
| 65 |
+
MessageParam(
|
| 66 |
+
role="user",
|
| 67 |
+
content=f"Based on my request, create a data pipeline plan. Here is information about available data: {context}"
|
| 68 |
+
)
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Call Claude API with system message as separate parameter
|
| 72 |
response = anthropic_client.messages.create(
|
| 73 |
model="claude-3-7-sonnet-20250219",
|
| 74 |
+
system=system_message,
|
| 75 |
+
messages=anthropic_messages,
|
| 76 |
max_tokens=3000
|
| 77 |
)
|
| 78 |
|