-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
bugThis issue is a bug.This issue is a bug.investigatingThis issue is being investigated and/or work is in progress to resolve the issue.This issue is being investigated and/or work is in progress to resolve the issue.p2This is a standard priority issueThis is a standard priority issue
Description
Describe the bug
I randomly get this Exception while streaming responses with the BedrockAgentRuntimeClient. This is doesn't happen consistently, maybe once every 10 times.
Aws\Api\Parser\Exception\ParserException Message checksum mismatch. at vendor/aws/aws-sdk-php/src/Api/Parser/NonSeekableStreamDecodingEventStreamIterator.php:55
Sample code to reproduce the issue
<?php
namespace App\Console\Commands;
use Aws\BedrockAgentRuntime\BedrockAgentRuntimeClient;
use Aws\Result;
use Illuminate\Console\Command;
class Chat extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'chat';
/**
* The console command description.
*
* @var string
*/
protected $description = '';
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
* @throws \Throwable
*/
public function handle()
{
$client = new BedrockAgentRuntimeClient(
[
'version' => config('services.bedrock.version'),
'region' => config('services.bedrock.region'),
'credentials' => [
'key' => config('services.bedrock.key'),
'secret' => config('services.bedrock.secret'),
],
'http' => [
'stream' => true,
],
]
);
$data = [
'agentId' => 'IDHERE',
'agentAliasId' => 'TSTALIASID',
'sessionId' => uniqid(),
'inputText' => 'tell me everything about tylenol',
'memoryId' => uniqid(),
'streamingConfigurations' => [
'streamFinalResponse' => true,
],
];
$result = $client->invokeAgent($data);
foreach ($this->processResult($result) as $chunk) {
echo $chunk['data']['bytes'];
}
}
public function processResult(Result $result): \Generator
{
$base_data = [
'session_id' => $result['sessionId'],
'memory_id' => $result['memoryId'],
];
// Process all events in the completion stream
foreach ($result['completion'] as $event) {
$data = $base_data;
if (isset($event['chunk'])) {
$data['data'] = $event['chunk'];
} elseif (isset($event['files'])) {
$data['files'] = $event['files']['files'];
} elseif (isset($event['returnControl'])) {
$data['return_control'] = $event['returnControl'];
} elseif (isset($event['trace'])) {
$data['trace'] = $event['trace'];
} else {
// Everything else is treated as an exception
$exceptionType = array_key_first($event);
$exceptionData = $event[$exceptionType];
throw new \Exception($exceptionType);
}
yield $data;
}
}
}
This happens for me in two different projects, using the latest SDK version.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
I should be able to consistently stream invoke agent responses.
Current Behavior
Reproduction Steps
See the included sample code, try it multiple times.
Possible Solution
No response
Additional Information/Context
No response
SDK version used
3.342.32 - tried earlier versions as well same issue
Environment details (Version of PHP (php -v
)? OS name and version, etc.)
Happens with both php 8.3 and 8.4
glennschmidt
Metadata
Metadata
Assignees
Labels
bugThis issue is a bug.This issue is a bug.investigatingThis issue is being investigated and/or work is in progress to resolve the issue.This issue is being investigated and/or work is in progress to resolve the issue.p2This is a standard priority issueThis is a standard priority issue