-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor(agent-core-v2): carry the context fold cursor in state and converge fold/projection internals #2875
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
Changes from 16 commits
8780d6a
2d41945
e83ad3f
2b47fe7
e7fe16e
55b9e0b
c5cf562
a8ee42c
5ddab0c
8892e84
5ba63a4
a7a0b45
29c0a54
51f31ae
641157e
2c36afe
a085428
450645f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,6 @@ | ||
| /** | ||
| * `contextMemory` domain — `IAgentContextMemoryService` implementation. | ||
| * | ||
| * Owns per-agent conversation history through `wire`, maintains measurements | ||
| * with `tokenCounting`, and broadcasts live mutations through `event`. Every | ||
| * splice-shaped mutation (`clear` / `applyCompaction` / `undo`, plus verified | ||
| * cross-model trailing removal) publishes `context.spliced` from the live path | ||
| * only — replay rebuilds silently — and truncates the measured-anchor ledger | ||
| * when a cut crosses an anchor, letting `tokenCounting` restore the surviving | ||
| * prefix's REAL size from the remaining anchors. Bound at Agent scope. | ||
| * Owns the Agent-scoped bounded context window, persists its mutations, keeps | ||
| * token anchors aligned, and publishes live splice events to consumers. | ||
| */ | ||
|
Comment on lines
1
to
11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The shortened header no longer starts with the required AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L38-L40 Useful? React with 👍 / 👎. |
||
|
|
||
| import { Disposable } from '#/_base/di/lifecycle'; | ||
|
|
@@ -30,16 +23,18 @@ import { | |
| } from './contextMemory'; | ||
| import { buildContextCompactionShape, type TokenEstimate } from './compactionHandoff'; | ||
| import { | ||
| computeUndoCut, | ||
| ContextModel, | ||
| contextAppendLoopEvent, | ||
| contextAppendMessage, | ||
| contextApplyCompaction, | ||
| contextClear, | ||
| contextUndo, | ||
| } from './contextOps'; | ||
| import { | ||
| computeUndoCut, | ||
| isFullyUndoable, | ||
| type UndoCut, | ||
| } from './contextOps'; | ||
| } from './conversationTime'; | ||
| import type { LoopRecordedEvent } from './loopEventFold'; | ||
| import type { ContextMessage } from './types'; | ||
|
|
||
|
|
@@ -54,7 +49,6 @@ declare module '#/app/event/eventBus' { | |
| } | ||
| } | ||
|
|
||
| // NOTE: stays Disposable — its own 'get' collides with the Fiber | ||
| export class AgentContextMemoryService extends Disposable implements IAgentContextMemoryService { | ||
| declare readonly _serviceBrand: undefined; | ||
|
|
||
|
|
@@ -75,7 +69,11 @@ export class AgentContextMemoryService extends Disposable implements IAgentConte | |
| } | ||
|
|
||
| get(): readonly ContextMessage[] { | ||
| return this.wire.getModel(ContextModel) as readonly ContextMessage[]; | ||
| return this.getMessageLog(); | ||
| } | ||
|
|
||
| getMessageLog(): readonly ContextMessage[] { | ||
| return this.wire.getModel(ContextModel).messages as readonly ContextMessage[]; | ||
| } | ||
|
|
||
| append(...messages: readonly ContextMessage[]): void { | ||
|
|
@@ -172,9 +170,6 @@ export class AgentContextMemoryService extends Disposable implements IAgentConte | |
| private sizeOpsForCut(cutIndex: number): Op[] { | ||
| const model = this.wire.getModel(TokenCountingModel); | ||
| if (!model.anchors.some((anchor) => anchor.length > cutIndex)) return []; | ||
| // The display tokens are the post-cut size computed from the CURRENT | ||
| // ledger — anchors at or below the cut are identical before and after | ||
| // the truncation, so the pre-dispatch read is exact. | ||
| return [ | ||
| tokenCountingTruncated({ | ||
| length: cutIndex, | ||
|
|
||
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 rewritten header no longer begins with the required
`contextMemory` domain — ...identity line and omits the helper’s cross-domain roles, including token estimation throughkosongand reminder rendering throughsystemReminder. Restore those ownership details in the top-of-file block so the module remains discoverable under the package’s mandatory header convention.AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L38-L40
Useful? React with 👍 / 👎.