Thread spawn model from request through to the spawn event#180
Conversation
Adds an optional `model` to the agent spawn path so a caller (e.g. the Agent Relay `add_agent` MCP tool) can choose the model a spawned worker boots with. Previously `model` had nowhere to travel: it was only stored as agent metadata and never reached the broker that launches the CLI. - SpawnAgentRequestSchema (types/agent.ts): accept optional `model`. - AgentSpawnRequestedEventSchema (types/events.ts): carry `model` on the emitted event's agent payload. - /v1/agents/spawn route: read `model`, fold it into the agent metadata (so it stays visible via list_agents) and include it in the spawn event data. - wsTransform: pass `model` through on agent.spawn_requested. - sdk-rust: add `model` to SpawnAgentRequest and AgentSpawnRequestedPayload. The TS SDK `agents.spawn` forwards the whole request body, so it picks up `model` automatically once the type includes it. Verified: `packages/types` tsc clean; `sdk-rust` cargo check clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
📝 WalkthroughWalkthroughThis PR extends agent spawn request and event handling to include an optional ChangesAgent Spawn Model Field
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces support for a model parameter when spawning an agent. It updates the TypeScript/Zod and Rust schemas, persists the requested model into the agent's metadata, and includes it in WebSocket spawn events. Additionally, Python SDK tests are updated to dynamically reference the SDK version instead of using hardcoded version strings. A review comment suggests using a strict undefined check (model !== undefined) instead of a truthiness check when merging the model into the metadata to ensure that explicit falsy values (like null or empty strings) are correctly persisted.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| metadata, | ||
| // Persist the requested model into agent metadata so it is visible via | ||
| // list_agents, in addition to being emitted on the spawn event below. | ||
| metadata: model ? { ...(metadata ?? {}), model } : metadata, |
There was a problem hiding this comment.
Using a truthiness check (model ? ...) will prevent explicitly passed falsy values (such as null or an empty string "") from being persisted in the agent's metadata. Since model is optional and nullable (z.string().nullable().optional()), checking model !== undefined is more robust and ensures that explicit null or empty string values are correctly propagated and stored.
| metadata: model ? { ...(metadata ?? {}), model } : metadata, | |
| metadata: model !== undefined ? { ...(metadata ?? {}), model } : metadata, |
The Rust SDK build broke after adding `model` to SpawnAgentRequest: the broker self-registration path (registration.rs) and the parity test both construct the struct with explicit fields. Add `model` to both. - registration.rs: `model: None` (worker-session auto-registration has no caller-chosen model). - parity.rs: set `model` and assert it appears in the serialized /v1/agents/spawn body, proving the field flows through the request. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/engine/src/routes/agent.ts`:
- Around line 351-354: The metadata persistence uses a truthy check that drops
valid empty-string models; change the conditional in the object construction
that sets metadata to use a nullish check so empty strings remain persisted
(i.e., replace the existing "model ? { ...(metadata ?? {}), model } : metadata"
logic with a nullish-aware check using model ?? to decide whether to include
model in metadata), updating the code around the metadata assignment so
persisted metadata and the emitted spawn event use the same model presence
semantics.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9cb54c96-b064-458c-a1fa-35a1a77771d1
📒 Files selected for processing (9)
packages/engine/src/engine/wsTransform.tspackages/engine/src/routes/agent.tspackages/sdk-python/tests/test_imports.pypackages/sdk-python/tests/test_ws.pypackages/sdk-rust/src/registration.rspackages/sdk-rust/src/types.rspackages/sdk-rust/tests/parity.rspackages/types/src/agent.tspackages/types/src/events.ts
| // Persist the requested model into agent metadata so it is visible via | ||
| // list_agents, in addition to being emitted on the spawn event below. | ||
| metadata: model ? { ...(metadata ?? {}), model } : metadata, | ||
| }); |
There was a problem hiding this comment.
Use a nullish check when persisting model into metadata.
model ? ... drops valid empty-string inputs, while the emitted event still includes model via model ?? null. This creates inconsistent persisted vs emitted data.
Suggested fix
+ const hasExplicitModel = model !== undefined && model !== null;
const result = await agentEngine.spawnAgent(db, workspace.id, {
name,
cli,
task,
channel: channel ?? undefined,
persona: persona ?? undefined,
// Persist the requested model into agent metadata so it is visible via
// list_agents, in addition to being emitted on the spawn event below.
- metadata: model ? { ...(metadata ?? {}), model } : metadata,
+ metadata: hasExplicitModel ? { ...(metadata ?? {}), model } : metadata,
});🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/engine/src/routes/agent.ts` around lines 351 - 354, The metadata
persistence uses a truthy check that drops valid empty-string models; change the
conditional in the object construction that sets metadata to use a nullish check
so empty strings remain persisted (i.e., replace the existing "model ? {
...(metadata ?? {}), model } : metadata" logic with a nullish-aware check using
model ?? to decide whether to include model in metadata), updating the code
around the metadata assignment so persisted metadata and the emitted spawn event
use the same model presence semantics.
Problem
A caller cannot choose the model a spawned worker boots with. The Agent Relay
add_agentMCPmodelarg was only stored as agent metadata and never reached the broker that launches the CLI, so workers always booted with the session default (Opus) regardless of the requested model.Change
Threads an optional
modelthrough the spawn path:types/agent.ts—SpawnAgentRequestSchemaaccepts optionalmodel.types/events.ts—AgentSpawnRequestedEventSchemacarriesmodelon the emitted agent payload.engine/routes/agent.ts—/v1/agents/spawnreadsmodel, folds it into agent metadata (so it stays visible vialist_agents) and includes it in the spawn event data.engine/wsTransform.ts— passesmodelthrough onagent.spawn_requested.sdk-rust/types.rs—modelonSpawnAgentRequestandAgentSpawnRequestedPayload.The TS SDK
agents.spawnforwards the whole request body, so it picks upmodelautomatically once the type includes it.Verified
packages/typestsc --noEmitclean.packages/sdk-rustcargo checkclean.(engine/sdk-typescript show only pre-existing env noise — missing
better-sqlite3/wstypes and stale@relaycast/typesdist — none in the changed files.)Downstream / release
This is the gating half of a two-repo fix. The consumer is AgentWorkforce/relay (branch
fix/spawn-model-passthrough, draft), whose MCP/SDK/broker passmodelend-to-end to--model. relay consumes the published@relaycast/sdk+relaycastcrate, so after this merges it needs a relaycast publish (npm@relaycast/sdk/@relaycast/types+ therelaycastcrate), then relay bumps those deps. Note: this local checkout was behind published versions — apply onto current main before releasing.🤖 Generated with Claude Code