Skip to content

feat(crewai): add Stagehand code-mode MCP example - #2628

Open
shrey150 wants to merge 2 commits into
shrey/stg-2765-codemode-mastrafrom
shrey/stg-2765-codemode-crewai
Open

feat(crewai): add Stagehand code-mode MCP example#2628
shrey150 wants to merge 2 commits into
shrey/stg-2765-codemode-mastrafrom
shrey/stg-2765-codemode-crewai

Conversation

@shrey150

@shrey150 shrey150 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Why

The code-mode MCP should be proven through framework-native clients before the package is published. This layer ports the CrewAI draft beside the canonical Stagehand implementation so the Python adapter can be tested without waiting for a separate package release.

Stack

  1. #2597 — private package and tool-free MCP host
  2. #2619code_execute, executor, configuration, and runtime tests
  3. #2620 — canonical skill, reference, generated exports, and loading checks
  4. #2626 — Vercel AI SDK adapter and smoke flows
  5. #2627 — Mastra adapter and smoke flows
  6. This PR — CrewAI adapter and smoke flows
  7. #2629 — LangChain Deep Agents adapter and smoke flows

What changed

  • adds a private package-local CrewAI example
  • launches the canonical compiled Stagehand MCP through CrewAI's context-managed stdio adapter
  • exposes exactly code_execute and uses the canonical Stagehand skill as agent guidance
  • keeps one MCP adapter open for the complete crew execution so browser state survives across calls
  • inherits both local and Browserbase configuration, including the optional project identifier
  • adds a dedicated local-browser CI smoke job with Python 3.12

E2E Test Matrix

Command / flow Observed output Confidence / sufficiency
Canonical integrations build 4 build tasks passed and rebuilt dist/codemode/stdio-server.mjs. Confirms the example exercised the exact local MCP build under review.
ruff format --check and ruff check over the Python example Both files were formatted and all checks passed. Confirms the adapter and smoke satisfy Python formatting and static lint rules.
CrewAI MCP smoke with STAGEHAND_BROWSER=local code_execute ran twice; the second call observed the same page title and DOM marker; the adapter exited cleanly. Proves discovery, execution, persistent state, and cleanup with a real local browser.
CrewAI MCP smoke with STAGEHAND_BROWSER=browserbase code_execute ran twice against the same remote page and retained its DOM marker and title. Proves Browserbase credentials and project configuration reach the canonical child and the remote browser is reused.
Real CrewAI agent with an OpenAI-compatible model and Browserbase startup The agent made exactly two code_execute calls; the second retained the remote page title and marker, and the agent returned CREWAI_PERSISTENCE_PASS. Proves the real model loop, CrewAI MCP adapter, canonical guidance, and Browserbase work together.
Process cleanup audit No matching stdio child remained after the local, Browserbase, or model-driven flows. Confirms normal adapter teardown closes the owned MCP child.

Changeset

None. This adds a private example and test surface without changing a published package.

@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6959607

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@socket-security

socket-security Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedpypi/​crewai-tools@​1.15.1273100100100100
Addedpypi/​crewai@​1.15.1291100100100100

View full report

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found and verified against the latest diff

Confidence score: 5/5

  • In packages/integrations/examples/crewai/agent.py (build_stagehand_agent and run_stagehand_agent), duplicating the default model literal while docs/smoke use a different model can cause config drift and confusing example behavior over time; centralize the default in one constant and align the docs/smoke reference to it.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/integrations/examples/crewai/agent.py">

<violation number="1" location="packages/integrations/examples/crewai/agent.py:49">
P3: The default LLM model string `openai/gpt-5-mini` is duplicated as a literal on both `build_stagehand_agent` and `run_stagehand_agent`, and the docs/smoke use a different literal (`openai/gpt-4o-mini`). Because there is no single source of truth, the default can drift between the two helpers and the examples. Consider hoisting it to a module-level constant (e.g. `DEFAULT_STAGEHAND_LLM`) used by both functions and referenced in the README, so the model name stays consistent.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


def build_stagehand_agent(
tools: Sequence[BaseTool],
llm: str | Any = "openai/gpt-5-mini",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The default LLM model string openai/gpt-5-mini is duplicated as a literal on both build_stagehand_agent and run_stagehand_agent, and the docs/smoke use a different literal (openai/gpt-4o-mini). Because there is no single source of truth, the default can drift between the two helpers and the examples. Consider hoisting it to a module-level constant (e.g. DEFAULT_STAGEHAND_LLM) used by both functions and referenced in the README, so the model name stays consistent.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/integrations/examples/crewai/agent.py, line 49:

<comment>The default LLM model string `openai/gpt-5-mini` is duplicated as a literal on both `build_stagehand_agent` and `run_stagehand_agent`, and the docs/smoke use a different literal (`openai/gpt-4o-mini`). Because there is no single source of truth, the default can drift between the two helpers and the examples. Consider hoisting it to a module-level constant (e.g. `DEFAULT_STAGEHAND_LLM`) used by both functions and referenced in the README, so the model name stays consistent.</comment>

<file context>
@@ -0,0 +1,64 @@
+
+def build_stagehand_agent(
+    tools: Sequence[BaseTool],
+    llm: str | Any = "openai/gpt-5-mini",
+) -> Agent:
+    return Agent(
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant