BedrockAgentCore client

This page contains examples with the BedrockAgentCore client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.

The BedrockAgentCore package could be installed with Composer.

composer require async-aws/bedrock-agent-core

A new client object may be instantiated by:

use AsyncAws\BedrockAgentCore\BedrockAgentCoreClient; $bedrockAgentCore = new BedrockAgentCoreClient();

The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:

use AsyncAws\BedrockAgentCore\BedrockAgentCoreClient; $bedrockAgentCore = new BedrockAgentCoreClient([ 'accessKeyId' => 'my_access_key', 'accessKeySecret' => 'my_access_secret', 'region' => 'eu-central-1', ]);

For all available options, see the configuration reference.

Usage

Invoke an agent runtime

use AsyncAws\BedrockAgentCore\BedrockAgentCoreClient; use AsyncAws\BedrockAgentCore\Input\InvokeAgentRuntimeRequest; $bedrockAgentCore = new BedrockAgentCoreClient(); $request = new InvokeAgentRuntimeRequest([ 'agentRuntimeArn' => 'arn:aws:bedrock-agentcore:eu-west-1:965624758642:runtime/my-agent', 'qualifier' => 'DEFAULT', 'contentType' => 'application/json', 'accept' => 'application/json', 'payload' => json_encode(['prompt' => 'Write me a love poem.']), ]); $result = $bedrockAgentCore->invokeAgentRuntime($request); echo $result->getResponse() . PHP_EOL;

Pass a runtimeSessionId to keep several invocations in the same conversation:

use AsyncAws\BedrockAgentCore\BedrockAgentCoreClient; use AsyncAws\BedrockAgentCore\Input\InvokeAgentRuntimeRequest; $bedrockAgentCore = new BedrockAgentCoreClient(); $sessionId = 'ba8dc2f0-3b3f-4f4a-9a1e-9c0d3f2b7a11'; $result = $bedrockAgentCore->invokeAgentRuntime(new InvokeAgentRuntimeRequest([ 'agentRuntimeArn' => 'arn:aws:bedrock-agentcore:eu-west-1:965624758642:runtime/my-agent', 'runtimeSessionId' => $sessionId, 'payload' => json_encode(['prompt' => 'And now a haiku.']), ])); echo $result->getRuntimeSessionId() . PHP_EOL; echo $result->getResponse() . PHP_EOL;

See InvokeAgentRuntime for more information.


The source code to this page is found on GitHub.