mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-12 19:10:55 -07:00
hmm speculative
This commit is contained in:
@@ -37,8 +37,17 @@ export class IrProjector {
|
||||
}
|
||||
|
||||
const maxTokens = sidecar.budget.maxTokens;
|
||||
const currentTokens =
|
||||
env.tokenCalculator.calculateConcreteListTokens(ship);
|
||||
const currentTokens = env.tokenCalculator.calculateConcreteListTokens(ship);
|
||||
|
||||
// V0: Always protect the first node (System Prompt) and the last turn
|
||||
if (ship.length > 0) {
|
||||
protectedIds.add(ship[0].id);
|
||||
if (ship[0].logicalParentId) protectedIds.add(ship[0].logicalParentId);
|
||||
|
||||
const lastNode = ship[ship.length - 1];
|
||||
protectedIds.add(lastNode.id);
|
||||
if (lastNode.logicalParentId) protectedIds.add(lastNode.logicalParentId);
|
||||
}
|
||||
|
||||
if (currentTokens <= maxTokens) {
|
||||
tracer.logEvent(
|
||||
@@ -101,11 +110,11 @@ export class IrProjector {
|
||||
const skipList = new Set<string>();
|
||||
for (const node of processedShip) {
|
||||
if (node.abstractsIds) {
|
||||
for (const id of node.abstractsIds) skipList.add(id);
|
||||
for (const id of node.abstractsIds) skipList.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
const visibleShip = processedShip.filter(n => !skipList.has(n.id));
|
||||
const visibleShip = processedShip.filter((n) => !skipList.has(n.id));
|
||||
|
||||
const contents = IrMapper.fromIr(visibleShip);
|
||||
tracer.logEvent('IrProjector', 'Projected Sanitized Context to LLM', {
|
||||
|
||||
@@ -37,8 +37,8 @@ function isCompleteEpisode(ep: Partial<Episode>): ep is Episode {
|
||||
return (
|
||||
typeof ep.id === 'string' &&
|
||||
typeof ep.timestamp === 'number' &&
|
||||
Array.isArray(ep.concreteNodeIds) &&
|
||||
ep.concreteNodeIds.length > 0
|
||||
Array.isArray(ep.concreteNodes) &&
|
||||
ep.concreteNodes.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ function parseToolResponses(
|
||||
currentEpisode = {
|
||||
id: getStableId(msg),
|
||||
timestamp: Date.now(),
|
||||
concreteNodeIds: [getStableId(msg.parts![0] || msg)],
|
||||
concreteNodes: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -152,7 +152,10 @@ function parseToolResponses(
|
||||
transformations: [],
|
||||
},
|
||||
};
|
||||
currentEpisode.concreteNodeIds = [...(currentEpisode.concreteNodeIds || []), step.id];
|
||||
currentEpisode.concreteNodes = [
|
||||
...(currentEpisode.concreteNodes || []),
|
||||
step,
|
||||
];
|
||||
if (callId) pendingCallParts.delete(callId);
|
||||
}
|
||||
}
|
||||
@@ -193,7 +196,8 @@ function parseUserParts(
|
||||
return {
|
||||
id: getStableId(msg),
|
||||
timestamp: Date.now(),
|
||||
concreteNodeIds: [trigger.id], };
|
||||
concreteNodes: [trigger],
|
||||
};
|
||||
}
|
||||
|
||||
function parseModelParts(
|
||||
@@ -206,7 +210,7 @@ function parseModelParts(
|
||||
currentEpisode = {
|
||||
id: getStableId(msg),
|
||||
timestamp: Date.now(),
|
||||
concreteNodeIds: [getStableId(msg.parts![0] || msg)],
|
||||
concreteNodes: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -221,25 +225,29 @@ function parseModelParts(
|
||||
text: part.text,
|
||||
metadata: createMetadata([part]),
|
||||
};
|
||||
currentEpisode.concreteNodeIds = [...(currentEpisode.concreteNodeIds || []), thought.id];
|
||||
currentEpisode.concreteNodes = [
|
||||
...(currentEpisode.concreteNodes || []),
|
||||
thought,
|
||||
];
|
||||
}
|
||||
}
|
||||
return currentEpisode as Partial<Episode>;
|
||||
}
|
||||
|
||||
function finalizeYield(currentEpisode: Partial<Episode>) {
|
||||
if (currentEpisode.concreteNodeIds && currentEpisode.concreteNodeIds.length > 0) {
|
||||
const yieldNode: AgentYield = {
|
||||
id: randomUUID(),
|
||||
type: 'AGENT_YIELD',
|
||||
text: 'Yield', // Synthesized yield since we don't have the original concrete node
|
||||
metadata: {
|
||||
originalTokens: 1,
|
||||
currentTokens: 1,
|
||||
transformations: []
|
||||
},
|
||||
};
|
||||
const existingNodes = currentEpisode.concreteNodeIds as string[];
|
||||
currentEpisode.concreteNodeIds = [...existingNodes.slice(0, -1), yieldNode.id];
|
||||
if (currentEpisode.concreteNodes && currentEpisode.concreteNodes.length > 0) {
|
||||
const yieldNode: AgentYield = {
|
||||
id: randomUUID(),
|
||||
type: 'AGENT_YIELD',
|
||||
text: 'Yield', // Synthesized yield since we don't have the original concrete node
|
||||
metadata: {
|
||||
originalTokens: 1,
|
||||
currentTokens: 1,
|
||||
transformations: [],
|
||||
},
|
||||
};
|
||||
const existingNodes =
|
||||
currentEpisode.concreteNodes as import('./types.js').ConcreteNode[];
|
||||
currentEpisode.concreteNodes = [...existingNodes, yieldNode];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export type IrNodeType =
|
||||
| 'AGENT_THOUGHT'
|
||||
| 'TOOL_EXECUTION'
|
||||
| 'AGENT_YIELD'
|
||||
|
||||
|
||||
// Synthetic Concrete Nodes
|
||||
| 'SNAPSHOT'
|
||||
| 'ROLLING_SUMMARY'
|
||||
@@ -56,17 +56,17 @@ export interface IrNode {
|
||||
readonly metadata: IrMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Concrete Nodes: The atomic, renderable pieces of data.
|
||||
* These are the actual "planks" of the Ship of Theseus.
|
||||
*/
|
||||
export interface BaseConcreteNode extends IrNode {
|
||||
/** The ID of the Logical Node (e.g., Episode) that structurally owns this node */
|
||||
readonly logicalParentId?: string;
|
||||
|
||||
|
||||
/** If this node replaced a single node 1:1 (e.g., masking), this points to the original */
|
||||
readonly replacesId?: string;
|
||||
|
||||
|
||||
/** If this node is a synthetic summary of N nodes, this points to the original IDs */
|
||||
readonly abstractsIds?: readonly string[];
|
||||
}
|
||||
@@ -171,14 +171,14 @@ export interface RollingSummary extends BaseConcreteNode {
|
||||
|
||||
export type SyntheticLeaf = Snapshot | RollingSummary;
|
||||
|
||||
export type ConcreteNode =
|
||||
| UserPrompt
|
||||
| SystemEvent
|
||||
| AgentThought
|
||||
| ToolExecution
|
||||
| MaskedTool
|
||||
| AgentYield
|
||||
| Snapshot
|
||||
export type ConcreteNode =
|
||||
| UserPrompt
|
||||
| SystemEvent
|
||||
| AgentThought
|
||||
| ToolExecution
|
||||
| MaskedTool
|
||||
| AgentYield
|
||||
| Snapshot
|
||||
| RollingSummary;
|
||||
|
||||
/**
|
||||
@@ -189,7 +189,7 @@ export interface Episode extends IrNode {
|
||||
readonly type: 'EPISODE';
|
||||
readonly timestamp: number;
|
||||
/** References to the Concrete Node IDs that conceptually belong to this Episode. */
|
||||
concreteNodeIds: readonly string[];
|
||||
concreteNodes: readonly ConcreteNode[];
|
||||
}
|
||||
|
||||
export interface Task extends IrNode {
|
||||
|
||||
Reference in New Issue
Block a user