AgentsDefine an AI Agent in C# and ASP.NET Core
AGENTS

Define an AI Agent in C# and ASP.NET Core

Create a .NET AI agent in C#, configure its model and instructions, and register it with ASP.NET Core dependency injection using Runiq.Net.

This guide creates the support-agent used throughout the Agents documentation. You need a .NET 10 ASP.NET Core application and a configured model provider.

Install the package

Run this in the project that defines and executes agents:

.NET CLI
dotnet add package Runiq.AI.Agents

The Agents package references Core and includes the agent runtime. For a new solution, you can also follow Get Started.

Register the agent

Add the definition before building the host:

Program.cs
using Runiq.AI.Agents;
using Runiq.AI.Core;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRuniqServer(options =>
{
    options.AddAgent(new Agent(
        id: "support-agent",
        name: "Support Agent",
        instructions: """
            Help users understand the application.
            Ask for missing details before giving specific guidance.
            Keep answers concise and state uncertainty clearly.
            """,
        model: "openai/gpt-5",
        apiKey: builder.Configuration["OpenAI:ApiKey"]));
});

var app = builder.Build();

app.Run();

The runtime can now resolve support-agent. Registration alone does not send a request to the model. Configure your key using Model and provider, then follow Running agents to add an endpoint.

Choose identity and instructions

FieldWhat to choose
idA unique, stable identifier such as support-agent. Calls and links may depend on it.
nameA readable label such as Support Agent.
instructionsThe agent's responsibility, boundaries, and answer style.
modelA supported provider name followed by the model identifier.
apiKeyRead from configuration when the provider requires a key.

Keep the id stable after callers depend on it. See Instructions for guidance you can test.

Add capabilities deliberately

Tools let the agent request application operations. Define a typed tool, then attach it with AddTool<TTool>(). Follow Defining tools for the contract and registration.

RAG supplies relevant document passages. After configuring and ingesting a named index, connect it to an existing agent definition:

Snippet
agent.UseRag(rag =>
{
    rag.IndexName = "product-docs";
});

This does not create or ingest the index. The default policy allows normal answers when no context is accepted. Choose the grounding and no-context policy explicitly for source-dependent answers in Defining indexes.

Keep the first definition small

Start with one responsibility and verify a response before attaching more capabilities. Move definitions into separate files when they grow; Patterns shows how.

Next: Configure the model connection →

On this page