--- brief: 3 convoy: ai-agent-studio role: role-implementer title: Conversational AI agent builder status: blocked priority: P1 slice_dependencies: - brief-1-ai-workspace-tabs - brief-2-agent-registry-marketplace recommended_model: auto/coding model_tier: standard --- # Brief 3 — `Task-ai-assisted-agent-builder.md` (service slice) ## Goal Implement the provider-agnostic builder service and streaming contracts that transform an Agents-mode request into validated clarification or structured draft-patch events. UI editing and private-draft persistence remain a follow-on slice. ## Files Expected scope; confirm routing conventions before implementation. - `packages/shared/src/` — versioned builder request/event/draft-patch schemas. - `packages/ai/src/prompts/` — agent-builder prompts and structured-output instructions. - `apps/web/app/api/` or a suitable streaming tRPC boundary — workspace-authorized builder stream separate from `/api/chat`. - Adjacent service tests for validation, workspace authorization, provider abstraction, stream event ordering, and malformed output. ## Required design - The builder requests an existing model role/capability and uses provider resolution; no direct OmniRoute/provider branch exists in UI or route code. - Model output is untrusted. Only versioned zod-validated clarification and draft-patch events may affect client state. - The service emits deterministic base revision IDs and structured patches so a follow-on UI can maintain conflict-safe draft history. - Generated requested tools, channel access, activation, and workspace publication remain inert, unapproved fields in validated output. - The endpoint does not persist, publish, install, activate, or execute an agent. ## Acceptance - Outcome-oriented prompts create valid drafts or targeted clarification questions. - The service supports initial requests and follow-up refinements through validated clarification/draft-patch events. - Invalid or policy-violating model output becomes a typed error event and is never persisted. - Requested tools and access remain marked unapproved and cannot be exercised by this endpoint. - No plaintext provider secret appears in events, logs, or client payloads. - `pnpm lint && pnpm type-check && pnpm test` pass; `pnpm build` passes for changed server/AI exports. ## Prompt Read model routing, `packages/ai` provider adaptation, prompt conventions, registry contracts from Brief 2, and workspace guards. Use the existing AI SDK only as a normalized model API; keep the builder compatible with OmniRoute and other providers through the resolved model contract. Do not build the editor or draft CRUD in this brief.