Spaces:
Sleeping
Sleeping
Daniel Amendoeira
commited on
Update agent.py
Browse files
agent.py
CHANGED
@@ -60,6 +60,7 @@ def tool_node(state: MessagesState):
|
|
60 |
result.append(ToolMessage(content=observation, tool_call_id=tool_call["id"]))
|
61 |
return {"messages": result}
|
62 |
|
|
|
63 |
def should_continue(state: MessagesState) -> Literal["Action", END]:
|
64 |
"""Decide if we should continue the loop or stop based upon whether the LLM made a tool call"""
|
65 |
|
@@ -69,3 +70,24 @@ def should_continue(state: MessagesState) -> Literal["Action", END]:
|
|
69 |
return "Action"
|
70 |
# Otherwise, we stop (reply to the user)
|
71 |
return END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
result.append(ToolMessage(content=observation, tool_call_id=tool_call["id"]))
|
61 |
return {"messages": result}
|
62 |
|
63 |
+
# Conditional edge function to route to the tool node or end based upon whether the LLM made a tool call
|
64 |
def should_continue(state: MessagesState) -> Literal["Action", END]:
|
65 |
"""Decide if we should continue the loop or stop based upon whether the LLM made a tool call"""
|
66 |
|
|
|
70 |
return "Action"
|
71 |
# Otherwise, we stop (reply to the user)
|
72 |
return END
|
73 |
+
|
74 |
+
# Build workflow
|
75 |
+
builder = StateGraph(MessagesState)
|
76 |
+
|
77 |
+
# Add nodes
|
78 |
+
builder.add_node("llm_call", llm_call)
|
79 |
+
builder.add_node("environment", tool_node)
|
80 |
+
|
81 |
+
# Add edges to connect nodes
|
82 |
+
builder.add_edge(START, "llm_call")
|
83 |
+
builder.add_conditional_edges(
|
84 |
+
"llm_call",
|
85 |
+
should_continue,
|
86 |
+
{
|
87 |
+
# Name returned by should_continue : Name of the next node
|
88 |
+
"Action": "environment",
|
89 |
+
END: END
|
90 |
+
})
|
91 |
+
builder.add_edge("environment", "llm_call")
|
92 |
+
|
93 |
+
gaia_agent = builder.compile()
|