进阶 zcode.z.ai 2026-11-25 14:51:22 · 0 阅读

第18章 Subagents

Core FeaturesSubagents A subagent is a specialized agent that the primary Agent launches in its own isolated context; when it finishes, the results are summarized back into the main conversation. The primary Agent dispatches one whenever a task needs a separate context or parallel research, and you can also call one by name with @ in the chat input. ZCode ships with two built-in subagents, and you can create your own under Settings → Subagents. Built-in Subagents SubagentToolsUse casesgeneral-purposeEvery tool (default)Independent tasks involving file access and command executionExploreRead and search tools only; never changes filesWide searches, tracing call chains, and scoping risk before a change For example, specify Explore in the task instructions: Use Explore to trace this module's call chain first, then summarize the entry points and risks. Subagents Inside a Session Once subagents start, a card for each appears in the conversation, and a status pill above the composer shows how many are running or completed. The example below shows Explore and general-purpose running in parallel. Subagent cards in the conversationOpen the status pill to see each subagent's state and time Subagent cards: show the subagent type and the task it was given. Status pill: reads Active while any subagent is running and Completed once all have ended; open it to see each subagent's state (running, completed, failed, cancelled, and so on) and how long it took. Subagent directory: lists every subagent this session has dispatched under Running / Ended. Click a subagent in the status pill's list to open its full session on the right: the model it uses is shown at the top, followed by the instructions the primary Agent gave it, what it did, and its result.After the subagents return their results, the primary Agent continues processing and summarizes them in the main conversation. A background subagent's card also shows its stages: launched, running in the background and syncing output, then result received. The primary Agent continues processing when results are available. Managing Subagents Open Settings → Subagents to see every subagent currently available. Configuration Scope Use the scope menu at the top left to switch between user-level and workspace-level configurations. Their storage locations and scope are shown below. User levelWorkspace levelLocation~/.zcode/agents//.zcode/agents/ScopeAny project opened on this machineThis project onlyOwnerStored in the local user directoryShared through the project repositoryForCode review or writing roles used across projectsProject-specific roles, such as reviewing PRs against this repo's conventions or running this project's release checks The menu has User and Projects; the Projects submenu lists every workspace currently open. Switching to a workspace shows only that project's subagents, and New writes into its folder. Built-in subagents are listed under User only, but they are available in every project. The list has three groups: Installed: subagents you created or manually added to the configuration directory. You can edit, enable or disable, and delete them. Subagents from plugins: contributed by enabled plugins; each plugin forms its own group under the plugin's name. Their body is read-only, but you can give each one its own model and reasoning effort. Built-in subagents: general-purpose and Explore. They cannot be edited, deleted, or disabled, but support model and reasoning-effort overrides. The badges after each name show its current model and tool setup: Inherit means it follows the primary Agent's current model; All tools means it inherits every tool from the main session, otherwise a tool count is shown. The switch on the right enables or disables it; a disabled subagent is never dispatched. Creating a Subagent Click New to the right of the Installed group and fill in the form: FieldDescriptionScopeUser or a specific workspace; decides where the file is written. Cannot be changed after saving.NameLetters, digits, and hyphens only, 3–50 characters, e.g. code-reviewer.ColorDistinguishes the subagent in lists and sessions. Identification only.ModelDefaults to "Inherit", following the primary Agent's current model; or select a specific model.Reasoning effortAppears only after selecting a specific model; the options depend on that model.DescriptionDescribes the responsibilities and applicable tasks, allowing the primary Agent to determine when to use the subagent.Allowed tools"Default all permissions" inherits every tool; "Custom allowed tools" supports individual selection, with write-capable tools flagged.System promptThe subagent's role, boundaries, and rules.Inject AGENTS.mdControls whether user-level and workspace AGENTS.md instructions are included. Enabled by default. On save, ZCode writes /.md, a Markdown file with frontmatter whose body is the system prompt. Start a new session for it to take effect; open sessions do not hot-reload, but you can send /reload in an open task to apply it. Adjusting Existing Subagents Custom subagents: click the row to edit every field, or edit the Markdown file directly. Either way, start a new session or send /reload in the current task afterwards. Plugin and built-in subagents: only the model and reasoning effort at the end of the row can change; everything else stays as is. Disable: turn off a custom subagent to prevent subsequent calls while retaining its configuration file. Inheritance Model, tool, and project-instruction settings follow these inheritance rules: Inherited by defaultModel: follows ZCode Agent's current model unless setReasoning setting, when the model is inheritedEvery tool, including connected MCP toolsUser-level and workspace AGENTS.mdNot carried overMCP servers connected after the main session startedMCP tools once you switch to a custom tool list (unless named in full)AGENTS.md for the built-in ExploreDispatching other subagents Model: "Inherit" is the primary Agent's current model. When you switch the main session's model, subagents without a fixed model follow it on their next call; subagents with a specific model are unaffected. Reasoning effort: only applies when a specific model is set; with an inherited model, the primary Agent's reasoning setting is inherited too. Tools: "Default all permissions" inherits every tool from the main session, including connected MCP tools. With a custom list, only the checked built-in tools are available and MCP tools are excluded; to keep an individual MCP tool, write its full name mcp____ into tools in the definition file. Wildcards are ignored. MCP connections: a subagent only sees MCP servers that were connected when the main session started; servers connected mid-session are invisible to it. Project instructions: the user-level ~/.zcode/AGENTS.md and workspace AGENTS.md are injected by default, same as the primary Agent; the built-in Explore does not inject them. No nesting: a subagent cannot dispatch subagents of its own. When editing the definition file by hand, these frontmatter fields are supported beyond what the form shows (camelCase, case-sensitive; unknown fields are silently ignored): FieldDescriptionmodel / thoughtLevelSpecific model and reasoning effort; thoughtLevel only applies when model is settools / disallowedToolsAllowed / blocked tool listsmaxTurnsMaximum turns per callbackgroundAllow the primary Agent to dispatch it as a background taskinjectAgentsMdWhether to inject AGENTS.md, default truemcpServersMCP servers it depends on; the call fails if a required server is not connected Foreground and Background Execution ForegroundBackgroundMain taskWaits for all subagents before continuingDoes not wait; can keep going or even finish its turnResultsSeveral subagents run in parallel and are summarized togetherReturn to the main conversation automatically for the primary Agent to processUse casesResearch whose results are required by the main taskLong-running work that can proceed independently The primary Agent selects the execution mode based on the task. A background Explore only has read-only tools. Terminal commands can run in the background too, see ADE tools. Next Steps ZCode AgentHow ZCode's own Agent works and which models it is tuned for.PluginPackage skills, commands, subagents, and MCP servers into one extension.

评论 (0)