@@ -91,7 +91,6 @@ async def reason(self,state:AgentState):
9191 })
9292 messages = [SystemMessage (system_prompt )]+ state .get ('messages' )
9393 ai_message = await self .llm .async_invoke (messages = messages )
94- # print(ai_message.content)
9594 agent_data = extract_agent_data (ai_message .content )
9695 memory = agent_data .get ('Memory' )
9796 evaluate = agent_data .get ("Evaluate" )
@@ -128,14 +127,14 @@ async def action(self,state:AgentState):
128127 action_result = await self .registry .async_execute (action_name ,action_input ,context = self .context )
129128 observation = action_result .content
130129 if self .verbose :
131- print (colored (f'Observation: { textwrap .shorten (observation ,width = 500 )} ' ,color = 'green' ,attrs = ['bold' ]))
130+ print (colored (f'Observation: { textwrap .shorten (observation ,width = 1000 , placeholder = '...' )} ' ,color = 'green' ,attrs = ['bold' ]))
132131 if self .verbose and self .token_usage :
133132 print (f'Input Tokens: { self .llm .tokens .input } Output Tokens: { self .llm .tokens .output } Total Tokens: { self .llm .tokens .total } ' )
134- # Get the current browser state
133+ # Get the current screenshot, browser state and dom state
135134 browser_state = await self .context .get_state (use_vision = self .use_vision )
135+ current_tab = browser_state .current_tab
136136 dom_state = browser_state .dom_state
137137 image_obj = browser_state .screenshot
138- current_tab = browser_state .current_tab
139138 # Redefining the AIMessage and adding the new observation
140139 action_prompt = self .action_prompt .format (** {
141140 'memory' :memory ,
@@ -147,10 +146,6 @@ async def action(self,state:AgentState):
147146 observation_prompt = self .observation_prompt .format (** {
148147 'iteration' :self .iteration ,
149148 'max_iteration' :self .max_iteration ,
150- 'memory' :memory ,
151- 'evaluate' :evaluate ,
152- 'thought' :thought ,
153- 'action' :f'{ action_name } ({ ',' .join ([f'{ k } ={ v } ' for k ,v in action_input .items ()])} )' ,
154149 'observation' :observation ,
155150 'current_tab' :current_tab .to_string (),
156151 'tabs' :browser_state .tabs_to_string (),
@@ -189,7 +184,8 @@ async def answer(self,state:AgentState):
189184 message = AIMessage (answer_prompt )
190185 if self .verbose :
191186 print (colored (f'Final Answer: { final_answer } ' ,color = 'cyan' ,attrs = ['bold' ]))
192- return {** state ,'output' :final_answer ,'messages' :[message ]}
187+ await self .close ()
188+ return {** state ,'browser_state' :None ,'dom_state' :None ,'output' :final_answer ,'messages' :[message ],'prev_observation' :'' ,'agent_data' :{}}
193189
194190 def main_controller (self ,state :AgentState ):
195191 "Route to the next node"
@@ -243,7 +239,6 @@ async def async_invoke(self, input: str)->dict|BaseModel:
243239 }
244240 self .start_time = datetime .now ()
245241 response = await self .graph .ainvoke (state ,config = {'recursion_limit' :self .max_iteration })
246- await self .close ()
247242 self .end_time = datetime .now ()
248243 total_seconds = (self .end_time - self .start_time ).total_seconds ()
249244 if self .verbose and self .token_usage :
0 commit comments