Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnetv3: please add BedrockAgentRuntime sample #7104

Open
1 of 15 tasks
hamano-yu opened this issue Nov 25, 2024 · 0 comments
Open
1 of 15 tasks

dotnetv3: please add BedrockAgentRuntime sample #7104

hamano-yu opened this issue Nov 25, 2024 · 0 comments
Assignees

Comments

@hamano-yu
Copy link

hamano-yu commented 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!

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

@hamano-yu hamano-yu changed the title [Enhancement]: <dotnetv3: please add BedrockAgentRuntime sample> dotnetv3: please add BedrockAgentRuntime sample Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants