feat(agent): surface the run's artist_account_id in the agent system prompt
Part of recoupable/chat#1837 (primary fix). Base: main.
Problem
Every scheduled run passes artistId (customer-prompt-task → POST /api/chat/runs), but the value stops at session provisioning — 0 occurrences in buildRunAgentInput/runAgentWorkflow/runAgentStep. The interactive chat injects artist_account_id into its system prompt (getSystemPrompt.ts:44); the headless prompt (buildAgentSystemPrompt) had only env + custom instructions. Result: agents roster-guess, nondeterministically hit the org-scoped artist list, and conclude the artist doesn't exist.
Benchmark evidence (#1837 comment): across 2 rounds of Steph@OneRPM's 3 tasks — id-embedded prompt 2/2 delivered; implicit-artist prompts 1/4 (chats fd8e8b26, aa4eb91f, 4fa700b5 all declared the artist missing while it sat in the personal roster).
Fix
buildAgentSystemPromptgainsartistId?/accountId?→ emits, when present:# IMPORTANT CONTEXT VALUES (use these exact values in tools)
- artist_account_id: <id> (the active artist for this run — use for /api/artists/{id}/* and roster operations; do NOT search the roster for it)
- account_id: <id>- Threaded
artistIdthroughBuildRunAgentInputParams→RunAgentWorkflowInput→RunAgentStepInput(+ declaredaccountIdon the step input). - Headless:
handleStartChatRunpasses the validatedartistId. Interactive:handleChatWorkflowStreampassessession.artist_id(sessions already carry it).
Tests (TDD)
- RED→GREEN on
buildAgentSystemPrompt: emits the context block with both ids; omits it when neither is provided. - Full
lib/chat+app/lib/workflowssuites green (570); tsc adds no new errors (2 pre-existing baseline); eslint clean.
Preview verification to follow: re-run the implicit-artist Cosculluela prompt verbatim on the preview — Done-when is the agent using the injected artist_account_id instead of roster-guessing.
🤖 Generated with Claude Code
Summary by cubic
Injects the run’s artist_account_id (and account_id) into the agent system prompt and threads artistId through the workflow to stop roster-guessing in headless runs, matching interactive chat behavior.
- Bug Fixes
buildAgentSystemPromptadds an “IMPORTANT CONTEXT VALUES” block when ids are present.- Threaded
artistIdviabuildRunAgentInput→RunAgentWorkflowInput→runAgentStep. handleStartChatRunpasses the validatedartistId;handleChatWorkflowStreampassessession.artist_id.- Tests cover inclusion/omission of the context block; suites pass.