feat(agent-core): custom agent files and secondary model on the v1 engine#2232
Open
7Sageer wants to merge 20 commits into
Open
feat(agent-core): custom agent files and secondary model on the v1 engine#22327Sageer wants to merge 20 commits into
7Sageer wants to merge 20 commits into
Conversation
…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 detectedLatest commit: 22a0a69 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/ experimentalkimi -p). Sessions on the default engine — the interactive TUI and plainkimi -p— could not discover or delegate to custom agents, override the main agent's system prompt viaSYSTEM.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
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: truegate before a file replaces a same-name builtin,SYSTEM.mdmain-prompt override, and dead-pattern warnings (bare*, incompletemcp__literals, unknown tool names).SessionAgentProfileCatalogmerges builtin and file profiles.${base_prompt}binds to an "effective default" slot (theSYSTEM.mdoverride 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'subagentsallowlists and extends the default profile's delegatable set with custom agents.--agent-filefails session creation); the three hardcodedDEFAULT_AGENT_PROFILESlookups (subagent host, persisted-profile restore, Agent tool description) now read the catalog.--agent/--agent-filework in print mode on either engine (the TUI still rejects them, matching v2);CreateSessionOptionsgainsagentProfile/agentFiles.Secondary model on v1 (experimental flag)
[secondary_model]config section (amodelpointer plus model patch fields) withKIMI_SECONDARY_MODEL/KIMI_SECONDARY_EFFORTenv overlays; a recipe with patch fields synthesizes an in-memory__secondary__derived entry that is stripped on write and never reachesconfig.toml.model> profilemodel_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.Agent/AgentSwarmtools gain aprimary|secondarymodelparameter (available models advertised in the tool description); startup validation surfacessecondary-model-invalid/secondary-model-effort-not-listedthrough the existing session warnings channel.disallowedToolsdeny semantics: exact names andmcp__glob patterns evaluated by the tool manager against resolved tool names (partial server denies likemcp__github__*work under a broadmcp__*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./secondary_modelcommand (mirrors/model: a picker with a thinking-effort step) that persists[secondary_model]and live-applies to the current session viaSession.applyPersistedSecondaryModel(node-sdk wrapper included), so newly spawned subagents bind the new model right away. The/modelpicker hides the synthesized__secondary__derived entry, and theupdate-configbuiltin skill now lists the section.agent.status.updatedcarries 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_modelcommand and the subagent model display); end-to-end smoke on the v1 engine (custom agent discovery,--agentselection, invalid--agent-filefailure). Docs updated in both English and Chinese.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.