Spaces:
Runtime error
Runtime error
Update agents/executor.py
Browse files- 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
|
| 26 |
-
sql_queries = state
|
| 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 |
-
#
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 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=
|
| 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 |
|