Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(ai): enable querying history by session #14368

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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface CommunicationRecordingService {

getHistory(agentId: string): CommunicationHistory;

getSessionHistory(sessionId: string): CommunicationHistory;

clearHistory(): void;
readonly onStructuralChange: Event<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,29 @@ describe('DefaultCommunicationRecordingService', () => {
expect(history2[0].response).to.eq('dummy response');
});

it('returns session history', () => {
const service = new DefaultCommunicationRecordingService();
(service as unknown as { logger: ILogger }).logger = new MockLogger();
// some requests and responses for session 1
service.recordRequest({ agentId: 'agent', requestId: '1', sessionId: '1', timestamp: 100, request: 'session 1 request 1' });
service.recordResponse({ agentId: 'agent', requestId: '1', sessionId: '1', timestamp: 200, response: 'session 1 response 1' });
service.recordRequest({ agentId: 'agent2', requestId: '2', sessionId: '1', timestamp: 100, request: 'session 1 request 2' });
service.recordResponse({ agentId: 'agent2', requestId: '2', sessionId: '1', timestamp: 200, response: 'session 1 response 2' });
// some requests and responses for session 2
service.recordRequest({ agentId: 'agent', requestId: '3', sessionId: '2', timestamp: 100, request: 'different session request' });
service.recordResponse({ agentId: 'agent', requestId: '3', sessionId: '2', timestamp: 200, response: 'different session request' });

const history1 = service.getSessionHistory('1');
expect(history1.length).to.eq(2);
expect(history1[0].request).to.eq('session 1 request 1');
expect(history1[0].response).to.eq('session 1 response 1');
expect(history1[1].request).to.eq('session 1 request 2');
expect(history1[1].response).to.eq('session 1 response 2');

const history2 = service.getSessionHistory('2');
expect(history2.length).to.eq(1);
expect(history2[0].request).to.eq('different session request');
expect(history2[0].response).to.eq('different session request');
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export class DefaultCommunicationRecordingService implements CommunicationRecord
return this.history.get(agentId) || [];
}

getSessionHistory(sessionId: string): CommunicationHistory {
return Array.from(
this.history.values()
).reduce((acc, current) =>
acc.concat(current.filter(entry => entry.sessionId === sessionId)), []
);
}

recordRequest(requestEntry: CommunicationHistoryEntry): void {
this.logger.debug('Recording request:', requestEntry.request);
if (this.history.has(requestEntry.agentId)) {
Expand Down
Loading