Repository navigation
feat(agent-core-v2): add a fork parameter to the Agent tool #3007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
f51209a
feat(agent-core-v2): add a fork parameter to the Agent tool
7Sageer c93fede
fix(agent-core-v2): bind the stale-todo reminder only into the main a…
7Sageer 2844e13
fix(agent-core-v2): inherit the caller's live binding and label fork …
7Sageer d32a871
fix(agent-core-v2): close inherited in-flight tool calls instead of t…
7Sageer 51b5403
refactor(agent-core-v2): route Agent tool forks through agentLifecycl…
7Sageer 6cfc57d
Merge remote-tracking branch 'origin/main' into fork-subagent
7Sageer 4b8095d
feat(agent-core-v2): add a fork parameter to the AgentSwarm tool
7Sageer f7fdc19
Merge remote-tracking branch 'origin/main' into fork-subagent
7Sageer 9c68567
fix(agent-core-v2): seal partial assistant forks
7Sageer 3fa0d0a
fix(agent-core-v2): align fork parameter descriptions
7Sageer 65af0ca
fix(agent-core-v2): drop the main-only registration gate from goal tools
7Sageer 0e68451
Merge remote-tracking branch 'origin/main' into fork-subagent
7Sageer ecbaf05
fix(agent-core-v2): disclose dates via reminders to keep the system p…
7Sageer fe9bfdf
docs: condense the fork changesets to single sentences
7Sageer 56c1329
docs(agent-core-v2): frame the tool-contribution when gate as a fork …
7Sageer 957b3a6
test(agent-core-v2): plug fork coverage gaps and decouple swarm tests…
7Sageer 1de050e
Merge remote-tracking branch 'origin/fork-subagent' into fork-subagent
7Sageer 7aad1fc
docs(agent-core-v2): keep the when-gate guidance in the contribution …
7Sageer 261e60f
fix(agent-core-v2): contribute cron tools to every agent for fork pre…
7Sageer 4777fd5
feat(agent-core-v2): track the fork parameter in the subagent_created…
7Sageer 014c367
fix(agent-core-v2): gate tower orchestration tools at execution time
7Sageer 66f104d
test(agent-core-v2): expect the fork field in the subagent_created mi…
7Sageer c99ec1f
test(agent-core-v2): cover fork subagent first-request prefix parity
7Sageer b4e4a94
refactor(agent-core-v2): share the main-agent-only tool refusal acros…
7Sageer 35f6a13
Merge remote-tracking branch 'origin/main' into fork-subagent
7Sageer fc09a8f
refactor(agent-core-v2): keep the goal main-agent gate at the tool la…
7Sageer a77d8a5
fix(agent-core-v2): preserve the fork tool surface when inheriting us…
7Sageer eeafd0f
Revert "refactor(agent-core-v2): keep the goal main-agent gate at the…
7Sageer 7eaed14
test(agent-core-v2): complete fork lifecycle stub
7Sageer a3a58d6
Delete .changeset/btw-inflight-tool-calls.md
7Sageer 3234a05
Delete .changeset/todo-reminder-main-only.md
7Sageer 3227e09
Delete .changeset/swarm-fork-context.md
7Sageer 4176ff8
Add optional 'fork' parameter to subagent tools
7Sageer c390800
docs(agent-core-v2): drop the fork JSDoc comments
7Sageer f70b856
Merge remote-tracking branch 'origin/main' into fork-subagent
7Sageer 0c93629
feat(agent-core-v2): add prompt_cache_probe telemetry for forked agents
7Sageer 2efffa0
Merge remote-tracking branch 'origin/main' into fork-subagent
7Sageer 8b30c28
feat(agent-core-v2): gate the subagent fork parameter behind an exper…
7Sageer 9c74db8
Merge remote-tracking branch 'origin/main' into fork-subagent
7Sageer 63a178e
Merge remote-tracking branch 'origin/main' into fork-subagent
7Sageer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Fix side-question conversations started while the main agent is mid-task: tool calls still running on the main agent are now marked as unfinished in the side conversation instead of dangling, so the side agent no longer reports their results as lost. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": minor | ||
| --- | ||
|
|
||
| Subagents can now fork the current context: the Agent tool accepts an optional `fork` parameter that starts the subagent with a snapshot of the calling agent's conversation history — same agent type, tool set, and model — instead of zero context. Tool calls still in flight at fork time are carried over explicitly marked as unfinished. The model opts in per spawn with `fork: true` when a task builds on the current conversation. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": minor | ||
| --- | ||
|
|
||
| Agent swarms can now fork the current context: the AgentSwarm tool accepts an optional `fork` parameter that starts every item-spawned subagent with a snapshot of the calling agent's conversation history — same agent type, tool set, and model — instead of zero context. Pass `fork: true` when every item builds on the current conversation. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Only the main agent now receives the stale-todo-list reminder; subagents keep sharing the session todo list but are no longer nudged about it. |
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
48 changes: 48 additions & 0 deletions
48
packages/agent-core-v2/src/agent/contextMemory/openToolExchange.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { createToolMessage } from '#/kosong/contract/message'; | ||
|
|
||
| import type { ContextMessage } from './types'; | ||
|
|
||
| export const INHERITED_IN_FLIGHT_TOOL_OUTPUT = | ||
| 'This tool call was still executing when this conversation snapshot was inherited from the source agent, so its result is not part of this context. The outcome is unknown — do not assume it succeeded or failed, and do not wait for it.'; | ||
|
|
||
| /** | ||
| * Closes a trailing open tool exchange in a history about to seed another | ||
| * agent's context memory. The source's in-flight tool calls can never receive | ||
| * their real results in the inheriting agent, so each unclosed call is | ||
| * answered with a synthetic {@link INHERITED_IN_FLIGHT_TOOL_OUTPUT} tool | ||
| * message rather than trimmed away — the seeded conversation stays | ||
| * well-formed and the source's final step remains visible as reference. | ||
| */ | ||
| export function closeTrailingOpenToolExchange( | ||
| history: readonly ContextMessage[], | ||
| ): ContextMessage[] { | ||
| let lastNonToolIndex = history.length - 1; | ||
| while (lastNonToolIndex >= 0 && history[lastNonToolIndex]?.role === 'tool') { | ||
| lastNonToolIndex -= 1; | ||
| } | ||
|
|
||
| const assistant = history[lastNonToolIndex]; | ||
| if (assistant === undefined) return []; | ||
| if (assistant.role !== 'assistant' || assistant.toolCalls.length === 0) return [...history]; | ||
|
|
||
| const answeredToolCallIds = new Set( | ||
| history | ||
| .slice(lastNonToolIndex + 1) | ||
| .map((message) => message.toolCallId) | ||
| .filter((toolCallId): toolCallId is string => typeof toolCallId === 'string'), | ||
| ); | ||
| const openCalls = assistant.toolCalls.filter( | ||
| (toolCall) => !answeredToolCallIds.has(toolCall.id), | ||
| ); | ||
| if (openCalls.length === 0) return [...history]; | ||
| const settledAssistant = | ||
| assistant.partial === true ? { ...assistant, partial: undefined } : assistant; | ||
| return [ | ||
| ...history.slice(0, lastNonToolIndex), | ||
| settledAssistant, | ||
| ...history.slice(lastNonToolIndex + 1), | ||
| ...openCalls.map((toolCall) => | ||
| createToolMessage(toolCall.id, INHERITED_IN_FLIGHT_TOOL_OUTPUT), | ||
| ), | ||
| ]; | ||
| } |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entry uses three sentences and mixes the fork feature with in-flight-call handling and usage guidance;
.changeset/swarm-fork-context.mdlikewise uses multiple sentences. The repository requires every changeset to contain one short user-facing sentence stating only what changed, so condense each entry and leave the separately changesetted in-flight fix out of this one.AGENTS.md reference: AGENTS.md:L85-L87
Useful? React with 👍 / 👎.