Skip to content
Open
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 @@ -392,7 +392,8 @@ void testBuilderGetters() {

@Test
void testExtendedAdvisorWithCustomHooks() {
int[] hookCallCounts = { 0, 0, 0 }; // initializeLoop, beforeCall, afterCall
int[] hookCallCounts = { 0, 0, 0, 0 }; // initializeLoop, beforeCall, afterCall,
// doFinalizeLoop

// Create extended advisor to verify hooks are called
TestableToolCallAdvisor advisor = new TestableToolCallAdvisor(this.toolCallingManager,
Expand All @@ -413,11 +414,13 @@ void testExtendedAdvisorWithCustomHooks() {
assertThat(hookCallCounts[0]).isEqualTo(1); // doInitializeLoop called once
assertThat(hookCallCounts[1]).isEqualTo(1); // doBeforeCall called once
assertThat(hookCallCounts[2]).isEqualTo(1); // doAfterCall called once
assertThat(hookCallCounts[3]).isEqualTo(1); // doFinalizeLoop called once
}

@Test
void testExtendedAdvisorHooksCalledMultipleTimesWithToolCalls() {
int[] hookCallCounts = { 0, 0, 0 }; // initializeLoop, beforeCall, afterCall
int[] hookCallCounts = { 0, 0, 0, 0 }; // initializeLoop, beforeCall, afterCall,
// doFinalizeLoop

TestableToolCallAdvisor advisor = new TestableToolCallAdvisor(this.toolCallingManager,
BaseAdvisor.HIGHEST_PRECEDENCE + 300, hookCallCounts);
Expand Down Expand Up @@ -454,6 +457,8 @@ void testExtendedAdvisorHooksCalledMultipleTimesWithToolCalls() {
// iteration)
assertThat(hookCallCounts[2]).isEqualTo(2); // doAfterCall called twice (each
// iteration)
assertThat(hookCallCounts[3]).isEqualTo(1); // doFinalizeLoop called once
// (after loop)
}

@Test
Expand Down Expand Up @@ -606,6 +611,15 @@ protected ChatClientResponse doAfterCall(ChatClientResponse chatClientResponse,
return super.doAfterCall(chatClientResponse, callAdvisorChain);
}

@Override
protected ChatClientResponse doFinalizeLoop(ChatClientResponse chatClientResponse,
CallAdvisorChain callAdvisorChain) {
if (this.hookCallCounts != null) {
this.hookCallCounts[3]++;
}
return super.doFinalizeLoop(chatClientResponse, callAdvisorChain);
}

static TestableBuilder testBuilder() {
return new TestableBuilder();
}
Expand Down