feat(agent): opt-in tool-result context pruning
This commit is contained in:
committed by
Peter Steinberger
parent
937e0265a3
commit
eeaa6ea46f
39
src/agents/pi-extensions/context-pruning/runtime.ts
Normal file
39
src/agents/pi-extensions/context-pruning/runtime.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { EffectiveContextPruningSettings } from "./settings.js";
|
||||
|
||||
export type ContextPruningRuntimeValue = {
|
||||
settings: EffectiveContextPruningSettings;
|
||||
contextWindowTokens?: number | null;
|
||||
isToolPrunable: (toolName: string) => boolean;
|
||||
};
|
||||
|
||||
// Session-scoped runtime registry keyed by object identity.
|
||||
// Important: this relies on Pi passing the same SessionManager object instance into
|
||||
// ExtensionContext (ctx.sessionManager) that we used when calling setContextPruningRuntime.
|
||||
const REGISTRY = new WeakMap<object, ContextPruningRuntimeValue>();
|
||||
|
||||
export function setContextPruningRuntime(
|
||||
sessionManager: unknown,
|
||||
value: ContextPruningRuntimeValue | null,
|
||||
): void {
|
||||
if (!sessionManager || typeof sessionManager !== "object") {
|
||||
return;
|
||||
}
|
||||
|
||||
const key = sessionManager as object;
|
||||
if (value === null) {
|
||||
REGISTRY.delete(key);
|
||||
return;
|
||||
}
|
||||
|
||||
REGISTRY.set(key, value);
|
||||
}
|
||||
|
||||
export function getContextPruningRuntime(
|
||||
sessionManager: unknown,
|
||||
): ContextPruningRuntimeValue | null {
|
||||
if (!sessionManager || typeof sessionManager !== "object") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return REGISTRY.get(sessionManager as object) ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user