You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/Unit/Agents/AgentTest.php
+19-3Lines changed: 19 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,10 @@
9
9
useCortex\Agents\Data\Step;
10
10
useCortex\Events\AgentStart;
11
11
useCortex\JsonSchema\Schema;
12
+
useCortex\Events\AgentStepEnd;
12
13
useCortex\LLM\Data\ChatResult;
13
14
useCortex\LLM\Enums\ChunkType;
15
+
useCortex\Events\AgentStepStart;
14
16
useCortex\LLM\Data\ChatStreamResult;
15
17
useCortex\LLM\Data\ToolCallCollection;
16
18
useCortex\LLM\Data\ChatGenerationChunk;
@@ -637,9 +639,9 @@ function (int $x, int $y): int {
637
639
->and($endCalled)->toBe(1, 'AgentEnd should be dispatched exactly once');
638
640
});
639
641
640
-
test('it dispatches AgentStartand AgentEnd events only once when streaming with tool calls and multiple steps', function (): void {
642
+
test('it dispatches AgentStart, AgentEnd, AgentStepStart, and AgentStepEnd events only once when streaming with tool calls and multiple steps', function (): void {
641
643
// This test verifies that even with multiple steps (tool call + final response),
642
-
// AgentStartand AgentEnd are only dispatched once
644
+
// AgentStart, AgentEnd, AgentStepStart, and AgentStepEnd are only dispatched exactly once.
643
645
$multiplyTool = tool(
644
646
'multiply',
645
647
'Multiply two numbers together',
@@ -666,6 +668,8 @@ function (int $x, int $y): int {
666
668
667
669
$startCalled = 0;
668
670
$endCalled = 0;
671
+
$stepStartCalled = 0;
672
+
$stepEndCalled = 0;
669
673
670
674
$agent->onStart(function (AgentStart$event) use ($agent, &$startCalled): void {
671
675
$startCalled++;
@@ -677,6 +681,16 @@ function (int $x, int $y): int {
677
681
expect($event->agent)->toBe($agent);
678
682
});
679
683
684
+
$agent->onStepStart(function (AgentStepStart$event) use ($agent, &$stepStartCalled): void {
685
+
$stepStartCalled++;
686
+
expect($event->agent)->toBe($agent);
687
+
});
688
+
689
+
$agent->onStepEnd(function (AgentStepEnd$event) use ($agent, &$stepEndCalled): void {
690
+
$stepEndCalled++;
691
+
expect($event->agent)->toBe($agent);
692
+
});
693
+
680
694
$result = $agent->stream(input: [
681
695
'query' => 'What is 3 times 4?',
682
696
]);
@@ -695,7 +709,9 @@ function (int $x, int $y): int {
695
709
// Verify final counts after stream is fully consumed
696
710
expect($chunkCount)->toBeGreaterThan(0, 'Should have consumed some chunks')
697
711
->and($startCalled)->toBe(1, 'AgentStart should be dispatched exactly once even with multiple steps')
698
-
->and($endCalled)->toBe(1, 'AgentEnd should be dispatched exactly once even with multiple steps');
712
+
->and($endCalled)->toBe(1, 'AgentEnd should be dispatched exactly once even with multiple steps')
713
+
->and($stepStartCalled)->toBe(2, 'AgentStepStart should be dispatched exactly twice even with multiple steps')
714
+
->and($stepEndCalled)->toBe(2, 'AgentStepEnd should be dispatched exactly twice even with multiple steps');
0 commit comments