@@ -46,7 +46,6 @@ def create_graph(self):
4646 workflow = StateGraph (AgentState )
4747
4848 # Create nodes
49- workflow .add_node ("initialize" , self .initialize )
5049 workflow .add_node ("chat_with_tools" , self .chat_with_tools )
5150 workflow .add_node (
5251 "tools" ,
@@ -57,35 +56,24 @@ def create_graph(self):
5756 ]
5857 ),
5958 )
60- workflow .add_node ("finalize" , self .finalize )
6159
6260 # Create edges
63- workflow .set_entry_point ("initialize" )
64- workflow .add_edge ("initialize" , "chat_with_tools" )
61+ workflow .set_entry_point ("chat_with_tools" )
6562 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+ },
7469 )
7570 workflow .add_edge ("tools" , "chat_with_tools" )
76- workflow .add_edge ("finalize" , END )
7771
7872 # Compile the graph
7973 return workflow .compile (
8074 name = ChatWithToolsAgent .__name__ ,
8175 )
8276
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-
8977 def chat_with_tools (self , state : AgentState ) -> AgentState :
9078 """Chat with tools using the state."""
9179 logger .info (f"Chatting with tools using state: { state } " )
@@ -119,15 +107,5 @@ def route_tools(
119107 return "tools"
120108 return END
121109
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-
132110
133111graph = ChatWithToolsAgent ().create_graph ()
0 commit comments