cleaner logging slightly

This commit is contained in:
Nick Sweeting
2025-08-14 19:06:18 -07:00
parent c5d33b4537
commit 78ee73c949
2 changed files with 10 additions and 9 deletions

View File

@@ -1580,15 +1580,15 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Get action name from the action model
action_data = action.model_dump(exclude_unset=True)
action_name = next(iter(action_data.keys())) if action_data else 'unknown'
action_params = getattr(action, action_name, '') or str(action.model_dump(mode='json'))[:56].replace(
action_params = getattr(action, action_name, '') or str(action.model_dump(mode='json'))[:140].replace(
'"', ''
).replace('{', '').replace('}', '').replace("'", '').strip().strip(',')
# Ensure action_params is always a string before checking length
action_params = str(action_params)
action_params = f'{action_params[:50]}...' if len(action_params) > 54 else action_params
action_params = f'{action_params[:122]}...' if len(action_params) > 128 else action_params
time_start = time.time()
self.logger.info(f'🦾 Executing action {i + 1}/{total_actions}: {cyan}{action_name}({action_params}){reset}...')
self.logger.info(f'🦾 {cyan}[ACTION {i + 1}/{total_actions}] {action_name}({action_params})... {reset}')
result = await self.controller.act(
action=action,

View File

@@ -574,13 +574,13 @@ class BrowserSession(BaseModel):
self.logger.debug(f'🔄 AgentFocusChangedEvent received: tab_index={event.tab_index}, url={event.url}')
# Clear cached DOM state since focus changed
self.logger.debug('🔄 Clearing DOM cache...')
# self.logger.debug('🔄 Clearing DOM cache...')
if self._dom_watchdog:
self._dom_watchdog.clear_cache()
self.logger.debug('🔄 Cleared DOM cache after focus change')
# self.logger.debug('🔄 Cleared DOM cache after focus change')
# Clear cached browser state
self.logger.debug('🔄 Clearing cached browser state...')
# self.logger.debug('🔄 Clearing cached browser state...')
self._cached_browser_state_summary = None
self._cached_selector_map.clear()
self.logger.debug('🔄 Cached browser state cleared')
@@ -592,7 +592,7 @@ class BrowserSession(BaseModel):
self.logger.debug(f'🔄 Got {len(targets)} targets')
if 0 <= event.tab_index < len(targets):
target_id = targets[event.tab_index]['targetId']
self.logger.debug(f'🔄 Getting CDP session for target {target_id}...')
# self.logger.debug(f'🔄 Getting CDP session for target {target_id}...')
self.agent_focus = await self.get_or_create_cdp_session(target_id, focus=True)
self.logger.debug(f'🔄 Updated agent focus to tab {event.tab_index} (target {target_id})')
@@ -607,14 +607,15 @@ class BrowserSession(BaseModel):
timeout=2.0,
)
if test_result.get('result', {}).get('value') == 2:
self.logger.debug('🔄 ✅ Browser is responsive after focus change')
# self.logger.debug('🔄 ✅ Browser is responsive after focus change')
pass
else:
raise Exception('❌ Failed to execute test JS expression with Page.evaluate')
except Exception as e:
self.logger.error(f'🔄 ❌ Page appears crashed after focus change: {e}')
raise
self.logger.debug('🔄 AgentFocusChangedEvent handler completed successfully')
# self.logger.debug('🔄 AgentFocusChangedEvent handler completed successfully')
async def on_FileDownloadedEvent(self, event: FileDownloadedEvent) -> None:
"""Track downloaded files during this session."""