Voice Agent — Pastoral Care Response Integration Plan
Summary
Integrate tradition_care_context into the Care Agent's system prompt. Fix the rag_context bug. Defer pastoral_care_responses integration until table is seeded.
Changes (4 files, post-review)
1. Fix rag_context bug — agents.py line 72
Bug: CareAgent accepts rag_context and stores it as self.rag_context but NEVER injects it into instructions. The Care Agent has been operating WITHOUT the church knowledge base since launch.
Fix:
instructions = build_care_prompt(church)
if rag_context:
instructions += f"\n\n--- KNOWLEDGE BASE ---\n{rag_context}"
super().__init__(instructions=instructions, tts=tts_descriptor, chat_ctx=chat_ctx)
2. Add load_tradition_care_context() — session.py
New async function after load_inline_faqs():
- Accepts
denomination: strandsupabase - Resolves tradition_key via
get_tradition_key_for_denomination()fromtradition_care_contexts.py - DB-first query:
SELECT context_prompt FROM tradition_care_context WHERE tradition_key = ? AND is_active = true - Python module fallback:
build_tradition_block(get_tradition_context(key)) - Universal fallback if neither found
- Cache: 15-minute TTL, key includes tradition_key to prevent cross-church contamination
- Non-fatal: returns "" on exception
3. Add parallel task — main.py _build_church_path()
Add tradition_task = load_tradition_care_context(supabase, church.get("denomination")) to the asyncio.gather() block alongside existing rag/product/faq/repeat tasks.
Pass result to CoordinatorAgent: tradition_context=tradition_context
4. Thread through handoff — agents.py
CoordinatorAgent.__init__(): Addtradition_context: str = ""param, store asself.tradition_contexttransfer_to_care(): Passtradition_context=self.tradition_contextto CareAgent constructorCareAgent.__init__(): Addtradition_context: str = ""param, inject after rag_context:
if tradition_context:
instructions += tradition_context # Already formatted with header
What NOT to do (per review)
- Do NOT add
load_pastoral_care_patterns()— table has 0 rows, defer until seeded - Do NOT add fallback phrase to
build_care_prompt()— prompt works without tradition context - Do NOT inject full response patterns into system prompt — too large, belongs in per-turn RAG
- Do NOT load all care responses at call setup — load on-demand when CareAgent activates
- Do NOT touch the handoff mechanism (transfer_to_care tuple return) — it works
- Do NOT touch TTS/voice switching — it works
Key finding: Coordinator also needs minimal tradition awareness
Inject just the tradition_avoids list into Coordinator so it doesn't say "let me arrange the Eucharist" to a Baptist caller before handoff. Full context_prompt stays with Care Agent only.
Performance impact
- Call setup: +1 parallel Supabase query (~20ms, runs alongside existing queries) = negligible
- Handoff: +0ms (tradition context already loaded, just passed through)
- CareAgent prompt: +700 tokens max (within limits)