CHAPTER 12 · PROMPT CONTEXT
PromptContext: Inspectable Rendering Input
PromptContext stores Agent-specific template inputs. It gains serialization capability via Serde derive, then is passed to ToolBridge::render_prompt() for rendering.
Course Goal
Accurately identify PromptContext fields, the three TemplateOverride variants, and rendering responsibilities. Delete non-existent context fields and methods.
Accurately identify PromptContext fields, the three TemplateOverride variants, and rendering responsibilities. Delete non-existent context fields and methods.
Core Visual · Pedagogical Rendering Pipeline
Real Field Groups
Version & Template
versionprompt_modeaudienceprompt_bodysystem_promptbuild_timestamp_utcsystem_prompt_labelConfig & Identity
agents_md_filespersona_summariesrole_instructionspersona_instructionsmemory_enabledmemory_global_pathmemory_workspace_pathUser Runtime Environment
os_nameshell_pathworking_directorycurrent_dateis_non_interactiveTemplateOverride
None
Standard Template
Primary uses the standard base template; Subagent uses its corresponding compact template.
Codex
Apply-patch profile
Source code comments define the apply-patch profile prompt template, decrypted on demand.
Custom(String)
Caller-provided Template
Complete custom template string provided by the caller.
Real Source Code Evidence
crates/codegen/xai-grok-agent/src/prompt/context.rs
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PromptContext {
pub version: u32,
pub prompt_mode: PromptMode,
pub audience: PromptAudience,
pub prompt_body: Option<String>,
pub system_prompt: TemplateOverride,
pub agents_md_files: Vec<AgentConfigFile>,
pub persona_summaries: Vec<String>,
pub build_timestamp_utc: String,
pub memory_enabled: bool,
// ...remaining path, identity, and runtime env fields
}
pub struct PromptContext {
pub version: u32,
pub prompt_mode: PromptMode,
pub audience: PromptAudience,
pub prompt_body: Option<String>,
pub system_prompt: TemplateOverride,
pub agents_md_files: Vec<AgentConfigFile>,
pub persona_summaries: Vec<String>,
pub build_timestamp_utc: String,
pub memory_enabled: bool,
// ...remaining path, identity, and runtime env fields
}
crates/codegen/xai-grok-agent/src/prompt/context.rs
#[derive(Debug, Clone, PartialEq, Eq,
Serialize, Default)]
pub enum TemplateOverride {
#[default]
None,
Codex,
Custom(String),
}
Serialize, Default)]
pub enum TemplateOverride {
#[default]
None,
Codex,
Custom(String),
}
Fact Check: The field list is authoritative as defined by the struct. Serialization capability comes from the
Serialize and Deserialize derives; the source code does not define dedicated JSON conversion methods. Tool descriptions are handled by the rendering path combined with ToolBridge.Source Snapshot Note: This page is verified against a local sync copy. This copy has no
.git metadata, so no specific commit version is claimed.Classroom Exercise
Infer sections from fields
Map agents_md_files, memory_enabled, os_name, and role_instructions to their likely prompt sections. Then check which fields use skip_serializing_if, and explain how empty values reduce persistence output.
Takeaway: PromptContext is a serializable rendering input; TemplateOverride determines the base template; ToolBridge and TemplateRenderer complete the final render. Fields and capabilities should be described according to the derives and real definitions.