-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(crewai): add Stagehand code-mode MCP example #2628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shrey150
wants to merge
19
commits into
shrey/stg-2765-codemode-mastra
Choose a base branch
from
shrey/stg-2765-codemode-crewai
base: shrey/stg-2765-codemode-mastra
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
eb1cc57
feat(crewai): add Stagehand code-mode MCP example
shrey150 6959607
Merge updated Mastra integration parent
shrey150 b4013ab
Merge updated Mastra integration parent
shrey150 82d6c0d
Merge updated Mastra integration parent
shrey150 6f6668d
Merge refreshed Mastra integration parent
shrey150 1353b83
docs: sandbox the CrewAI code-mode MCP
shrey150 1143cd5
fix: preserve CI Chrome launch settings
shrey150 40f8b45
fix: harden sandbox bridge lifecycle
shrey150 93ab5b1
Merge remote-tracking branch 'origin/shrey/stg-2765-codemode-mastra' …
shrey150 0d7cfd7
refactor(crewai): use sandboxed code-mode MCP
shrey150 d3abc46
Merge latest Mastra parent into CrewAI
shrey150 b9172e4
fix(crewai): gate live proof on credentials
shrey150 214526c
Merge latest Mastra review fixes into CrewAI
shrey150 60e1c45
fix(crewai): harden sandbox lease and adapter contracts
shrey150 f1431f6
Merge latest Mastra review fixes into CrewAI
shrey150 0d1ce95
Merge latest Mastra contract tests into CrewAI
shrey150 e1b860e
fix(crewai): harden cancellation and teardown edges
shrey150 7b468a8
Merge deterministic Mastra stack test into CrewAI
shrey150 73911f3
fix(crewai): close lifecycle review gaps
shrey150 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
.github/actions/detect-codemode-live-credentials/action.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: Detect code-mode live credentials | ||
| description: Decide whether Browserbase, Vercel, and optional OpenAI live proofs can run. | ||
|
|
||
| inputs: | ||
| require-openai: | ||
| description: Require OPENAI_API_KEY in addition to Browserbase and Vercel credentials. | ||
| default: "false" | ||
|
|
||
| outputs: | ||
| available: | ||
| description: Whether every credential required by the live proof is available. | ||
| value: ${{ steps.detect.outputs.available }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - id: detect | ||
| shell: bash | ||
| env: | ||
| REQUIRE_OPENAI: ${{ inputs.require-openai }} | ||
| run: | | ||
| browserbase_ready=false | ||
| vercel_ready=false | ||
| openai_ready=false | ||
|
|
||
| if [[ -n "$BROWSERBASE_API_KEY" && -n "$BROWSERBASE_PROJECT_ID" ]]; then | ||
| browserbase_ready=true | ||
| fi | ||
| if [[ -n "$VERCEL_TOKEN" ]]; then | ||
| if [[ -n "$VERCEL_TEAM_ID" && -n "$VERCEL_PROJECT_ID" ]]; then | ||
| vercel_ready=true | ||
| fi | ||
| elif [[ -n "$VERCEL_OIDC_TOKEN" ]]; then | ||
| vercel_ready=true | ||
| fi | ||
| if [[ "$REQUIRE_OPENAI" != "true" || -n "$OPENAI_API_KEY" ]]; then | ||
| openai_ready=true | ||
| fi | ||
|
|
||
| if [[ "$browserbase_ready" == "true" && "$vercel_ready" == "true" && "$openai_ready" == "true" ]]; then | ||
| echo "available=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "available=false" >> "$GITHUB_OUTPUT" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # CrewAI with Stagehand code mode | ||
|
|
||
| This example gives a CrewAI agent one browser tool, `code_execute`, without running generated | ||
| JavaScript in the Python agent process. A small trusted Python lease owner starts the | ||
| package-installed [Vercel Sandbox example](../vercel-sandbox) and receives its `{ url, token }` | ||
| connection. CrewAI then connects directly through authenticated Streamable HTTP: | ||
|
|
||
| ```text | ||
| CrewAI MCPServerAdapter -> authenticated HTTPS -> Vercel Sandbox -> Stagehand code-mode MCP | ||
| `-> generated JavaScript | ||
| ``` | ||
|
|
||
| The adapter discovers the canonical tool description and uses it as the agent's backstory. It does | ||
| not copy the executor, schema, or code-mode skill. | ||
|
|
||
| ## Setup | ||
|
|
||
| Create a Python 3.12 environment and install the pinned CrewAI example dependencies: | ||
|
|
||
| ```bash | ||
| python3.12 -m venv .venv | ||
| . .venv/bin/activate | ||
| python -m pip install -r packages/integrations/examples/crewai/requirements.txt | ||
| ``` | ||
|
|
||
| Build and pack the exact Stagehand packages under review: | ||
|
|
||
| ```bash | ||
| pnpm install | ||
| pnpm --filter @browserbasehq/stagehand-integrations-example-vercel-sandbox pack:artifacts | ||
| ``` | ||
|
|
||
| ## Run the end-to-end proof | ||
|
|
||
| ```bash | ||
| STAGEHAND_SANDBOX_ARTIFACTS="$PWD/packages/integrations/examples/vercel-sandbox/.artifacts" \ | ||
| BROWSERBASE_API_KEY=<api-key> \ | ||
| BROWSERBASE_PROJECT_ID=<project-id> \ | ||
| VERCEL_OIDC_TOKEN=<oidc-token> \ | ||
| OPENAI_API_KEY=<openai-key> \ | ||
| python packages/integrations/examples/crewai/e2e.py | ||
| ``` | ||
|
|
||
| For external CI, replace `VERCEL_OIDC_TOKEN` with `VERCEL_TEAM_ID`, `VERCEL_PROJECT_ID`, and | ||
| `VERCEL_TOKEN`. Set `CREWAI_MODEL` in your own wrapper if you want to pass a model other than the | ||
| example's `openai/gpt-5-mini` default. | ||
|
|
||
| The proof uses one live package-installed sandbox and one context-managed CrewAI MCP adapter. It: | ||
|
|
||
| 1. invokes `code_execute` twice directly and requires the same page ID and DOM marker; | ||
| 2. records CrewAI's tool-usage event from a real model-selected `code_execute` call; | ||
| 3. invokes the tool again to independently verify the model's browser-side change; | ||
| 4. proves the model key and a host-only marker are absent inside generated code; and | ||
| 5. closes the CrewAI MCP adapter before ending the sandbox lease, emitting `PASS` only afterward. | ||
|
|
||
| ## Use the agent | ||
|
|
||
| Run the snippet with the example directory as the working directory so its local `agent.py` and | ||
| `sandbox.py` modules resolve: | ||
|
|
||
| ```bash | ||
| cd packages/integrations/examples/crewai | ||
| ``` | ||
|
|
||
| ```python | ||
| from agent import run_stagehand_agent | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| from sandbox import StagehandSandboxLease | ||
|
|
||
| with StagehandSandboxLease() as connection: | ||
| result = run_stagehand_agent( | ||
| connection, | ||
| "Open https://example.com and return its title and URL.", | ||
| ) | ||
| print(result) | ||
| ``` | ||
|
|
||
| The lease subprocess receives only Browserbase, Vercel, artifact, and runtime variables from its | ||
| allowlist. Outer model-provider credentials are intentionally excluded, and the sandbox foundation | ||
| brokers the Browserbase credential at its egress boundary. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.