Skip to content

Commit a308acc

Browse files
committed
fix chat history management
1 parent 13b0ad6 commit a308acc

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Agent/Nodes/StreamingNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ public function __invoke(AIInferenceEvent $event, AgentState $state): Generator|
5656

5757
$this->emit('inference-stop', new InferenceStop($lastMessage, $message));
5858

59-
// Add the message to the chat history
60-
$this->addToChatHistory($state, $message);
61-
6259
// Route based on the message type
6360
if ($message instanceof ToolCallMessage) {
6461
return new ToolCallEvent($message, $event);
6562
}
6663

64+
// Add the final message to the chat history (after tool loop)
65+
$this->addToChatHistory($state, $message);
66+
6767
return new StopEvent();
6868

6969
} catch (Throwable $exception) {

src/Agent/Nodes/StructuredOutputNode.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ public function __invoke(AIInferenceEvent $event, AgentState $state): ToolCallEv
102102

103103
$this->emit('inference-stop', new InferenceStop($last, $response));
104104

105-
$this->addToChatHistory($state, $response);
106-
107105
// If the response is a tool call, route to tool execution
108106
if ($response instanceof ToolCallMessage) {
109107
return new ToolCallEvent($response, $event);
110108
}
111109

110+
// Add the final message to the chat history (after tool loop)
111+
$this->addToChatHistory($state, $response);
112+
112113
// Process the response: extract, deserialize, and validate
113114
$output = $this->processResponse($response, $schema, $this->outputClass);
114115

0 commit comments

Comments
 (0)