Documentation

Roles & Context Briefing

How agent roles are resolved, applied, and how context is propagated to subagents.

Edit on GitHub

When Nyzhi spawns a subagent, it needs to decide what the agent can do (its role) and what it knows (its context briefing). This page explains how both systems work internally.

Role Resolution

When spawn_agent is called with an agent_type, Nyzhi resolves the role in this order:

  1. User-defined roles — from [agent.agents.roles] in your config
  2. Built-in roles — shipped with Nyzhi
  3. Fallback — a synthesized default role

The first match wins.

Built-in Roles

RoleDescriptionRead-only
defaultGeneral-purpose agentNo
explorerCodebase explorationYes
workerImplementation tasksNo
reviewerCode reviewYes
plannerArchitecture and planningYes
architectSystem designYes
debuggerRoot-cause debuggingNo
security-reviewerSecurity analysisYes
quality-reviewerCode quality assessmentYes
test-engineerTest writing and QANo
build-fixerBuild failure resolutionNo
deep-executorComplex multi-step tasksNo
document-specialistDocumentationNo
code-simplifierRefactoring and simplificationNo

Each built-in role has a dedicated system prompt personality and optional tool constraints.

User-Defined Roles

Define roles in your config:

[agent.agents.roles.api-specialist]
description = "Backend API expert"
system_prompt = "You are an API development specialist..."
model = "anthropic/claude-sonnet-4-20250514"
max_steps = 60
allowed_tools = ["read", "write", "edit", "bash", "grep", "glob", "git_status"]

File-Based Roles

Create a markdown file at .nyzhi/agents/<role-name>.md:

---
name: api-specialist
description: Backend API expert
model: anthropic/claude-sonnet-4-20250514
max_steps: 60
read_only: false
allowed_tools: [read, write, edit, bash, grep, glob]
---

You are a backend API specialist. Focus on:
- RESTful API design
- Input validation
- Error handling
- Performance optimization

The markdown body becomes the system prompt override.

Priority: .nyzhi/agents/ wins over .claude/agents/ on name conflicts.

Role Application

When a role is resolved, apply_role modifies the spawned agent’s config:

  1. System prompt — overridden if the role specifies one
  2. Max steps — capped if the role limits it
  3. Model — overridden if the role specifies one (via subagent_model)
  4. Agent name — labeled as sub-agent/<role>

Then apply_model_override layers any session-scoped override from /subagent-config.

Tool Fencing

Roles control tool access:

  • allowed_tools — explicit whitelist of tools the agent can use
  • disallowed_tools — blacklist subtracted from available tools

At execution time, ToolRegistry::execute enforces the allowed_tool_names gate. If a tool isn’t in the list, it can’t run.

Context Briefing

When a subagent is spawned, it receives a context briefing — a compact summary of the parent’s state.

What’s Included

SharedContext carries:

FieldWhat it contains
recent_changesFiles modified by the parent agent
active_todosCurrent todo list items
conversation_summaryRecent message preview
project_rootWorkspace path

How It’s Built

build_briefing() renders these into markdown sections with caps:

LimitValue
Total briefing lines60
Recent change entries20
Message preview5 messages

Injection

At spawn time:

  1. Lock the shared context
  2. Render the briefing markdown
  3. Append it to the child’s system prompt
  4. Append recent notepad wisdom (if available)

This gives subagents enough context to work effectively without re-reading the parent’s entire conversation.

Project Memory

The briefing can also include a project memory excerpt (from SharedContext::build_briefing()), so subagents benefit from stored project knowledge.

Runtime Model Overrides

The /subagent-config slash command lets you override models per role for the current session:

/subagent-config set explorer deepseek/deepseek-chat
/subagent-config set worker anthropic/claude-sonnet-4-20250514
/subagent-config reset explorer

These overrides apply on top of role-defined models and config-defined models.

Next Steps