feat(langchain): add Stagehand code-mode MCP example - #2629
Conversation
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…into shrey/stg-2765-codemode-langchain
…into shrey/stg-2765-codemode-langchain
…into shrey/stg-2765-codemode-langchain # Conflicts: # .github/workflows/codemode-framework-examples.yml # packages/integrations/README.md
There was a problem hiding this comment.
1 issue found across 8 files (changes from recent commits).
Confidence score: 5/5
- In
packages/integrations/examples/langchain/agent.py, the newbuild_stagehand_agent,run_stagehand_agent, andstagehand_code_sessionpaths are not covered by focused unit tests, so behavior regressions in agent construction or session scoping could slip through unnoticed; add targeted tests for these flows (including success and failure/session-boundary cases) to de-risk future changes.
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/langchain/agent.py">
<violation number="1" location="packages/integrations/examples/langchain/agent.py:63">
P3: The newly added agent-construction and session-scoping paths (`build_stagehand_agent`, `run_stagehand_agent`, `stagehand_code_session`) have no focused unit tests — the existing tests cover only the client shape, tool-description validation, and the tool-call counter. These paths are currently validated only through the live, model-dependent e2e. Adding focused tests that verify `build_stagehand_agent` passes the tool description as the system prompt, rejects non-`code_execute` tools, and that `stagehand_code_session` scopes the loaded tool to one session would encode the contract and protect against regressions independently of the flaky real-model run.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| yield await load_stagehand_code_tool(session) | ||
|
|
||
|
|
||
| def build_stagehand_agent( |
There was a problem hiding this comment.
P3: The newly added agent-construction and session-scoping paths (build_stagehand_agent, run_stagehand_agent, stagehand_code_session) have no focused unit tests — the existing tests cover only the client shape, tool-description validation, and the tool-call counter. These paths are currently validated only through the live, model-dependent e2e. Adding focused tests that verify build_stagehand_agent passes the tool description as the system prompt, rejects non-code_execute tools, and that stagehand_code_session scopes the loaded tool to one session would encode the contract and protect against regressions independently of the flaky real-model run.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/integrations/examples/langchain/agent.py, line 63:
<comment>The newly added agent-construction and session-scoping paths (`build_stagehand_agent`, `run_stagehand_agent`, `stagehand_code_session`) have no focused unit tests — the existing tests cover only the client shape, tool-description validation, and the tool-call counter. These paths are currently validated only through the live, model-dependent e2e. Adding focused tests that verify `build_stagehand_agent` passes the tool description as the system prompt, rejects non-`code_execute` tools, and that `stagehand_code_session` scopes the loaded tool to one session would encode the contract and protect against regressions independently of the flaky real-model run.</comment>
<file context>
@@ -3,120 +3,105 @@
+ yield await load_stagehand_code_tool(session)
+
+
+def build_stagehand_agent(
+ code_tool: BaseTool,
+ model: str | Any = DEFAULT_STAGEHAND_MODEL,
</file context>
There was a problem hiding this comment.
Addressed in c29ce4a8. The focused suite now verifies canonical tool-description → system-prompt wiring, rejects non-code_execute tools without reflecting remote names, proves one named MCP session owns the loaded tool, and exercises run_stagehand_agent input/config wiring. The exact pinned environment passes 9/9 agent/session tests.
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
## Why The code-mode product work spans three distinct review domains: process hosting, browser code execution, and agent guidance. This bottom PR isolates the package and Model Context Protocol (MCP) host so its build, transport, and shutdown behavior can be reviewed without the execution engine or prompt content. ## Stack 1. **This PR:** private package, MCP stdio host, lifecycle, repository build/test wiring 2. #2619: Stagehand executor, local and Browserbase configuration, schemas, queueing, and `code_execute` registration 3. #2620: `SKILL.md`, `REFERENCE.md`, generated exports, package assets, and guidance loading checks 4. [#2626](#2626) — Vercel AI SDK MCP example and smoke flows 5. [#2627](#2627) — Mastra MCP example and smoke flows 6. [#2628](#2628) — CrewAI MCP example and smoke flows 7. [#2629](#2629) — LangChain Deep Agents MCP example and smoke flows Each PR is intended to build, test, and make a truthful claim independently. ## What changed - adds the private `@browserbasehq/stagehand-integrations` workspace package - adds a compiled stdio entrypoint backed by the MCP SDK - negotiates MCP server metadata without advertising capabilities that do not exist yet - bounds concurrent shutdown cleanup to five seconds - preserves conventional process exit codes for `SIGINT` and `SIGTERM` - wires the package into workspace, Turbo, Vitest, and CI discovery ## Intentionally not included - no MCP tools - no browser or model configuration - no Stagehand executor - no skill or reference content - no published package surface; the package remains private ## E2E Test Matrix | Command / flow | Observed output | Confidence / sufficiency | | --- | --- | --- | | `pnpm --filter @browserbasehq/stagehand-integrations typecheck && pnpm --filter @browserbasehq/stagehand-integrations build && pnpm --filter @browserbasehq/stagehand-integrations test:unit` | Package typecheck and build passed; 3 test files and 9 tests passed. | Covers host construction, bounded cleanup, compiled stdio startup, end-of-file shutdown, and signal exit codes. It intentionally does not prove a tool or browser session. | | Manual MCP client connected to the compiled stdio entrypoint | `{"initialized":true,"toolsCapability":null,"readyMessage":true}` | Proves the built artifact starts as a child process, negotiates MCP, emits its readiness message, and truthfully advertises no tools. | | `pnpm exec turbo run test:unit --filter=@browserbasehq/stagehand-integrations` | 2/2 Turbo tasks passed; package build plus 9/9 tests passed. | Proves the repository task graph builds the package before compiled-child tests. | | `pnpm check` | 9/9 repository tasks passed. | Supports repository-wide formatting, lint, and type compatibility for this layer. | ## Changeset None. This introduces a private workspace package and does not publish a release. --------- Co-authored-by: miguel <miguelg71921@gmail.com>
Why
Stagehand code mode executes model-generated JavaScript. This integration keeps that execution behind the package-installed Vercel Sandbox boundary from #2626 while preserving the explicit stateful MCP session LangChain requires.
Stack
@browserbasehq/stagehand-codemodepackage and CLIWhat changed
MultiServerMCPClientover authenticated Streamable HTTP{ url, token }connectionclient.session("stagehand")across discovery, direct calls, and the complete Deep Agent invocation; the default convenience path is intentionally not used because it is statelesscode_executedescription and uses it as the Deep Agent system prompt instead of copying the schema, executor, or skillProof matrix
sandboxandagentimports resolve.pnpm checkopenai:gpt-5-minimodel-selected call, independent DOM verification, credential isolation, and ordered cleanup before emittingPASS.The live job intentionally fails closed when repository Browserbase, Vercel, or OpenAI credentials are absent. Repository Vercel credentials are not currently configured for this workflow, so no live pass is claimed yet.
Changeset
None. This adds an integration example and CI proof surface without changing a published API.