Prompt Architecture (Top-Down)
This is the runtime order used in current code.
Top-Down Flow Diagram
PromptSpecWithSkills(...)
|
v
ApplyPersonaIdentity(...)
|
v
AppendLocalToolNotesBlock(...)
|
v
AppendPlanCreateGuidanceBlock(...)
|
v
AppendTodoWorkflowBlock(...)
|
v
Channel PromptAugment(...)
|
v
AppendMemorySummariesBlock(...)
|
v
BuildSystemPrompt(...) -> system prompt text1) Identity Layer
Base identity comes from agent.DefaultPromptSpec().
Then runtime may replace it via local persona files:
file_state_dir/IDENTITY.mdfile_state_dir/SOUL.md
Applied by promptprofile.ApplyPersonaIdentity(...).
2) Skills Layer
skillsutil.PromptSpecWithSkills(...) discovers selected skills and injects only metadata into the system prompt:
- skill name
SKILL.mdpath- short description
- required
auth_profiles(if provided)
The model reads the actual skill file through read_file when needed.
3) Core Policy Blocks
Common blocks are appended in task runtime order:
- local tool notes (
SCRIPTS.md) viaAppendLocalToolNotesBlock plan_createguidance viaAppendPlanCreateGuidanceBlock- TODO workflow policy via
AppendTodoWorkflowBlock
4) Channel Blocks
Channel runtime then appends channel-specific blocks.
Examples:
- Telegram:
AppendTelegramRuntimeBlocks(...) - Slack:
AppendSlackRuntimeBlocks(...) - LINE:
AppendLineRuntimeBlocks(...) - Lark:
AppendLarkRuntimeBlocks(...)
5) Memory Injection Block
If enabled, memory snapshot text is appended as another block through AppendMemorySummariesBlock(...).
6) System Prompt Rendering
agent.BuildSystemPrompt(...) renders agent/prompts/system.md with:
- identity
- skills metadata
- appended blocks
- tool summary from registry
- rules list
7) Message Stack Sent to LLM
In engine.Run(...), message order is:
[system] rendered system prompt
->
[user] mister_morph_meta (optional)
->
[history] non-system messages
->
[user] current message or raw task- system prompt
- injected runtime metadata message (
mister_morph_meta, if present) - history messages (non-system)
- current message (if provided) or raw task text
Practical Rule
If you need to customize prompt behavior, prefer these extension points in order:
IDENTITY.md/SOUL.mdSKILL.md+skills.loadSCRIPTS.md- runtime-specific prompt augment
- low-level
agent.WithPromptBuilder(...)(only for full custom wiring)