Hello Agent
This page defines one agent, runs it, sends one message, and prints the final response.
Prerequisites
You need a supported .NET SDK and one model provider. This page uses OpenAI with OPENAI_API_KEY.
The provider reads the API key from the environment. Use environment variables or your normal secret manager for keys. Do not hard-code provider secrets in source files.
Create A Console App
dotnet new console -n HpdAgentQuickstart
cd HpdAgentQuickstart
dotnet add package HPD-Agent.Framework --version 0.9.7
dotnet add package HPD-Agent.Providers.OpenAI --version 0.9.7Set an OpenAI API key in the environment:
export OPENAI_API_KEY="..."Use environment variables or your normal secret manager for keys. Do not hard-code provider secrets in source files.
Add Program.cs
Replace Program.cs with:
using HPD.Agent;
using HPD.Agent.Providers.OpenAI;
var assistant = new AgentConfig()
.WithOpenAI(model: "gpt-5-mini")
.WithInstructions("You are a concise helpful assistant.");
await using var runtime = await new AgentRuntimeBuilder()
.AddAgent("assistant", assistant)
.BuildAsync();
var result = await runtime.RunAsync("Say hello in one sentence.");
Console.WriteLine(result.Text);Run it:
dotnet runYou Succeeded If
You should see one short assistant sentence printed in the console, similar to:
Hello! I'm ready to help you build with HPD Agent.What Happens
new AgentConfig() starts the agent's definition. An agent in HPD Agent is a definition: what model it calls, how it behaves, and which tools it can use. You do not build or hold an agent object yourself.
The With... methods fill in that definition and return the same AgentConfig, so they chain:
.WithOpenAI(model: "gpt-5-mini")configures the chat provider and model. The OpenAI provider resolves the API key fromOPENAI_API_KEY..WithInstructions(...)sets the agent's behavior guidance.
new AgentRuntimeBuilder() starts the runtime. The runtime runs agents; it holds what every agent of the application shares, such as session storage, secrets, and shared middleware. An application usually has one.
.AddAgent("assistant", assistant) registers the definition under the id assistant. The runtime keeps its own copy of the definition. A runtime with one registered agent runs that agent by default.
BuildAsync() creates the AgentRuntime. It validates every registered definition, for example that each provider the definition names is one the application references, and fails early if a definition is wrong. It builds no agent: the runtime builds the agent the first time it runs, then reuses it.
runtime.RunAsync(...) sends one user message to the default agent and waits for the turn to finish.
result.Text contains the final assistant text for the turn.
await using disposes the runtime when the program ends.
Stream The Same Run
If you want live output, subscribe to text deltas before calling RunAsync(...):
using var output = runtime.Subscribe<TextDeltaEvent>(evt => Console.Write(evt.Text));
_ = await runtime.RunAsync("Say hello in one sentence.");That is the smallest streaming path. For typed event families, timelines, tool progress, and hosted clients, continue to Streaming Events.
Local Alternative With Ollama
Use Ollama when you want a local, no-cloud first run. This is an optional provider swap: only the provider call on the AgentConfig changes, and the rest of the getting-started path uses the same definition-and-runtime shape.
ollama pull llama3.2
ollama serve
dotnet add package HPD-Agent.Framework --version 0.9.7
dotnet add package HPD-Agent.Providers.Ollama --version 0.9.7Use this Program.cs:
using HPD.Agent;
using HPD.Agent.Providers.Ollama;
var assistant = new AgentConfig()
.WithOllama(model: "llama3.2")
.WithInstructions("You are a concise helpful assistant.");
await using var runtime = await new AgentRuntimeBuilder()
.AddAgent("assistant", assistant)
.BuildAsync();
var result = await runtime.RunAsync("Say hello in one sentence.");
Console.WriteLine(result.Text);Ollama does not require an API key. The provider uses an explicit endpoint if supplied, then OLLAMA_ENDPOINT, then OLLAMA_HOST, then http://localhost:11434.
Troubleshooting
If BuildAsync() throws a ValidationException with an error that starts with agent_provider_unknown, the definition names a provider the application does not reference. Install the matching provider package, add its namespace, and call the matching method such as .WithOpenAI(...) or .WithOllama(...) on the AgentConfig. The error names the path, clients.Chat.provider.key, and suggests a close provider name when there is one. exception.Errors lists each error; exception.Message lists them all.
If the run says no chat model is configured, make sure the AgentConfig includes a provider call with a model.
If OpenAI configuration is invalid or a required OpenAI secret is missing, set OPENAI_API_KEY in the same shell where you run dotnet run.
If the Ollama run fails at runtime, confirm the server is running and the model has been pulled.
Client setup is resolved when the run needs the client, not during BuildAsync(), so a missing key or model still fails at run time. A direct runtime.RunAsync(...) call throws a typed setup exception. If the host should continue after a missing key, model, or provider configuration, catch IClientSetupFailure:
using HPD.Agent.Providers;
try
{
var result = await runtime.RunAsync("Say hello in one sentence.");
Console.WriteLine(result.Text);
}
catch (Exception exception) when (exception is IClientSetupFailure setupFailure)
{
var diagnostic = setupFailure.Diagnostic;
Console.Error.WriteLine($"[{diagnostic.Code}] {diagnostic.Message}");
if (!string.IsNullOrWhiteSpace(diagnostic.Guidance))
Console.Error.WriteLine(diagnostic.Guidance);
}Next
Next: print the same run live in Streaming Events.
Then: register one local function in Add A Tool.
Go deeper: for definitions, the runtime, default agents, and when agents are built, see The Runtime And Its Agents. For provider models and credentials, see Providers, Clients, And Secrets.