Prompt construction is split across two layers: The gateway decides which previous conversation messages should be included. The agent compiles the system prompt and current turn runtime context. The provider adapter then maps the commonDocumentation Index
Fetch the complete documentation index at: https://docs.getpioneer.dev/llms.txt
Use this file to discover all available pages before exploring further.
ChatRequest into the provider-specific API shape.
This split is deliberate. Conversation history is durable thread state, so the gateway owns loading, summarizing, and truncating it. Runtime instructions are turn-scoped, so the agent owns skills, retry instructions, task orchestration policy, and runtime facts. Provider adapters should only translate the already-built request into API-specific payloads.
Why Prompt Compilation Is A Separate Crate
Prompt behavior changes the product more than most internal refactors. Small wording changes can affect tool use, recovery, task delegation, and user trust. Keeping prompt compilation inpioneer-promt makes it testable and reviewable as its own layer instead of hiding it in the middle of the agent loop.
The compiler also gives Pioneer stable/dynamic prompt separation. Stable sections can be fingerprinted and potentially cached by providers. Dynamic sections can change between rounds when skills, retry instructions, continuation hints, or runtime facts change.
Conversation History
Historical context is loaded byMessageProcessor::load_conversation_history in crates/gateway/src/message/provider_handlers.rs.
The gateway loads up to 200 completed conversation entries from CrudStore::get_thread_conversation_history. It also loads the thread summary if one exists. Token counting uses tiktoken-rs with cl100k_base as a provider-agnostic approximation.
The budget is derived from gateway thread config:
Prompt Compiler
The system prompt compiler lives incrates/promt. The crate name is intentionally promt in the current workspace.
compile_prompt receives PromptCompileInput:
| Input | Meaning |
|---|---|
workspace_root | Directory where bootstrap prompt files are read. |
profile | Prompt profile: full, minimal, or none. Agent turns use AssistantFull. |
skills_prompt | Dynamic skills section built after skill resolution. |
retry_instruction | Dynamic instruction inserted after recoverable tool failures or loop budget exhaustion. |
include_tool_recovery_policy | Adds stable tool failure recovery instructions. |
include_task_orchestration_policy | Adds task/subagent orchestration guidance when task tools are available. |
continue_generation_hint | Adds continuation guidance during recovery. |
dynamic_context | Reserved dynamic context hook. Currently passed as None by the main agent flow. |
extra_system | Runtime facts such as local date/time and OS. |
limits | Character budgets for bootstrap files. |
Prompt Sections
The compiler builds ordered sections:| Section | Stability | Source |
|---|---|---|
| Identity | Stable | Built-in identity base. |
| Safety | Stable | Built-in safety lines. |
| Soul Core | Stable | SOUL.md, or default soul prompt if missing. |
| Identity Core | Stable | IDENTITY.md, or default identity prompt if missing. |
| User Persona | Stable | USER.md if present. |
| Tool Recovery Policy | Stable | Built-in policy when enabled. |
| Task Orchestration | Dynamic | Built-in policy when task tools are materialized. |
| Recovery Continuation | Dynamic | Built-in continuation hint when requested. |
| Skills Runtime | Dynamic | Active skills prompt for the turn. |
| Retry Instruction | Dynamic | Tool retry or final-answer instruction. |
| Dynamic Context | Dynamic | Optional caller-provided context. |
| Extra System | Dynamic | Current runtime date/time and OS. |
full_system_text through CompiledPromptPayload. Adapters can use this to support provider-side prompt caching where available.
Bootstrap Files
The compiler reads the canonical files in this order:SOUL.mdIDENTITY.mdUSER.md
Skills Prompt
Skills are resolved before prompt compilation.pioneer-skills builds a compact [Skills] section listing active skills, their exact read_skill slug, and their descriptions. When few skills are active and budget allows, explicitly mentioned or path-matched skills can include full skill bodies. If the prompt budget is tight, the section includes a read_skill hint so the model can load exact skill instructions on demand.
Tool Definitions Are Separate
Tool definitions are not embedded as prompt prose. The agent passes model-visible tool definitions inChatRequest.tools. The prompt can explain recovery or task orchestration policy, but the callable JSON schema for tools goes through the provider tool-calling interface.
This distinction prevents two common bugs. First, a tool should not become callable just because its name appears in prompt text. Second, removing a tool from the model-visible tool list should actually remove the capability, not merely change an instruction sentence. Tool availability is enforced by the tool router described in Tools System.
Prompt Manifest
Every prompt compilation emits aPromptManifest durable event with compiler version, profile, section ids, stable/dynamic/full fingerprints, and diagnostics. The gateway persists this metadata on the turn through CrudStore::update_turn_prompt_manifest.
The manifest is the audit handle. It tells a developer which prompt shape was sent, whether bootstrap files were missing or truncated, and whether dynamic sections changed between provider rounds.
The manifest intentionally stores metadata rather than turning the prompt into the only source of truth. The actual behavior is the combination of prompt sections, conversation messages, tool definitions, provider adapter behavior, and runtime policies.
Common Debugging Path
When model behavior looks wrong, check these in order:- Was the thread in
chatoragentmode? See Agent Loop. - Was history compressed or truncated by the gateway?
- Which prompt sections appear in the
PromptManifest? - Were relevant skills resolved, disabled, or non-implicit? See Skills Architecture.
- Which tools were model-visible for that provider round? See Tools System.
- Did the provider adapter map
compiled_promptin the expected way? See Provider System.
Related Pages
- Gateway explains where history loading is triggered.
- Agent Loop explains how prompt compilation fits into provider/tool rounds.
- Skills Architecture explains the skills prompt.
- Tasks And Subagents explains why task orchestration can add prompt policy.