Skip to content

Commit be52e8a

Browse files
Marco van AngerenMarco van Angeren
authored andcommitted
Fixed metadata overwriting bug in StreamResult
1 parent e7947c7 commit be52e8a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/agent/src/Toolbox/StreamResult.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ public function getContent(): \Generator
3333
if ($value instanceof ToolCallResult) {
3434
$innerResult = ($this->handleToolCallsCallback)($value, Message::ofAssistant($streamedResult));
3535

36-
$this->getMetadata()->set($innerResult->getMetadata()->all());
37-
36+
// Propagate metadata from inner result to this result
37+
foreach ($innerResult->getMetadata()->all() as $key => $metadataValue) {
38+
$this->getMetadata()->add($key, $metadataValue);
39+
}
40+
3841
$content = $innerResult->getContent();
3942
// Strings are iterable in PHP but yield from would iterate character-by-character.
4043
// We need to yield the complete string as a single value to preserve streaming behavior.

0 commit comments

Comments
 (0)