Skip to content

Commit 6a3c8ab

Browse files
committed
refactor(agent): drop tool-set digest narration
1 parent 5357a1a commit 6a3c8ab

2 files changed

Lines changed: 0 additions & 28 deletions

File tree

‎src/agent/director.ts‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ const logger = getLogger([LOG_NAMESPACE_ROOT, "agent", "director"]);
5959
// (mount, description edit, reorder) drops the next turn's cache hit. The
6060
// digest stays deterministic — it only moves when discovery grows the set.
6161
// Hashed: MCP descriptions are arbitrary server text, not log material.
62-
//
63-
// Pure by design: the memoization lives on the director (_toolSetDigest), the
64-
// only production caller, so the module keeps no per-array state. Callers swap
65-
// tool arrays wholesale (constructor, updateToolDefinitions) without in-place
66-
// mutation; mutating an installed array in place would leave the director's
67-
// cached digest stale.
6862
export function toolSetDigest(tools: readonly ToolDefinition[]): string {
6963
const shape = tools
7064
.map(
@@ -481,12 +475,6 @@ class ChatDirectorImpl extends DefaultDirector {
481475
private readonly askOperatorCalls = new Set<string>();
482476
private readonly _systemPrompt: string;
483477
private _toolDefinitions: ToolDefinition[];
484-
// Digest of the installed _toolDefinitions, stored when the array is set so
485-
// updateToolDefinitions can compare an incoming set without re-hashing the
486-
// current one. One slot per director — the digest is only consumed by the
487-
// next update on this instance, never by shared/static context (all
488-
// production call sites are here). Stale only if a caller mutates the
489-
// installed array in place; callers swap arrays wholesale instead.
490478
private _toolSetDigest: string | undefined;
491479
private inactivityTimeoutMs: number | undefined;
492480
private totalTimeoutMs: number | undefined;
@@ -712,9 +700,6 @@ class ChatDirectorImpl extends DefaultDirector {
712700
}
713701

714702
updateToolDefinitions(toolDefinitions: ToolDefinition[]): void {
715-
// The stored digest covers the current set (installed by the constructor
716-
// or a prior update); only the very first update has to hash it, and the
717-
// fallback runs once per director.
718703
const before = this._toolSetDigest ?? toolSetDigest(this._toolDefinitions);
719704
const after = toolSetDigest(toolDefinitions);
720705
this._toolDefinitions = toolDefinitions;

‎src/agent/tool-set-digest.test.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { describe, expect, test } from "bun:test";
22
import { withMockedModule } from "../../testkit/mock-module.js";
33

4-
// Spy on createHash to prove toolSetDigest memoizes per director: installing
5-
// a tool set runs the sha256 exactly once for that set, and comparing a later
6-
// update against the stored per-director digest must not re-hash the previous
7-
// set. The mock delegates to the real implementation (captured before mocking)
8-
// so behavior is unchanged; hashCalls only measures the delta around each
9-
// assertion.
104
let hashCalls = 0;
115
await withMockedModule<typeof import("node:crypto")>(
126
import.meta.resolve("node:crypto"),
@@ -19,7 +13,6 @@ await withMockedModule<typeof import("node:crypto")>(
1913
}),
2014
);
2115

22-
// Dynamic import so director.ts resolves node:crypto through the mock above.
2316
const { createChatDirector } = await import("./director.js");
2417

2518
const base = {
@@ -34,11 +27,8 @@ describe("toolSetDigest memoization", () => {
3427
const tools = [{ ...base }];
3528
const changed = [{ ...base, description: "changed" }];
3629

37-
// Warm-up installs `tools`; its digest is stored on the director.
3830
director.updateToolDefinitions(tools);
3931
hashCalls = 0;
40-
// The previous set's digest comes from the per-director field (no re-hash);
41-
// only the incoming set is hashed.
4232
director.updateToolDefinitions(changed);
4333
expect(hashCalls).toBe(1);
4434
});
@@ -51,9 +41,6 @@ describe("toolSetDigest memoization", () => {
5141
director.updateToolDefinitions(tools);
5242
director.updateToolDefinitions(changed);
5343
hashCalls = 0;
54-
// A fresh reference (even with identical content) misses the stored slot
55-
// and re-runs the hash; the digest gates the tool-set-changed log, so
56-
// identical content still logs nothing.
5744
director.updateToolDefinitions([{ ...base }]);
5845
expect(hashCalls).toBe(1);
5946
});

0 commit comments

Comments
 (0)