Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/common/src/base/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export const PochiClientHeader = "x-pochi-client";
export const PochiRequestUseCaseHeader = "x-pochi-request-use-case";

/**
* Task Memory thresholds — background extraction of session notes.
* Task Memory extracts once per compaction cycle. Everything after the
* extraction boundary survives compaction verbatim, so a second extraction in
* the same cycle would only shrink that tail; only failures are retried.
*/
export const TaskMemoryInitTokenThreshold = 10_000;
export const TaskMemoryUpdateTokenIncrement = 5_000;
export const TaskMemoryUpdateToolCallThreshold = 3;
export const TaskMemoryExtractionThresholdRatio = 0.8;
export const MaxTaskMemoryExtractionAttemptsPerCycle = 2;
export const TaskMemoryFallbackCompactThreshold = 120_000;

/**
* Timeout (ms) for any single git operation.
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export interface BackgroundTaskState {
tools?: readonly ToolSpecInput[];
parentTaskId?: string;
useCase?: ForkAgentUseCase;
/** Maximum number of steps this background task may run. */
maxSteps?: number;
/** Step-start count inherited from the parent, excluded from the max-step guard. */
baselineStepCount?: number;
}
5 changes: 2 additions & 3 deletions packages/common/src/base/memory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { AutoMemoryContext } from "./prompts/auto-memory";

export interface TaskMemoryState {
initialized: boolean;
lastExtractionTokens: number;
lastExtractionToolCalls: number;
/**
* UUID of the last message incorporated into memory.md by the most recent
* successful extraction. Compaction uses this as the boundary to know
Expand All @@ -17,6 +14,8 @@ export interface TaskMemoryState {
* fork agent writes memory.md successfully.
*/
pendingExtractionMessageId?: string;
extractionAttemptsSinceCompact: number;
extractedSinceCompact?: boolean;
isExtracting: boolean;
extractionCount: number;
activeTaskId?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("createForkAgent", () => {
parentMessages,
parentCwd: "/repo",
directive: "extract memory",
maxSteps: 3,
}).initMessages;

expect(result).toHaveLength(3);
Expand All @@ -50,6 +51,7 @@ describe("createForkAgent", () => {
parentCwd: "/repo",
directive: "extract memory",
tools: ["readFile(/memory/**)", "writeToFile(/memory/**)"],
maxSteps: 3,
});

expect(agent).toMatchObject({
Expand All @@ -62,6 +64,7 @@ describe("createForkAgent", () => {
"writeToFile(/memory/**)",
"attemptCompletion",
],
maxSteps: 3,
baselineStepCount: 0,
});
expect(agent).not.toHaveProperty("taskId");
Expand Down Expand Up @@ -97,6 +100,7 @@ describe("createForkAgent", () => {
parentMessages,
parentCwd: "/repo",
directive: "extract memory",
maxSteps: 3,
});

expect(agent.baselineStepCount).toBe(3);
Expand Down
4 changes: 4 additions & 0 deletions packages/livekit/src/background-task/fork-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ForkAgentInput<TMessage extends UIMessage> = {
parentCwd: string | undefined;
directive: string;
tools?: readonly ToolSpecInput[];
maxSteps: number;
};

export type ForkAgent<TMessage extends UIMessage> = {
Expand All @@ -31,6 +32,7 @@ export type ForkAgent<TMessage extends UIMessage> = {
initTitle: string | undefined;
parentTaskId: string | undefined;
tools: readonly ToolSpecInput[] | undefined;
maxSteps: number;
baselineStepCount: number;
};

Expand Down Expand Up @@ -94,6 +96,7 @@ export function createForkAgent<TMessage extends UIMessage>(
parentMessages: input.parentMessages.length,
initMessages: initMessages.length,
tools: input.tools?.length,
maxSteps: input.maxSteps,
baselineStepCount,
},
"Creating fork agent",
Expand All @@ -106,6 +109,7 @@ export function createForkAgent<TMessage extends UIMessage>(
initTitle: input.initTitle,
parentTaskId: input.parentTaskId,
tools,
maxSteps: input.maxSteps,
baselineStepCount,
};
}
Expand Down
Loading
Loading