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
Hello,
Could you provide sample code for .NET's Amazon.BedrockAgentRuntime?
I have created an AWS Bedrock Agent on the AWS Console and confirmed its operation.
Afterward, I am trying to retrieve the results of the AWS Bedrock Agent using C# (with the intention of ultimately running it on Unity).
Below is the source code I wrote. I would greatly appreciate your assistance. Thank you in advance!
using System;
using System.Collections.Generic;
using System.Linq;
using Amazon;
using Amazon.BedrockAgentRuntime;
using Amazon.BedrockAgentRuntime.Model;
using Amazon.BedrockRuntime.Model;
// Create a Bedrock Runtime client in the AWS Region you want to use.
var client = new AmazonBedrockAgentRuntimeClient(RegionEndpoint.APNortheast1);
string agentId = <agentid>;
string agentAliasId = <agentaliasid>;
string sessionId = <sessionid>;
string prompt = "hello agent.";
// Create a request with the model ID, the user message, and an inference configuration.
// Prepare the request
var request = new InvokeAgentRequest
{
AgentId = agentId,
AgentAliasId = agentAliasId,
SessionId = sessionId,
InputText = prompt
};
try
{
// Send the request to the Bedrock Runtime and wait for the result.
var response = await client.InvokeAgentAsync(request);
// Extract and print the streamed response text in real-time.
foreach (var chunk in response.Completion.AsEnumerable())
{
Console.Write(chunk);
}
}
catch (BedrockAgentRuntimeEventStreamException e)
{
Console.WriteLine($"ERROR: Can't invoke '{agentId}'. Reason: {e.Message}");
}
What does this example accomplish?
I want to retrieve the results of AWS Bedrock Agent using .NET.
Which AWS service(s)?
Amazon Bedrock
Which AWS SDKs or tools?
All languages
.NET
C++
Go (v2)
Java
Java (v2)
JavaScript
JavaScript (v3)
Kotlin
PHP
Python
Ruby
Rust
Swift
Not applicable
Are there existing code examples to leverage?
No response
Do you have any reference code?
No response
The text was updated successfully, but these errors were encountered:
hamano-yu
changed the title
[Enhancement]: <dotnetv3: please add BedrockAgentRuntime sample>
dotnetv3: please add BedrockAgentRuntime sample
Nov 25, 2024
Background story
Hello,
Could you provide sample code for .NET's Amazon.BedrockAgentRuntime?
I have created an AWS Bedrock Agent on the AWS Console and confirmed its operation.
Afterward, I am trying to retrieve the results of the AWS Bedrock Agent using C# (with the intention of ultimately running it on Unity).
I referred to this code (https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/dotnetv3/Bedrock-runtime/Models/AnthropicClaude/ConverseStream/ConverseStream.cs) and wrote my source code, but I am unable to display the response results on the console.
Below is the source code I wrote. I would greatly appreciate your assistance. Thank you in advance!
What does this example accomplish?
I want to retrieve the results of AWS Bedrock Agent using .NET.
Which AWS service(s)?
Amazon Bedrock
Which AWS SDKs or tools?
Are there existing code examples to leverage?
No response
Do you have any reference code?
No response
The text was updated successfully, but these errors were encountered: