Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -33,19 +33,29 @@ tools = [add,
|
|
| 33 |
|
| 34 |
chat_with_tools = chat.bind_tools(tools)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
builder
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
builder.add_edge(
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
chat_with_tools = chat.bind_tools(tools)
|
| 35 |
|
| 36 |
+
def simple_graph():
|
| 37 |
+
|
| 38 |
+
## Defining our nodes
|
| 39 |
+
def assistant(state: MessagesState):
|
| 40 |
+
"""Assistant node"""
|
| 41 |
+
return {"messages": [sys_msg] + [chat_with_tools.invoke(state["messages"])]}
|
| 42 |
+
|
| 43 |
+
# Build graph / nodes
|
| 44 |
+
builder = StateGraph(State)
|
| 45 |
+
builder.add_node("assistant", chat) # Assistant
|
| 46 |
+
builder.add_node("tools", ToolNode(tools)) # Tools
|
| 47 |
+
|
| 48 |
+
# Logic / edges
|
| 49 |
+
builder.add_edge(START, "assistant")
|
| 50 |
+
builder.add_conditional_edges("assistant", tools_condition)
|
| 51 |
+
builder.add_edge("tools", "assistant")
|
| 52 |
+
|
| 53 |
+
graph = builder.compile()
|
| 54 |
+
|
| 55 |
+
return graph
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
# Build the graph
|
| 61 |
+
graph = simple_graph()
|