feat(agentcore): enhance Browser & Code Interpreter toolkits with full session config, new tools, and telemetry#4882
Conversation
13e2d95 to
746fb54
Compare
lib/crewai-tools/src/crewai_tools/aws/bedrock/browser/browser_session_manager.py
Outdated
Show resolved
Hide resolved
746fb54 to
5bfb5fa
Compare
…ols for Browser & Code Interpreter - Add integration_source="crewai" telemetry to BrowserClient and CodeInterpreter - Add identifier param for custom browser/code interpreter sandbox selection - Browser: add GenerateLiveViewUrl, TakeControl, ReleaseControl tools - Browser: fix CDP reconnect after release_control() invalidates connection - Code Interpreter: add UploadFile, UploadFiles, InstallPackages, DownloadFile, DownloadFiles, ClearContext tools - 59 unit tests (30 browser + 29 code interpreter)
5bfb5fa to
e23da7d
Compare
|
Fixed in e23da7d — changed |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| with self._lock: | ||
| self._sync_sessions[thread_id] = (browser_client, browser) | ||
|
|
||
| return browser |
There was a problem hiding this comment.
Reconnect failure leaves session in corrupt state
Medium Severity
In reconnect_sync_browser (and reconnect_async_browser), old_browser.close() is called before attempting pw.chromium.connect_over_cdp. If reconnection fails, the exception propagates but _sync_sessions[thread_id] still references the now-closed old_browser. The session is left in a corrupt state — every subsequent browser tool call for that thread_id will operate on a dead browser object and fail, with no way to recover.
Additional Locations (1)
| start_kwargs["extensions"] = self.extensions | ||
| if self.profile_configuration is not None: | ||
| start_kwargs["profile_configuration"] = self.profile_configuration | ||
| browser_client.start(**start_kwargs) |
There was a problem hiding this comment.
Duplicated start_kwargs construction across sync and async
Low Severity
The 13-line start_kwargs construction block is identically duplicated between _create_async_browser_session and _create_sync_browser_session. If a new session config parameter is added, both copies must be updated in lockstep — a likely source of future inconsistency bugs. This logic could be extracted into a small helper method like _build_start_kwargs.


Summary
Enhances the AWS Bedrock AgentCore Browser and Code Interpreter toolkits to expose the full SDK feature surface — session configuration with typed dataclass support, new tool capabilities, and telemetry tracking.
Telemetry
integration_source="crewai"toBrowserClientandCodeInterpreterconstructors for customer acquisition tracking via User-Agent headerSession Configuration Passthrough (with SDK Typed Dataclass Support)
Expose all
start()parameters so users can configure sessions at toolkit creation time. Previously onlyidentifierwas supported — all other SDK options were silently ignored.All config parameters accept both SDK typed dataclasses and plain dicts, matching the SDK's own
BrowserClient.start()signature. Typed dataclasses give users IDE autocomplete, validation at construction time, and convenience factory methods.Browser — 5 new params on
BrowserToolkit/create_browser_toolkit():session_timeout_seconds— session timeout in seconds (1–28800, default 3600)viewport—ViewportConfigurationor dict. Factory methods:.desktop_hd(),.laptop(),.mobile(), etc.proxy_configuration—ProxyConfigurationor dict. Proxy routing with optional auth via Secrets Managerextensions—list[BrowserExtension | dict]. S3-hosted browser extensionsprofile_configuration—ProfileConfigurationor dict. Persist cookies/local storage across sessionsCode Interpreter — 1 new param on
CodeInterpreterToolkit/create_code_interpreter_toolkit():session_timeout_seconds— session timeout in seconds (default 900)All params default to
None(SDK defaults apply). No validation on our side — the SDK handles it.Custom Sandbox Identifier
identifierparameter toBrowserToolkit,CodeInterpreterToolkit, andBrowserSessionManagerfor custom browser/interpreter resources (VPC, recording, Web Bot Auth).start(identifier=...)on the underlying SDK clientsNew Browser Tools (3)
GenerateLiveViewUrlTool— generate a presigned URL for live browser viewingTakeControlTool— take manual control of the browser (disables automation)ReleaseControlTool— release manual control (re-enables automation, reconnects Playwright)New Code Interpreter Tools (6)
UploadFileTool/UploadFilesTool— upload files with optional semantic descriptionsDownloadFileTool/DownloadFilesTool— download files from the sandboxInstallPackagesTool— install pip packages with optional--upgradeflagClearContextTool— reset the Python execution contextBrowser Session Manager
reconnect_sync_browser()/reconnect_async_browser()for CDP reconnection afterrelease_control()get_browser_client()/get_async_browser_client()accessors for the underlyingBrowserClientUsage Examples
Test Plan
1920x1080returned in session API response600sapplied correctly1800sapplied correctlyNote
Medium Risk
Medium risk because it changes how remote browser/interpreter sessions are created and managed (new
start()kwargs, Playwright lifecycle tracking, CDP reconnection), which can affect runtime session stability and cleanup behavior.Overview
Browser toolkit: Adds passthrough of full
BrowserClient.start()session configuration (e.g.identifier, timeouts, viewport, proxy, extensions, profile) and tags sessions withintegration_source="crewai". Introducesgenerate_live_view_url,take_control, andrelease_controltools;release_controlnow triggers a Playwright CDP reconnection via newBrowserSessionManager.reconnect_*helpers, and the manager now tracks/stops per-thread Playwright instances.Code interpreter toolkit: Tags
CodeInterpreterwithintegration_source="crewai", supportsidentifier/session_timeout_secondspassthrough tostart(), and adds tools for uploading/downloading files, installing pip packages, and clearing interpreter context.Adds comprehensive unit tests covering the new configuration forwarding, telemetry tagging, reconnection/control tools, and new code-interpreter utilities.
Written by Cursor Bugbot for commit e23da7d. This will update automatically on new commits. Configure here.