Skip to content

feat(agent-core): thread roleAdditional through the session API#2033

Open
TennyZhuang wants to merge 2 commits into
MoonshotAI:mainfrom
TennyZhuang:port-roleadditional-behavior
Open

feat(agent-core): thread roleAdditional through the session API#2033
TennyZhuang wants to merge 2 commits into
MoonshotAI:mainfrom
TennyZhuang:port-roleadditional-behavior

Conversation

@TennyZhuang

@TennyZhuang TennyZhuang commented Jul 22, 2026

Copy link
Copy Markdown

Related Issue

No prior issue — the problem is described below. Happy to open a tracking issue if preferred.

Problem

The agent profile system already renders a {{ROLE_ADDITIONAL}} slot: profile/resolve.ts reads context.roleAdditional as the highest-precedence source for it (profile/types.ts types it, system.md references it, and the default profiles set it via promptVars). But nothing populates context.roleAdditional — there is no way to set it through the session API. The render half exists with no input path, so a caller cannot inject a standing/role prompt without editing profiles on disk.

What changed

Thread an optional roleAdditional string, parallel to the existing additionalDirs, at every layer:

  • node-sdk: CreateSessionOptions / ResumeSessionInput
  • core RPC: CreateSessionPayload / ResumeSessionPayload
  • Session / Agent: into updateSystemPromptFromProfile, which passes it to the profile render context that already accepts roleAdditional

Resume/reload semantics: an explicit roleAdditional that differs from the value that rendered an agent's persisted prompt (tracked via AgentMeta.roleAdditional) re-renders that agent's system prompt from the restored profile — without refreshing AGENTS.md/cwd. An omitted value preserves the persisted standing prompt, so Session.reloadSession() / /reload (which cannot pass one) no longer clears the slot; an explicit empty string still clears it.

Additive and optional: no behavior change when roleAdditional is unset. Follows the existing additionalDirs threading pattern throughout. agent-core and node-sdk typecheck clean.

Checklist

  • I have explained the problem above.
  • I have added tests that prove my feature works — test/session/resume-roleadditional.test.ts (4 tests, passing).
  • Added a changeset — .changeset/roleadditional-session-api.md (minor).
  • Docs: this is an additive optional session option; no doc update included.

The agent profile system already renders a {{ROLE_ADDITIONAL}} slot
(profile/resolve.ts + system.md) but there was no way to set it through
the SDK — the render half existed with no input path.

Thread an optional `roleAdditional` string parallel to `additionalDirs`
at every layer: node-sdk CreateSessionOptions/ResumeSessionInput ->
core CreateSessionPayload/ResumeSessionPayload -> Session/Agent ->
updateSystemPromptFromProfile. On resume, if `roleAdditional` differs
from the value that rendered an agent's persisted prompt (tracked via
AgentMeta.roleAdditional), re-render just that agent's system prompt
from the restored profile. Additive and optional; no behavior change
when unset.
@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2a04750

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

This PR includes changesets to release 5 packages
Name Type
@moonshot-ai/agent-core Minor
@moonshot-ai/kimi-code-sdk Minor
@moonshot-ai/acp-adapter Patch
@moonshot-ai/migration-legacy Patch
kimi-code Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ca2a3c2d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// prompt using the restored profile and the fresh context. This keeps the
// persisted profile in sync with the new standing instructions without
// refreshing AGENTS.md/cwd on every resume.
if (this.roleAdditional !== meta.roleAdditional) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve roleAdditional across reload

When a session that was created or resumed with roleAdditional is later reloaded, the reload path calls resumeSessionWithOverrides({ sessionId }) without a way to pass the previous value, so this.roleAdditional is undefined here while meta.roleAdditional still contains the original text. This comparison then refreshes the system prompt with the {{ROLE_ADDITIONAL}} slot cleared and records undefined, silently dropping the standing prompt on SDK Session.reloadSession()//reload; either thread the value through reload or treat an omitted value as preserving the persisted prompt.

Useful? React with 👍 / 👎.

Session.reloadSession()/`/reload` (and a plain resume without the field)
call resume with no roleAdditional, so the session-level value was
undefined while the agent's persisted metadata still held the original
text. The resume-time comparison then re-rendered the system prompt with
an empty {{ROLE_ADDITIONAL}} slot and recorded undefined, silently
dropping the standing prompt.

Restore the persisted roleAdditional from the main agent's metadata on
resume when the caller omits it, so an omitted value preserves the
standing prompt (and newly-spawned agents keep inheriting it). An
explicit value still overrides, and an explicit empty string still
clears it.
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