Skip to content
Merged
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
23 changes: 23 additions & 0 deletions packages/core/src/context/agentHistoryProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ describe('AgentHistoryProvider', () => {
);
});

it('should use unambiguous label in fallback summary to avoid LLM confusion', async () => {
providerConfig.maxTokens = 60000;
providerConfig.retainedTokens = 60000;
vi.spyOn(config, 'getContextManagementConfig').mockReturnValue({
enabled: true,
} as unknown as ContextManagementConfig);
vi.mocked(estimateTokenCountSync).mockImplementation(
(parts: Part[]) => parts.length * 4000,
);
generateContentMock.mockRejectedValue(new Error('API Error'));

const history = createMockHistory(35);
const result = await provider.manageHistory(history);

expect(generateContentMock).toHaveBeenCalled();
expect(result.length).toBe(15);
// The fallback summary should use clear and unambiguous phrasing
expect(result[0].parts![0].text).toContain(
'Previous User Intent (Truncated):',
);
expect(result[0].parts![0].text).not.toContain('Last User Intent:');
});

it('should pass the contextual bridge to the summarizer', async () => {
vi.spyOn(config, 'getContextManagementConfig').mockReturnValue({
enabled: true,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/context/agentHistoryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ export class AgentHistoryProvider {
];

if (lastUserText) {
summaryParts.push(`- **Last User Intent:** "${lastUserText}"`);
summaryParts.push(
`- **Previous User Intent (Truncated):** "${lastUserText}"`,
);
}

if (actionPath) {
Expand Down
Loading