fix(prompts): consolidate routing guidance and correct runtime claims - #5
Merged
Conversation
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Optimize pi-flow's coordinator prompt design using the approved behavior baseline and real Pi-session evidence while preserving the public Agent and workflow contracts. Keep routing profile-agnostic: root-direct work, focused or small flat direct Agent delegation, and workflow for saved, staged, structured, replay, or larger orchestration; reuse session_key only for the same logical child stream. Treat focused delegation as a soft expectation and do not encode or test profile names, models, specialist selection, or defaults. Consolidate duplicated prompt guidance, make injected guidance reflect only active tools, correct dynamic-schema and saved-workflow runtime claims, replace prose-driven synthetic routing tests with deterministic behavior anchors, and add a privacy-safe opt-in real-model routing regression path and honest before/after evidence. Preserve unrelated runtime APIs and behavior, never include private session history, credentials, or machine-specific paths, and ship through review, tests, documentation validation, push, PR, and green CI without merging.
What Changed
src/prompts.ts; injected sections now reflect only the tools actually active (agent-only, workflow-only, both, or neither), correcting incorrect dynamic-schema and saved-workflow filename claims that were in the prior prompttest/proactive-routing.test.ts) with deterministic behavior anchors covering tool-gating, profile deduplication, and session-key continuation contract acrosstest/agent-contract.test.tsand the newtest/delegation-scenarios.test.tsscripts/e2e/prompt-routing.mjs) with committed before/after evidence (scripts/e2e/prompt-routing-evidence.md) documenting the accepted routing boundary and variance limitationsRisk Assessment
✅ Low: The change is a well-bounded prompt-text refactor and test realignment: it consolidates two builders into one, gates guidance on active tools (verified by deterministic unit tests), corrects the dynamic-schema and filename claims that were previously wrong, and replaces synthetic prompt-matching routing tests with behavioral anchors — with no changes to any runtime API or execution path.
Testing
Ran the two test files that directly exercise the changed prompt-building logic (11 tests across agent-contract and delegation-scenarios suites) — all passed. Supplemented with a direct behavioral snapshot of
buildFlowPromptconfirming every key user-intent constraint: routing boundary present exactly once, correct tool-gating, corrected dynamic-schema and filename claims, and accurate session_key guidance.Evidence: Targeted test run + behavioral anchor verification
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
src/prompts.ts:87-buildFlowPromptis exported but has no internal guard for the{ agentActive: false, workflowActive: false }case. If called with both false it emits a# Subagent Delegationheader with a profile roster but no tool-specific guidance sections — a semantically incomplete fragment. The only production call site (pi-subagent.ts:708) is correctly guarded and the test forneitherpasses through the early-return in the handler rather than throughbuildFlowPromptitself.✅ **Test** - passed
✅ No issues found.
npx vitest run test/agent-contract.test.ts test/delegation-scenarios.test.ts --reporter=verboseDirectbuildFlowPromptsnapshot: verified routing policy constants, section gating (both/agent-only/workflow-only/neither), profile deduplication, corrected dynamic-schema claim, corrected saved-workflow filename claim, and session_key parallel-branches guidance✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.