Skip to content

Commit e0ba9da

Browse files
committed
some changes on the system prompt and agent class
1 parent a3cb558 commit e0ba9da

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
browser_instance_dir = os.getenv('BROWSER_INSTANCE_DIR')
1111
user_data_dir = os.getenv('USER_DATA_DIR')
1212

13-
llm=ChatGemini(model='gemini-2.0-flash',api_key=api_key,temperature=0)
13+
llm=ChatGemini(model='gemini-2.5-flash',api_key=api_key,temperature=0)
1414
config=BrowserConfig(browser='edge',browser_instance_dir=browser_instance_dir,user_data_dir=user_data_dir,headless=False)
1515

16-
agent=WebAgent(config=config,llm=llm,verbose=True,use_vision=False,max_iteration=100)
16+
agent=WebAgent(config=config,llm=llm,verbose=True,use_vision=True,max_iteration=100)
1717
user_query = input('Enter your query: ')
1818
agent.print_response(user_query)

src/agent/web/__init__.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

src/agent/web/prompt/system.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ At every step, Web Agent will be given the state:
6060

6161
Web Agent must follow the following rules while browsing the web:
6262

63-
1. ALWAYS start solving the given query using the appropirate search domains like google, youtube, wikipaedia, ...etc.
63+
1. ALWAYS start solving the given query using the appropirate search domains like google, youtube, wikipaedia, twitter ...etc.
6464
2. When performing deep research make sure conduct it in a seperate tab using `Tab Tool` and not on the current working tab.
6565
3. If any banners or ads those are obstructing the way close it and accept cookies if you see in the page.
6666
4. If a captcha appears, attempt solving it if possible or else use fallback strategies (ex: go back, alternative site).

0 commit comments

Comments
 (0)