ernani commited on
Commit
75225d1
·
1 Parent(s): 6aa7079

fixing messages

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -52,14 +52,22 @@ class AgentState(TypedDict):
52
 
53
  def assistant(state: AgentState):
54
  # Prepare messages for the agent
 
55
  messages = [{"role": "user", "content": msg.content} for msg in state["messages"]]
56
 
57
  # Invoke the agent with the prepared messages
58
  response = agent.invoke({"messages": messages})
59
  print(response)
60
- # Extract the response content from the AIMessage object
61
- response_content = response
62
- # response_content = response.messages[-1].content # Access the content attribute directly
 
 
 
 
 
 
 
63
 
64
  return {
65
  "messages": [response_content],
 
52
 
53
  def assistant(state: AgentState):
54
  # Prepare messages for the agent
55
+
56
  messages = [{"role": "user", "content": msg.content} for msg in state["messages"]]
57
 
58
  # Invoke the agent with the prepared messages
59
  response = agent.invoke({"messages": messages})
60
  print(response)
61
+
62
+ # Ensure the response is a list of message dictionaries
63
+ response_messages = [
64
+ {"role": "assistant", "content": msg.content} for msg in response["messages"]
65
+ ]
66
+ print(response_messages)
67
+
68
+ # Extract the response content from the last message
69
+ response_content = response_messages[-1]["content"]
70
+ print(response_content)
71
 
72
  return {
73
  "messages": [response_content],