You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Create_Anthropic_Agent.cs 1.0 kB

12345678910111213141516171819202122232425262728
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Create_Anthropic_Agent.cs
  3. using AutoGen.Anthropic.Extensions;
  4. using AutoGen.Anthropic.Utils;
  5. using AutoGen.Core;
  6. namespace AutoGen.Anthropic.Sample;
  7. public static class Create_Anthropic_Agent
  8. {
  9. public static async Task RunAsync()
  10. {
  11. #region create_anthropic_agent
  12. var apiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY") ?? throw new Exception("Missing ANTHROPIC_API_KEY environment variable.");
  13. var anthropicClient = new AnthropicClient(new HttpClient(), AnthropicConstants.Endpoint, apiKey);
  14. var agent = new AnthropicClientAgent(anthropicClient, "assistant", AnthropicConstants.Claude3Haiku);
  15. #endregion
  16. #region register_middleware
  17. var agentWithConnector = agent
  18. .RegisterMessageConnector()
  19. .RegisterPrintMessage();
  20. #endregion register_middleware
  21. await agentWithConnector.SendAsync(new TextMessage(Role.Assistant, "Hello", from: "user"));
  22. }
  23. }