cryogenic22 commited on
Commit
89f9134
·
verified ·
1 Parent(s): 9a25947

Update agents/understanding.py

Browse files
Files changed (1) hide show
  1. agents/understanding.py +14 -24
agents/understanding.py CHANGED
@@ -22,7 +22,7 @@ def understanding_agent(anthropic_client, state: Dict[str, Any]) -> Dict[str, An
22
  # Get current messages
23
  messages = state.get("messages", [])
24
 
25
- # Add agent-specific instructions
26
  system_message = """
27
  You are an AI assistant specializing in understanding pharmaceutical data needs.
28
  Your job is to understand what data pipeline the user needs to create.
@@ -37,16 +37,21 @@ def understanding_agent(anthropic_client, state: Dict[str, Any]) -> Dict[str, An
37
  If you understand the request fully, summarize the user's intent and tag it as INTENT_COMPLETE.
38
  """
39
 
40
- # Prepare prompt for Claude
41
- prompt_messages = [
42
- MessageParam(role="system", content=system_message),
43
- *[MessageParam(role=m["role"], content=m["content"]) for m in messages]
44
- ]
 
 
 
 
45
 
46
- # Call Claude API
47
  response = anthropic_client.messages.create(
48
  model="claude-3-7-sonnet-20250219",
49
- messages=prompt_messages,
 
50
  max_tokens=2000
51
  )
52
 
@@ -62,19 +67,4 @@ def understanding_agent(anthropic_client, state: Dict[str, Any]) -> Dict[str, An
62
  # Parse the structured intent from the response
63
  # This would be more sophisticated in production
64
  new_state["user_intent"] = {
65
- "understood": True,
66
- "description": agent_response.replace("INTENT_COMPLETE", "").strip(),
67
- "time": time.time()
68
- }
69
- new_state["current_agent"] = "planning_agent"
70
- else:
71
- # Need more information, stay with understanding agent
72
- new_state["current_agent"] = "understanding_agent"
73
-
74
- # Add agent's response to messages
75
- new_messages = add_messages(state, [
76
- {"role": "assistant", "content": agent_response.replace("INTENT_COMPLETE", "").strip()}
77
- ])
78
- new_state["messages"] = new_messages
79
-
80
- return new_state
 
22
  # Get current messages
23
  messages = state.get("messages", [])
24
 
25
+ # Add agent-specific instructions as system parameter
26
  system_message = """
27
  You are an AI assistant specializing in understanding pharmaceutical data needs.
28
  Your job is to understand what data pipeline the user needs to create.
 
37
  If you understand the request fully, summarize the user's intent and tag it as INTENT_COMPLETE.
38
  """
39
 
40
+ # Convert state messages to the format expected by Anthropic API
41
+ # Excluding any messages with role "system"
42
+ anthropic_messages = []
43
+ for msg in messages:
44
+ if msg["role"] != "system": # Skip system messages
45
+ anthropic_messages.append(MessageParam(
46
+ role=msg["role"],
47
+ content=msg["content"]
48
+ ))
49
 
50
+ # Call Claude API with system message as separate parameter
51
  response = anthropic_client.messages.create(
52
  model="claude-3-7-sonnet-20250219",
53
+ system=system_message,
54
+ messages=anthropic_messages,
55
  max_tokens=2000
56
  )
57
 
 
67
  # Parse the structured intent from the response
68
  # This would be more sophisticated in production
69
  new_state["user_intent"] = {
70
+ "understood": T