Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (66 loc) · 2.45 KB
/
Copy pathProgram.cs
File metadata and controls
78 lines (66 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.ClientModel;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenAI;
using RockBot.A2A;
using RockBot.Host;
using RockBot.Messaging.RabbitMQ;
using RockBot.SampleAgent;
var builder = Host.CreateApplicationBuilder(args);
builder.Configuration.AddUserSecrets<Program>();
builder.Services.AddRockBotRabbitMq(opts => builder.Configuration.GetSection("RabbitMq").Bind(opts));
// Configure the LLM chat client (same pattern as RockBot.Agent)
var llmConfig = builder.Configuration.GetSection("LLM");
var endpoint = llmConfig["Endpoint"];
var apiKey = llmConfig["ApiKey"];
var modelId = llmConfig["ModelId"];
if (!string.IsNullOrEmpty(endpoint) && !string.IsNullOrEmpty(apiKey) && !string.IsNullOrEmpty(modelId))
{
var openAiClient = new OpenAIClient(
new ApiKeyCredential(apiKey),
new OpenAIClientOptions { Endpoint = new Uri(endpoint) });
builder.Services.AddRockBotChatClient(
openAiClient.GetChatClient(modelId).AsIChatClient());
}
else
{
builder.Services.AddRockBotChatClient(new EchoChatClient());
Console.WriteLine("No LLM config found — using EchoChatClient.");
Console.WriteLine("Set LLM:Endpoint, LLM:ApiKey, and LLM:ModelId to configure.");
}
builder.Services.AddRockBotHost(agent =>
{
agent.WithIdentity("SampleAgent");
agent.AddA2A(opts =>
{
opts.Card = new AgentCard
{
AgentName = "SampleAgent",
Description = "A sample agent demonstrating the A2A protocol pattern.",
Version = "1.0",
Skills =
[
new AgentSkill
{
Id = "general",
Name = "General Task",
Description = "General-purpose task execution using an LLM."
},
new AgentSkill
{
Id = "echo",
Name = "Echo",
Description = "Echoes the input message back as confirmation."
}
]
};
});
agent.Services.AddScoped<IAgentTaskHandler, SampleAgentTaskHandler>();
});
var app = builder.Build();
var startupLogger = app.Services.GetRequiredService<ILoggerFactory>().CreateLogger("Startup");
startupLogger.LogInformation("SampleAgent starting — listening for A2A task requests");
await app.RunAsync();