Prompt Templates and Rendering
Related source file:
src/agentmux/workflow/prompts.py
Template directories
agentmux/prompts/agents/— role-level prompts (define what each agent is):architect.md,planner.md,product-manager.md,reviewer.md,coder.md,code-researcher.md,web-researcher.md,designer.mdagentmux/prompts/commands/— phase-specific command prompts (what to do at each step):review.md,fix.md,summary.md,change.mdagentmux/prompts/shared/— reusable prompt fragments inlined via[[shared:fragment-name]]:handoff-contract-architecture.md,handoff-contract-plan.md,handoff-contract-review.md,coder-discipline.md,preference-memory.md
Placeholder syntax
Built-in prompt templates use [[placeholder:name]] value placeholders. Built-in templates can also inline session files with:
[[include:path]]— required include; raisesFileNotFoundErrorwhen missing.[[include-optional:path]]— optional include; resolves to empty string when missing.
Render model is three-stage:
- Template loading stage:
- Expand shared fragments using
[[shared:fragment-name]]. - Inject project extension text into
[[placeholder:project_instructions]].
- Expand shared fragments using
- Render stage:
- Resolve
[[placeholder:name]]values from the active prompt builder context.
- Resolve
- Session include expansion stage:
- Resolve
[[include:path]]/[[include-optional:path]]againstfeature_dir. - Include expansion runs after placeholder rendering, so include paths can contain placeholders (for example
[[include:[[placeholder:plan_file]]]]).
- Resolve
Every prompt builder provides feature_dir as the session directory and references workflow files with phase subpaths (for example 04_planning/plan.md, 07_review/review.md, state.json). Builders that need project-level context (for example product manager and coder) also provide project_dir.
Project-specific prompt extensions
Projects can extend built-in prompt templates with plain markdown files in:
.agentmux/prompts/agents/<role>.md.agentmux/prompts/commands/<command>.md
The prompt loader merges project content into the matching built-in template via [[placeholder:project_instructions]]. If a project file does not exist, [[placeholder:project_instructions]] resolves to an empty string and behavior stays unchanged.
Project extension files are plain markdown. They do not need template placeholder syntax. Curly braces in project content stay literal; only [[placeholder:...]] markers are rendered.
agentmux/prompts/context.md is pipeline-controlled and is not project-extendable.
Preference memory
Preference memory lets agents carry approved style/quality preferences forward to later roles. Preferences are written directly to .agentmux/prompts/agents/<role>.md under a ## Approved Preferences section — no intermediate JSON artifacts.
Agents pass approved preferences as an optional preferences parameter on the relevant submit tool call:
submit_review(
preferences=[
{"target_role": "coder", "bullet": "- Keep regression tests"}
]
)The preferences parameter is supported on submit_architecture, submit_pm_done, submit_plan, and submit_review. The MCP server calls apply_preference_entries(project_dir, preferences) which appends bullets to .agentmux/prompts/agents/<role>.md (creating the file if absent) under ## Approved Preferences. Deduplication is applied on a normalized casefold basis across all bullet lines in the file.
Application flow:
- Agents collect preference candidates during their work phase.
- Candidates are proposed to the user via the approval dialog (
[[shared:preference-memory]]fragment). - Approved entries are passed as
preferences=[...]in the existing submit tool call. apply_preference_entrieswrites bullets immediately to project prompt files.- Prompt builds are lazy, so newly persisted preferences are visible in subsequent prompt renders in later phases.
Deduplication rules (high level):
- Normalize bullets by trimming, removing leading bullet markers (
-,*,+), collapsing whitespace, and comparing case-insensitively. - Deduplicate within the current proposal batch per target role.
- Skip appending bullets already present in the target extension file after normalization.
Prompt injection
Prompts are not injected as full text. Instead, send_prompt() in agentmux/runtime/tmux_control.py sends a concise file reference message like:
Read and follow the instructions in /full/path/to/prompt_file.mdAgents still read the referenced prompt file themselves. Prompt files are now self-contained: session files referenced by template includes are inlined at build time, so agents do not need extra tool calls to fetch requirements.md, plan.md, state.json, and similar inputs separately.
Lazy build
Prompt files are built lazily by handlers just before injection, not pre-generated. Each build_*_prompt() function in agentmux/workflow/prompts.py loads and renders the markdown template for its phase.
Startup and resume now use explicit phase bootstrap: the orchestrator re-enters the active phase before steady-state event sources start, and that phase entry is what causes the handler to build and send the current prompt. Prompt injection therefore does not depend on the first seeded file.created event.
Handoff contract fragments
Three shared prompt fragments provide agents with MCP submission tool instructions and YAML fallback examples for non-MCP providers. They are inlined at template-load time via [[shared:fragment-name]]:
handoff-contract-architecture.md— used byarchitect.md; documentssubmit_architectureparameters and fallbackarchitecture.yamlschemahandoff-contract-plan.md— used byplanner.mdandchange.md; documentssubmit_subplanandsubmit_execution_planparameters and fallback YAML schemashandoff-contract-review.md— used by reviewer agent prompts; documentssubmit_reviewparameters and fallbackreview.yamlschema
See docs/handoff-contracts.md for full contract details.
Coder research handoff
Coder prompt rendering injects a Research handoff block into agentmux/prompts/agents/coder.md via [[placeholder:research_handoff]].
Behavior contract:
- Applies to both
build_coder_subplan_prompt()andbuild_coder_whole_plan_prompt() - Scans topic directories under
03_research/in sorted (deterministic) order - Includes a topic only when both
doneandsummary.mdare present - Lists
summary.mdas the primary reference - Adds
detail.mdas an additional reference only when present - Uses feature-relative paths (for example
03_research/code-auth/summary.md) - Omits the entire handoff section when no completed research topics are available
Coder workflow contract
The coder prompt contract now requires:
- TDD protocol: write tests first, run them, verify they fail (Red), then implement until tests pass (Green).
- Strict phase order discipline: follow the active plan/sub-plan phase order and do not move to later-phase logic early.
- Atomic execution from tasks: complete one task from your assigned
04_planning/tasks_<N>.mdat a time, validate it, and check it off before starting the next task. - Completion marker flow remains unchanged: finish all required validation first, then create the phase completion marker as the final action.
Staged planning contract
The architect/planner split is:
- Architect (
build_architect_prompt()) — defines the technical design: solution approach, components, interfaces, data models, cross-cutting concerns, technology choices, risks. Sole output:02_architecting/architecture.md. - Planner (
build_planner_prompt()) — receivesarchitecture.mdand produces the full execution schedule. Sole owner of all plan files.
Planner (and replanning via build_change_prompt()) output contract:
04_planning/plan.mdis the human-readable overview04_planning/plan_<N>.mdfiles are executable implementation units04_planning/execution_plan.yamlis the scheduling source of truth (ordered execution groups, each marked asserialorparallel, with explicit named plan references) and also contains planner workflow-intent metadata (needs_design,needs_docs,doc_files,review_strategy)04_planning/tasks_<N>.mdare per-plan implementation checklists mapped to the same work; each coder receives only their assigned plan's tasks04_planning/tasks.mdis an optional human-readable overview summarizing all tasks (not used by scheduler)- Documentation updates must be represented in planning artifacts (
plan.md,plan_<N>.md, and correspondingtasks_<N>.md) rather than a dedicated post-review docs phase.
Planner output requirements for execution plans include:
- A Phase 1 / Phase 2 / Phase 3 breakdown where Phase 1 defines interfaces/contracts and Phase 2 uses those contracts for parallel implementation
- Per parallel sub-plan sections for
Scope,Owned files/modules,Dependencies, andIsolation - Explicit conflict mapping by touched files/modules plus explicit ownership for each parallel lane
- Safety-first rule: Phase 2 parallel sub-plans are allowed only when their owned files/modules are disjoint; if two lanes would edit the same file/module, that work must be merged into one sub-plan or moved into a serial integration step
- Shared mutable artifacts such as
04_planning/tasks.md, prompt templates, monitor/state metadata files, and cross-cutting tests/docs should have a single Phase 2 owner unless intentionally deferred to integration Isolationmust be justified in terms of exclusive ownership, not only logical separation- A callout for any enabling refactor needed to preserve boundaries, plus explicit technical debt rationale when refactor work is deferred
Current prompt builders:
build_architect_prompt()renders architecting prompts (createsarchitecture.md)build_planner_prompt()renders planning prompts (creates plan files fromarchitecture.md)build_change_prompt()applies the same staged planning artifact contract in replanning mode- planning/replanning prompt contracts require:
04_planning/plan.mdas the human-readable overview04_planning/plan_<N>.mdexecutable sub-plan files04_planning/execution_plan.yamlas machine-readable schedule and metadata (version, orderedgroups,group_id,mode,plans, plusneeds_design,needs_docs,doc_files,review_strategy)- new plans must write
groups[].plans[]entries as{ file: plan_<N>.md, name: "<sub-plan title>" } execution_plan.yamlis required before implementation scheduling starts
build_product_manager_prompt()renders the PM analysis promptbuild_coder_subplan_prompt()renders implementing prompts for numberedcoder_prompt_<N>.mddispatch, including completion marker instructions and optional research handoff referencesbuild_coder_whole_plan_prompt()renders a single combined prompt for single-coder mode by embedding all plan and tasks content inline into the unifiedcoder.mdtemplate. When the coder provider iscopilotwithsingle_coder: true, the dispatch sends a/fleetprefix command as keystrokes before the prompt file reference, so Copilot CLI decomposes the plan into parallel sub-agent tasks. The prompt instructs copilot to createdone_Ncompletion markers as each plan finishes.build_reviewer_prompt(..., is_review=True)renders the review command promptbuild_reviewer_summary_prompt()renders the reviewer summary prompt (writes08_completion/summary.mdafter VERDICT:PASS)