feat(integrations): extract Claude Agent SDK harness adapter from evals - #2748
feat(integrations): extract Claude Agent SDK harness adapter from evals#2748miguelg719 wants to merge 3 commits into
Conversation
|
There was a problem hiding this comment.
All reported issues were addressed across 21 files
Architecture diagram
sequenceDiagram
participant Evals as Evals Harness
participant Adapter as Claude Agent SDK Adapter
participant SDK as Anthropic Claude Agent SDK
participant Runtime as Agent Tool Runtime
participant MCP as In-process MCP Server
participant Logger as Harness Logger
participant Verifier as Verifier Service
Note over Evals,Verifier: Claude Agent SDK Integration Flow
Evals->>Adapter: runClaudeAgentSession(prompt, config)
Adapter->>SDK: query() with options
SDK-->>Adapter: Stream messages
Adapter->>Adapter: Log message & track tool usage
loop Message stream
Adapter->>Adapter: Check message type
alt Assistant message with tool_use
Adapter->>Adapter: Map tool_use_id to name
else User message with tool_result
Adapter->>Evals: onToolResult(toolName)
else Result message
Adapter->>Adapter: Extract resultText & token usage
end
SDK->>MCP: Call run tool (mcp__stagehand__run)
MCP->>Runtime: Execute snippet with handles
Runtime->>Runtime: Wrap handles + startUrl + task
Runtime-->>MCP: Tool result
MCP-->>SDK: Serialized result
end
Adapter->>Adapter: Classify status (completed/max_turns/sdk_error)
Adapter-->>Evals: Return session result
alt Verifier configured
Evals->>Evals: Build trajectory from messages
Evals->>Verifier: Grade trajectory
Verifier-->>Evals: Evaluation result
end
Evals->>Evals: Build TaskResult with metrics & observations
Note over Evals,Adapter: Mount Session Prep (parallel path)
Evals->>Adapter: prepareClaudeMountSession(mount, context)
Adapter->>Adapter: Create temp cwd
alt Handle-based mount
Adapter->>MCP: buildRunMcpServer(handles, runTool)
MCP->>MCP: Create run tool with executeSnippet
MCP-->>Adapter: MCP server spec
Adapter->>Adapter: Allowlist [run_tool_name]
else MCP-based mount
Adapter->>Adapter: Pass through mcpServers
Adapter->>Adapter: Derive mcp__<server> allowlist
end
Adapter->>Adapter: Configure canUseTool gate
alt allowBash option set
Adapter->>Adapter: Add Bash to allowedTools
else Deny by default
Adapter->>Adapter: Bash denied with denyMessage
end
Adapter-->>Evals: Prepared session (cwd, env, tools, cleanup)
Evals->>Adapter: cleanup() on completion
Adapter->>Adapter: Remove temp cwd (idempotent, timeout-bound)
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
New thin package @browserbasehq/stagehand-integrations-claude-agent-sdk: loadClaudeAgentSdk + runClaudeAgentSession — the query() streaming loop (abort control, message logging, token usage, status/stop-reason) with explicit options and no EVAL_* env reads. This is the code the evals claude_code runner and the claude-code facade example were both maintaining; both now call the package. Deliberately NOT extracted: the tool-surface mount machinery (AgentMount handling, the in-process run MCP tool, permission gate derivation) stays in evals — it abstracts over evals' surface registry and has no integrations consumer.
c0dffa8 to
da0bd1b
Compare
|
Connected smoke on the reshaped code (restored evals mount machinery + thin session package): |
…redaction, drop unused vitest config - remove the abort forwarder on session completion so long-lived caller signals don't accumulate listeners (cubic P2) - pass iteration errors through sanitizeErrorMessage before they reach stop reasons and logs (cubic P1) - delete the package vitest.config.ts: tests run through the repo-root config via --root (cubic P3)
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Stacked on #2746 (← #2743). Part 2 of the harness consolidation stack. Reshaped after review feedback: thin session layer only.
What
New thin package
@browserbasehq/stagehand-integrations-claude-agent-sdk:loadClaudeAgentSdk+runClaudeAgentSession— thequery()streaming loop (abort control, message logging, token usage, status/stop-reason, max-turns classification) with explicit options and noEVAL_*env reads. This is the code the evalsclaude_coderunner and the claude-code facade example were both maintaining; both now call the package.Deliberately NOT extracted (returned to evals verbatim after the first cut over-reached): the tool-surface mount machinery —
AgentMounthandling, the in-processrunMCP tool over live handles, permission-gate derivation. That code abstracts over evals' surface registry and has no integrations consumer.Net diff +661/−515 — the positive remainder is package scaffolding (package.json/tsconfig/tsdown/vitest/turbo/CI globs); the logic itself is a move.
Verification
b:webvoyager --harness claude_code --tool stagehand_code -e browserbase) re-run on the reshaped code — results in PR commentcanUseTool, deny everything else)