Skip to content

feat(agent-core): custom agent files and secondary model on the v1 engine#2232

Open
7Sageer wants to merge 20 commits into
mainfrom
v1-subagent
Open

feat(agent-core): custom agent files and secondary model on the v1 engine#2232
7Sageer wants to merge 20 commits into
mainfrom
v1-subagent

Conversation

@7Sageer

@7Sageer 7Sageer commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained in the next section.

Problem

Custom agents (Markdown agent files) and the secondary model for subagents were only available on the v2 engine (kimi web / experimental kimi -p). Sessions on the default engine — the interactive TUI and plain kimi -p — could not discover or delegate to custom agents, override the main agent's system prompt via SYSTEM.md, select the main agent with --agent/--agent-file, or bind subagents to a cheaper secondary model. This PR migrates both capabilities to the v1 engine with full v2 semantics.

What changed

Custom agent files on v1

  • New profile/agentfile/ module: frontmatter parsing (shared with the skill parser; Claude Code comma-list and OpenCode file-name fallback compatible), user/extra/project/explicit discovery roots mirroring skill discovery, per-source priority merge, override: true gate before a file replaces a same-name builtin, SYSTEM.md main-prompt override, and dead-pattern warnings (bare *, incomplete mcp__ literals, unknown tool names).
  • SessionAgentProfileCatalog merges builtin and file profiles. ${base_prompt} binds to an "effective default" slot (the SYSTEM.md override when present, else the builtin default); the slot is structurally disjoint from the merge, so a file that overrides the default cannot recurse into itself. The delegation graph links file profiles' subagents allowlists and extends the default profile's delegatable set with custom agents.
  • Session integration: catalog loading rides the existing skills readiness gate (an invalid --agent-file fails session creation); the three hardcoded DEFAULT_AGENT_PROFILES lookups (subagent host, persisted-profile restore, Agent tool description) now read the catalog.
  • CLI/SDK: --agent/--agent-file work in print mode on either engine (the TUI still rejects them, matching v2); CreateSessionOptions gains agentProfile/agentFiles.

Secondary model on v1 (experimental flag)

  • [secondary_model] config section (a model pointer plus model patch fields) with KIMI_SECONDARY_MODEL/KIMI_SECONDARY_EFFORT env overlays; a recipe with patch fields synthesizes an in-memory __secondary__ derived entry that is stripped on write and never reaches config.toml.
  • Spawn binding with three-level precedence (tool-call model > profile model_preference > configured secondary default), upfront validation via the provider manager with a wrapped error pointing at [secondary_model]; with the flag on, resume/retry keeps the subagent's bound model (v2 semantics), and with the flag off, inheritance behavior is unchanged.
  • The Agent/AgentSwarm tools gain a primary|secondary model parameter (available models advertised in the tool description); startup validation surfaces secondary-model-invalid / secondary-model-effort-not-listed through the existing session warnings channel.
  • Full disallowedTools deny semantics: exact names and mcp__ glob patterns evaluated by the tool manager against resolved tool names (partial server denies like mcp__github__* work under a broad mcp__* allow). The deny list persists in the agent wire as an additive optional field (old records and older binaries are both compatible), so resumed agents keep the denylist.
  • The interactive TUI gains a /secondary_model command (mirrors /model: a picker with a thinking-effort step) that persists [secondary_model] and live-applies to the current session via Session.applyPersistedSecondaryModel (node-sdk wrapper included), so newly spawned subagents bind the new model right away. The /model picker hides the synthesized __secondary__ derived entry, and the update-config builtin skill now lists the section.
  • Running subagents surface their bound model in the TUI: the spawned agent's agent.status.updated carries its model alias, which the tool-call subagent stats and agent-group rows resolve to a display name.

Verification: full agent-core suite green (4075 tests, ~60 new cases covering parser/discovery/catalog merge/${base_prompt} chain/secondary config round-trip/spawn binding/tool deny/wire replay/session secondary-model override); kimi-code options, run-prompt, and TUI suites green (2401 tests, including the /secondary_model command and the subagent model display); end-to-end smoke on the v1 engine (custom agent discovery, --agent selection, invalid --agent-file failure). Docs updated in both English and Chinese.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…gine

Migrate the custom agentfile and secondary-model capabilities from
agent-core-v2 to the v1 engine so they work in the TUI and plain
kimi -p sessions:

- discover Markdown agent files from user/project/extra/explicit
  directories with the v2 precedence rules, a merged session profile
  catalog replacing the hardcoded builtin profile lookups, SYSTEM.md
  main prompt override, and ${base_prompt} backed by the effective
  default
- --agent/--agent-file now work in print mode on the default engine;
  CreateSessionOptions gains agentProfile/agentFiles
- [secondary_model] config + KIMI_SECONDARY_MODEL/EFFORT bind newly
  spawned subagents to a cheaper model behind the secondary-model
  experiment flag, with primary/secondary model params on Agent and
  AgentSwarm and upfront session warnings
- full disallowedTools deny semantics (exact names + mcp__ globs)
  evaluated by the tool manager and persisted in the agent wire
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 22a0a69

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@22a0a69
npx https://pkg.pr.new/@moonshot-ai/kimi-code@22a0a69

commit: 22a0a69

7Sageer and others added 19 commits July 27, 2026 13:27
runPrompt is also driven programmatically (headless goal flow) with
options that never pass through the CLI parser defaults, so agentFiles
can be undefined; mirror the addDirs optional-chaining pattern. Also
extend the SDK experimental-feature assertion with the secondary-model
flag.
Signed-off-by: 7Sageer <sag77r@hotmail.com>
Signed-off-by: 7Sageer <sag77r@hotmail.com>
Signed-off-by: 7Sageer <sag77r@hotmail.com>
Signed-off-by: 7Sageer <sag77r@hotmail.com>
The resume path only forwards the agent file's name for the bound-profile
assertion; the file's content is never re-applied (the session keeps its
creation-time catalog snapshot). Previously the combination was silently
accepted, so an edited file (or a same-named one) appeared to apply but did
not. Reject it at option validation and document the constraint.
… agentfile headers

The Windows notes, additional-dirs and skills prose blocks existed twice:
inline in the builtin default template (system.md) and as constants in the
agent-file renderer (from-file.ts). Extract them to profile/prompt-sections.ts
as the single source: system.md renders them through injected KIMI_* template
variables and from-file.ts imports the same constants. Rendered prompts are
byte-identical for all four builtin profiles across macOS/Windows and
skills/dirs on/off; a new test pins system.md to the shared constants.

Also mark each profile/agentfile file with the path of its agent-core-v2
counterpart so format/semantics changes land in both engines.
Mirror /model: a picker with a thinking-effort step that persists [secondary_model] and live-applies to the current session via a new Session.setSecondaryModel RPC (node-sdk wrapper included), so newly spawned subagents bind the new model right away. The /model picker now hides the synthesized __secondary__ derived entry; docs and the update-config builtin skill mention the section.
Subagents report their model alias via agent.status.updated after spawn; resolve it to a display name and surface it in tool-call subagent stats and agent-group rows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant