Part 6 · Inside a Production Coding Agent

How AgentDefinition & Persona Merge

Deconstructing Agent definitions, Persona overrides, and the merge order of final session behavior

THE QUESTION THIS PAGE ANSWERS

ANSWER FIRST

How AgentDefinition & Persona Merge?

Deconstructing Agent definitions, Persona overrides, and the merge order of final session behavior

DECISION RULE

Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.

TRY NEXT

Write one question you could answer with evidence after trying this idea.

WATCH FOR

A conclusion that sounds complete but leaves the key assumption untested.

Learning Objectives

Distinguish between AgentDefinition, SubagentRole, SubagentPersona, and EffectiveRuntimeConfig, and accurately determine the merge priority for each field.

TEACHING DIAGRAM

Definition Resolution and Runtime Overrides Are Two Input Streams

Type and function names in the diagram come from source code; arrows illustrate data convergence.

AgentDefinition and runtime overrides together form a sub-agent AgentDefinitiontools · prompt · permission · model spawn / role / personaruntime defaults and overrides resolve_effective_overridesEffectiveRuntimeConfigprompt fragments + runtime choices child sessiondefinition filtered and rendered
What Each of the Four Real Structures Controls

AgentDefinition: The Versionable Agent Contract

Parsed from .grok/agents/*.md. Real fields include prompt_mode, tool_config, capability_mode, permission_mode, tools, isolation, model, hooks, and MCP inheritance. Project-defined discovery takes priority over user and bundled definitions.

SubagentRole: Runtime Preset Matched by Type

A role can provide capability, model, reasoning effort, prompt file, and default isolation. It is looked up by subagent_type and the role prompt is read at spawn time.

SubagentPersona: Behavior Layer Selected by Name

A Persona has inline instructions, an instructions file, inputs, outputs, model, reasoning effort, and default isolation. Inline text is merged before file content, then injected as a <persona> block into the prompt.

EffectiveRuntimeConfig: The Resolved Result

Real fields are model, reasoning_effort, capability_mode, persona, persona_instructions, role_prompt, role_prompt_warning, role_name, persona_error, and isolation. There are no temperature, max_tokens, or tools fields in the source code.

crates/codegen/xai-grok-agent/src/config.rs crates/codegen/xai-grok-agent/src/discovery.rs crates/codegen/xai-grok-subagent-resolution/src/config.rs resolve_effective_overrides
Priority Must Be Read Field by Field
01 · spawn overrideExplicitly provided model, reasoning, capability, persona, and isolation when calling task.
02 · role defaultRole defaults for model, reasoning, capability, and isolation.
03 · persona defaultModel, reasoning, and isolation. Persona does not provide capability_mode.
04 · parent / noneUnmatched fields remain None, inheriting from the parent downstream; isolation ultimately falls back to None mode.

A Definition Fallback Follows EffectiveRuntimeConfig

After the shell receives the resolved result, if reasoning_effort is still empty, it reads AgentDefinition.effort. If runtime isolation is None but definition isolation is Worktree, it is upgraded to Worktree. In model resolution, the resolved runtime override takes precedence over per-agent pin, AgentDefinition.model, and parent model inheritance.

Fail-closed: Persona

If a Persona is requested but not found, has empty content, or fails to read its file, persona_error is written. File I/O failures return a defaulted result early; the spawn side aborts creation upon seeing a Persona error.

Soft Degradation: Role Prompt

A read failure for the role's prompt_file produces only role_prompt_warning; the remaining model, reasoning, capability, and isolation fields continue to be resolved.

Real Source Snapshot
crates/codegen/xai-grok-subagent-resolution/src/types.rsREAL SOURCE · abridged
pub struct EffectiveRuntimeConfig {
    pub model: Option<String>,
    pub reasoning_effort: Option<String>,
    pub capability_mode: Option<SubagentCapabilityMode>,
    pub persona: Option<String>,
    pub persona_instructions: Option<String>,
    pub role_prompt: Option<String>,
    pub persona_error: Option<String>,
    pub isolation: SubagentIsolationMode,
}

Snapshot note: Field names and types come from the real struct; comments and two observational fields are omitted. The convergence diagram above is a teaching visualization and does not imply a monolithic pipeline class of that name exists in the source code.

Class Exercise: Manually Compute the Effective Configuration

spawn specifies reasoning_effort=high and Persona reviewer; role specifies model=A, capability=read-only, isolation=worktree; Persona specifies model=B, reasoning=low, isolation=none. Write out the final values for all four fields and explain why capability will not be read from the Persona.

Takeaway: AgentDefinition provides the Agent skeleton; role and Persona provide runtime inputs at the spawn stage. Priority cascades field by field — accurate analysis requires first confirming which structure each field genuinely belongs to.

Why “Definition Resolution and Runtime Overrides Are Two Input Streams” depends on the operation

“Distinguish between AgentDefinition , SubagentRole , SubagentPersona , and EffectiveRuntimeConfig , and accurately determine the merge priority for each field” makes the structure concrete. The useful comparison is not which name sounds more advanced, but how the data is arranged and how far the most common operation has to travel.

Read a structure through access and change

“Type and function names in the diagram come from source code;” exposes a trade-off that is easy to miss: reading by position, looking up by key, adding at either end, inserting in the middle, and traversing relationships do not favor the same organization. A structure that is fast for one operation is not automatically fast for all of them.

Count scale and update frequency together

Use “spawn specifies reasoning_effort=high and Persona reviewer;” as a boundary check. Write down the data size, the dominant operation, and the latency you can accept before deciding whether an AI-generated structure actually fits.

From “Definition Resolution and Runtime Overrides Are Two Input Streams” to “AgentDefinition: The Versionable Agent Contract”

“Definition Resolution and Runtime Overrides Are Two Input Streams” grounds the problem in “Type and function names in the diagram come from source code; arrows illustrate data convergence”. “AgentDefinition: The Versionable Agent Contract” then moves it toward “Parsed from .grok/agents/*.md . Real fields include prompt_mode , tool_config , capability_mode , permission_mode , tools , isolation , model , hooks, and MCP inheritance. Project-defined discovery takes priori…”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.

Carry the judgment into the next situation

When you meet a new data structure, do not begin by memorizing its definition. Write down the most frequent operation, estimate scale and update behavior, and check whether the structure satisfies all three conditions.

  • “Definition Resolution and Runtime Overrides Are Two Input Streams”: Type and function names in the diagram come from source code; arrows illustrate data convergence
  • “AgentDefinition: The Versionable Agent Contract”: Parsed from .grok/agents/*.md . Real fields include prompt_mode , tool_config , capability_mode , permission_mode , tools , isolation , model , hooks, and MCP inheritance. Project-defined discovery takes priori…
  • “The closing point”: If a Persona is requested but not found, has empty content, or fails to read its file, persona_error is written. File I/O failures return a defaulted result early; the spawn side aborts creation upon seeing a P…

The final “The closing point” brings the discussion to “If a Persona is requested but not found, has empty content, or fails to read its file, persona_error is written. File I/O failures return a defaulted result early; the spawn side aborts creation upon seeing a P…”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.

Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing How AgentDefinition & Persona Merge Inside a Production Coding Agent
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.

ARTICLE DISCUSSION4 helpful