MCPcopy
hub / github.com/rohitg00/agentmemory / compressWithRetry

Function compressWithRetry

src/eval/self-correct.ts:7–28  ·  view source on GitHub ↗
(
  provider: MemoryProvider,
  systemPrompt: string,
  userPrompt: string,
  validator: (response: string) => { valid: boolean; errors?: string[] },
  maxRetries = 1,
)

Source from the content-addressed store, hash-verified

5IMPORTANT: Your previous response was invalid. Please ensure your output strictly follows the required XML format. Every required field must be present with valid values.`;
6
7export async function compressWithRetry(
8 provider: MemoryProvider,
9 systemPrompt: string,
10 userPrompt: string,
11 validator: (response: string) => { valid: boolean; errors?: string[] },
12 maxRetries = 1,
13): Promise<{ response: string; retried: boolean }> {
14 const first = await provider.compress(systemPrompt, userPrompt);
15 const result = validator(first);
16 if (result.valid) return { response: first, retried: false };
17
18 for (let i = 0; i < maxRetries; i++) {
19 const retry = await provider.compress(
20 systemPrompt + STRICTER_SUFFIX,
21 userPrompt,
22 );
23 const retryResult = validator(retry);
24 if (retryResult.valid) return { response: retry, retried: true };
25 }
26
27 return { response: first, retried: true };
28}

Callers 1

registerCompressFunctionFunction · 0.85

Calls 2

validatorFunction · 0.85
compressMethod · 0.65

Tested by

no test coverage detected