@@ -46,7 +46,6 @@ def create_graph(self):
46
46
workflow = StateGraph (AgentState )
47
47
48
48
# Create nodes
49
- workflow .add_node ("initialize" , self .initialize )
50
49
workflow .add_node ("chat_with_tools" , self .chat_with_tools )
51
50
workflow .add_node (
52
51
"tools" ,
@@ -57,35 +56,24 @@ def create_graph(self):
57
56
]
58
57
),
59
58
)
60
- workflow .add_node ("finalize" , self .finalize )
61
59
62
60
# Create edges
63
- workflow .set_entry_point ("initialize" )
64
- workflow .add_edge ("initialize" , "chat_with_tools" )
61
+ workflow .set_entry_point ("chat_with_tools" )
65
62
workflow .add_conditional_edges (
66
- "chat_with_tools" ,
67
- self .route_tools ,
68
- # The following dictionary lets you tell the graph to interpret the condition's outputs as a specific node
69
- # It defaults to the identity function, but if you
70
- # want to use a node named something else apart from "tools",
71
- # You can update the value of the dictionary to something else
72
- # e.g., "tools": "my_tools"
73
- {"tools" : "tools" , END : "finalize" },
63
+ source = "chat_with_tools" ,
64
+ path = self .route_tools ,
65
+ path_map = {
66
+ "tools" : "tools" ,
67
+ END : END ,
68
+ },
74
69
)
75
70
workflow .add_edge ("tools" , "chat_with_tools" )
76
- workflow .add_edge ("finalize" , END )
77
71
78
72
# Compile the graph
79
73
return workflow .compile (
80
74
name = ChatWithToolsAgent .__name__ ,
81
75
)
82
76
83
- def initialize (self , state : AgentState ) -> AgentState :
84
- """Initialize the agent with the given state."""
85
- logger .info (f"Initializing ChatWithToolsAgent with state: { state } " )
86
- # Here you can add any initialization logic if needed
87
- return state
88
-
89
77
def chat_with_tools (self , state : AgentState ) -> AgentState :
90
78
"""Chat with tools using the state."""
91
79
logger .info (f"Chatting with tools using state: { state } " )
@@ -119,15 +107,5 @@ def route_tools(
119
107
return "tools"
120
108
return END
121
109
122
- def finalize (self , state : AgentState ) -> AgentState :
123
- """Finalize the agent's work and prepare the output."""
124
- logger .info (f"Finalizing ChatWithToolsAgent with state: { state } " )
125
- # Here you can add any finalization logic if needed
126
- return state
127
-
128
- def draw_mermaid_png (self ) -> bytes :
129
- """Draw the graph in Mermaid format."""
130
- return self .create_graph ().get_graph ().draw_mermaid_png ()
131
-
132
110
133
111
graph = ChatWithToolsAgent ().create_graph ()
0 commit comments