Manifest Builder ??? Architecture and Prompt Stack Integration

Component: agent-brain Tags: manifest-builder,agent-brain,prompt-stack,p3.5,p12.9,question-type,haiku,context-curation Author: claude Updated: 5/31/2026, 10:31:26 AM

OVERVIEW:

The manifest builder is a fast Haiku 4.5 pre-call that runs at the very start of agent-brain's handleChatRequest(), before the scratchpad and before the primary model call. Its job is to read all available context (relationship block, user profile, recent conversation) and extract only what is directly relevant to the current message.


RETURN SHAPE:

runManifestBuilder() returns { manifest, _prompts } on success, or null on failure.

manifest = { focus, question_type, context_early[], context_reinforce[], answer_guidance[] }

_prompts = debug metadata (system_prompt, user_prompt, template_key, context_sizes, llm_call, raw_response)

On failure: null (graceful degradation ??? pipeline continues unchanged).


QUESTION TYPES:

relationship_identity | emotional_support | factual_profile | presence_check | task_request | casual | general

question_type drives two downstream behaviors:

1. Scratchpad confidence gate: when manifestHasFacts=true (question_type set), the low-confidence warning injection is suppressed.

2. answer_guidance filter: for relationship_identity, guidance items containing follow-up question patterns are stripped before injection into P12.9.


PROMPT STACK INJECTION:

P3.5 ??? context_early: 1-3 background framing facts injected between P3 (relationship context) and P4 (prompt modifiers). Only injected when context_early is non-empty.

P12.9 ??? context_reinforce + answer_guidance: critical facts + guidance injected immediately before the user message (P13). Positioned last for maximum recency weight. For relationship_identity, follow-up question guidance items are filtered.


SKIP CONDITIONS (logged as detailLog.setStep skip_reason):

clarification_turn ??? a clarification question was detected upstream; manifest skipped by design.

channel_override_none ??? the channel has scratchpad_template=none; full reasoning disabled.

flag_disabled ??? ENABLE_MANIFEST_BUILDER env/config is false.


LOGGING:

Every request records a manifest_builder step in zoey.zoey_detail_log:

steps.manifest_builder.enabled ??? whether the flag is on

steps.manifest_builder.skipped ??? whether the call was skipped

steps.manifest_builder.skip_reason ??? which skip condition fired

steps.manifest_builder.template_key ??? agent.manifest-builder

steps.manifest_builder.input ??? context sizes (chars/turns)

steps.manifest_builder.output ??? the full manifest object

steps.manifest_builder.latency_ms ??? wall-clock time

steps.manifest_builder.prompt_debug ??? full prompts + LLM params + raw_response (for debugging)

steps.manifest_builder.error ??? non-null on failure


GRACEFUL DEGRADATION:

Any failure in runManifestBuilder() returns null. The caller logs WARN and continues. No P3.5/P12.9 blocks are injected. The scratchpad confidence gate reverts to its default (fires on low confidence). The user still receives a response.


FILE LOCATIONS:

agent-brain/manifest-builder.js ??? the manifest builder module

agent-brain/index.js ??? caller (handleChatRequest, buildChatMessages, buildReasoningMessages)