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:
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:
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
| Field | What to choose |
|---|---|
id | A unique, stable identifier such as support-agent. Calls and links may depend on it. |
name | A readable label such as Support Agent. |
instructions | The agent's responsibility, boundaries, and answer style. |
model | A supported provider name followed by the model identifier. |
apiKey | Read 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:
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.