- Built-in subagents: Provided by qodercli, such as general-purpose search, code exploration, and planning.
- Custom subagents: Defined by SDK users through
QoderAgentOptions.agents, suitable for business review, test execution, security analysis, and other specialized roles.
QoderAgentOptions.agent is a special usage that runs an Agent definition as the main session role.
Built-in Subagents
When using a built-in subagent, you do not need to write the subagent definition yourself. You only need to know its name and reference it from the SDK. Common built-in subagents currently provided by qodercli:
The built-in subagent list can change with the qodercli version and current configuration. In the interactive CLI, enter
/agents to view the currently discovered subagents. From the command line, you can also run:
QoderSDKClient.supported_agents() to read the subagents actually available to the current session:
supported_agents() returns the subagents registered through agents plus the built-in, user, project, and plugin subagents discovered by the current CLI. See AgentInfo for the return structure.
Using Built-in Subagents
Run as the Main Session Role
If you want the entire session to run under a built-in subagent role, pass the built-in subagent name directly toQoderAgentOptions.agent. You do not need to redefine it in agents.
agent can reference a subagent registered by the SDK, or a built-in / user / project / plugin subagent discovered by the current CLI.
Delegate as a Subagent
Subagent delegation happens through the built-inAgent tool. The main session’s available tool set must include Agent; otherwise the model has no entry point for delegation. In SDK usage, a common pattern is to pre-authorize that tool call path and name the desired subagent in the prompt.
allowed_tools=["Agent"] allows or pre-authorizes this class of tool calls. If you also use tools to restrict the main session tool allowlist, include Agent in tools as well. Do not put Agent in disallowed_tools.
The subagent name must match the discovered result exactly, including case. For example, current built-in names include Explore, Plan, and general-purpose. If unsure, call client.supported_agents() first.
Custom Subagents
When built-in subagents do not fit your business or project constraints, define custom subagents throughQoderAgentOptions.agents. For example:
- Read-only code review subagent: can only read files and search; cannot modify code.
- Test execution subagent: can run test commands and analyze failure reasons.
- Security review subagent: focuses only on authentication, authorization, injection, sensitive information leakage, and related risks.
- Business support subagent: can only call specific MCP tools, such as order lookup, ticket search, or internal knowledge base search.
- Define the subagent name, usage description, and system prompt in
agents. - Narrow the tools it can use with
toolsordisallowedTools. - Let the main session delegate to it through the
Agenttool, or useagentto let it drive the main session directly.
TheAgenttool is required: Custom subagents need the main session to delegate through the built-inAgenttool, soallowed_toolsmust include theAgenttool.
Defining Custom Subagents with agents
Minimal example: register a read-only code review subagent.QoderAgentOptions.agentsregisters the custom subagents available to this session.- Subagent delegation happens through the
Agenttool; you must useallowed_tools=["Agent"]here to pre-authorize that call path. - The subagent’s own
toolsonly allow reading and searching, so it cannot edit files or execute commands.
agents Input
agents maps subagent names to AgentDefinition objects. See AgentDefinition for the complete type.
The Python SDK’s
AgentDefinition field names use protocol-style camelCase, such as disallowedTools, maxTurns, initialPrompt, and permissionMode, not disallowed_tools or max_turns.
Configuring the Subagent Role
description and prompt are the two most important fields for a custom subagent.
description
description explains when this subagent should be used. The model uses it to decide whether to delegate.
description should state the task boundary clearly. Avoid generic descriptions such as A helpful agent or Helper.
prompt
prompt defines the subagent’s role, boundaries, and output format. The Python AgentDefinition constructor requires this field.
prompt should explain three things:
Configuring Subagent Model and Reasoning
First makedescription and prompt clear, then consider model, effort, and maxTurns. The former decide whether the subagent is invoked correctly and whether it understands its boundaries once invoked. The latter mainly tune quality, speed, and cost after the role is clear.
At the Python type level,
model is str | None. Common values include "inherit", "auto", model aliases, or any full model ID supported by the current CLI / backend. Actual usable values depend on qodercli and backend configuration.
Example: give different subagents different strategies.
Controlling Subagent Tools
Custom subagents and the main session use the same tool names. Built-in tool names includeRead, Grep, Glob, and Bash; custom MCP tools use the full format mcp__{serverName}__{toolName}.
The Main Session’s Agent Tool
agents only registers subagents; it does not automatically make the model call them. To delegate a task, the main session’s tool set must contain Agent. If you set QoderAgentOptions.tools to limit the main session’s available tools, remember to include Agent. If you set disallowed_tools=["Agent"], delegation is disabled.
Tool Allowlist: tools
tools is the subagent’s tool allowlist. Once set, the subagent can only use listed tools.
Tool Blocklist: disallowedTools
disallowedTools is useful when you want to allow most tools while excluding a few.
tools and disallowedTools unless you are certain of the final tool set.
Relationship to Main Session Tool Configuration
A subagent’stools / disallowedTools only apply to that subagent. They do not inherit the main session’s tool allowlist or blocklist trimming. Even if the main session only pre-authorizes the Agent delegation path, the subagent can still use its own configured Read, Grep, and related tools.
Controlling Subagent Permissions
The tool set decides which tools a subagent can call. Permission settings decide how those tool calls are approved or blocked. You can configurepermissionMode separately on a subagent to control permission behavior for its internal tool execution.
permissionMode, see Agents Reference - permissionMode. If the host needs to approve tool calls one by one, use the session-level can_use_tool callback; the context.agent_id received by the callback can be used to identify whether the call comes from a subagent.
Loading Skills for Subagents
skills preloads specialized skills for a subagent. It is useful when you want to bind a specific workflow, team convention, or tool usage pattern to one subagent instead of putting it in every prompt.
skills only affect that subagent’s context. They are not the same as the main session’s QoderAgentOptions.skills. For session-level skill behavior, see Skills.
Configuring Subagent mcpServers
mcpServers limits or adds MCP servers for a subagent. It is suitable for exposing business tools only to the subagents that need them, such as order lookup, ticket search, or internal knowledge base search.
You can reference an MCP server already configured at the session level:
For complete field status, see Agents Reference - mcpServers.
Invoking Subagents
Subagents have three common invocation modes.Automatic Invocation
The model decides whether to call a subagent based on the task and each subagent’sdescription. Clear descriptions improve routing accuracy.
Explicit Invocation
If you want the model to use a specific subagent, name it in the prompt.Run as the Main Session Role
QoderAgentOptions.agent makes the main session run directly as a subagent identity.
agent can reference a custom subagent in agents, or a built-in / user / project / plugin subagent discovered by the current CLI.
Subagent Context and Results
A subagent runs in an independent context. It receives its own system prompt and delegation prompt, but it does not directly inherit the parent session’s full history.
The main channel for passing information from the parent session to a subagent is the task prompt passed when calling the Agent tool. If a subagent needs specific file paths, error messages, or business context, make the main session pass them explicitly during delegation.
When a subagent completes, the parent session receives its final response, not the full context of every internal tool call.
Combined Examples
Multi-role Collaboration
Register multiple subagents with different roles. The main session decides whether and when to call them based on the task.Automatically Run the First Task After Startup
initialPrompt only takes effect when that subagent becomes the main session role through agent:
auditor is called as a subagent through the main session’s Agent tool, initialPrompt is ignored.
Common Pitfalls
- When directly using a built-in subagent, do not redefine a subagent with the same name in
agentsunless you intentionally want to override it. - Calling subagents depends on the main session’s
Agenttool.allowed_tools=["Agent"]pre-authorizes it; if you usetoolsto restrict main-session tools, includeAgentthere too. - Subagent names are case-sensitive and must match the discovered result, such as
ExploreandPlanwith capitalized first letters. descriptiontells the model when to call the subagent;prompttells the subagent what to do after it is called.- Subagents cannot spawn their own subagents. Do not put
Agentin a subagent’stools. initialPromptonly takes effect for the main session role specified byagent; it is ignored when the agent is delegated to as a subagent.AgentDefinitionfield names are camelCase, not snake_case.- Fields like
background,memory, andcriticalSystemReminder_EXPERIMENTALexist as types, but the SDK registration pipeline does not currently use them to change runtime behavior. Check Agents Reference before relying on them.
Continue Reading
- Agents Reference: Complete reference for
AgentDefinition,AgentInfo,agent, andagents. - Tools: Built-in tools, custom tools, and tool permissions.
- Permissions:
permissionMode,allowed_tools, andcan_use_tool. - Skills: Session-level and subagent-level skill configuration.