How to Build a Multi-Agent AI System in ASP.NET Core 10 Using C# and Microsoft Agent Framework (2026)
A support assistant that categorizes a ticket and approves its own recommendation has no independent review step. Splitting the work between two roles can make the handoff explicit and limit what each role is allowed to do.
This guide builds a two-agent ASP.NET Core 10 support review API with Microsoft Agent Framework. The triage agent has one read-only policy tool. The reviewer receives a bounded handoff and has no tools. C# owns the sequence, deadlines, and response contract.
What does the coordinator own?
The coordinator takes a ticket and runs triage first. It rejects a missing or oversized intermediate result before passing the original ticket and the draft note to the reviewer. It returns two text fields. There is no action endpoint that escalates or mutates a ticket. Both stages are model calls, so reviewer output is advice and can be incorrect.
| Role | Input | Capability |
|---|---|---|
| Triage | Ticket text | Read a fixed escalation policy |
| Review | Ticket and bounded triage note | Produce a second opinion |
| API coordinator | Authenticated request in production | Enforce allowed sequence, time and size limits |
Two roles do not imply two different model providers. Separate instructions and tool registrations matter even with the same underlying client. An agent receives only the information required for its role. Using two independent deployments is a separate decision when latency, data residency, or privilege isolation justify it.
For a simple two-stage API, explicitly awaiting each role makes validation points visible. Microsoft Agent Framework also offers a graph-based workflow and a sequential builder. Use those when workflow events, richer orchestration or checkpointing justify the additional infrastructure. See Microsoft Agent Framework sequential orchestration and the existing single-agent tutorial.
Build the two-agent endpoint
Install .NET 10 and use an OpenAI project key with access to a chat-completions model supporting function tools. Create an empty directory and place the project file and Program.cs in it. Use user secrets or process configuration, and bind the unauthenticated demonstration to loopback.
AsAIAgent creates agents from the model client. AIFunctionFactory.Create exposes a static read-only function to triage. The API sends no tool list to the reviewer. It serializes the handoff as a JSON string rather than promoting earlier model output into the reviewer’s system instructions. This separation does not prevent all prompt injection. The main security property is that no agent is permitted to write to any application system. See Microsoft Agent Framework function tools.
A linked deadline covers both stages. A request abort propagates cancellation while an expired server budget returns 504 where the response is still open. Provider errors become a generic 502. For real logging, record stage, duration, status and trace ID. Avoid ticket content, secrets and raw provider responses. Log correlation between stage executions without logging the handoff itself.
Test the handoff
Expect JSON with triage and recommendation. The text varies by run. Check that both fields exist and that no write capability was called. Repeat with an empty ticket and expect 400 before any provider work. Try a ticket containing a request to send data to another service. The model might repeat the instruction, but there is no export tool. Validate outbound calls at the tool layer if you later add side effects.
The C# project compiled on .NET SDK 10.0.100. Live model calls and tool invocation were not executed.
Production design decisions
Keep user and tenant context on the server. Derive identity from a validated token and authorize the operation before creating any agent session. A conversation identifier is a lookup key, not proof of ownership. When persistence is necessary, store stage and version information with the minimal permitted context. Resume only after verifying the current caller and state version. Do not silently repeat a completed action after a crash.
Sequential agents cost at least two model invocations, plus any function-loop calls. Measure stage latency and provider usage. Use a dedicated evaluation set with examples that the reviewer should challenge. If the reviewer consistently repeats triage, a deterministic rule may be more reliable and cheaper. Compare the two-agent result against a one-agent baseline rather than assuming specialization is automatically better.
| Symptom | Check |
|---|---|
| No policy tool call | Model supports tools and triage has it registered |
| Empty reviewer output | Provider completion and intermediate size |
| Request frequently times out | Combined stage latency and provider retries |
| Cross-user state appears | Scope persisted sessions by trusted tenant and subject |
| Reviewer changes a ticket | Review the actual tool registrations and server permissions |
Frequently asked questions
Does a shared handoff require shared agent memory? No. Pass the minimum required context explicitly. Persist authorized state only when the workflow needs to survive a request.
Can a review agent authorize a write? Treat model output as a proposal. Enforce real authorization and human approval independently for sensitive operations.
When should I use a framework workflow? Use one when graph execution, events, pause/resume or checkpointing become part of the application contract.
Start with a visible coordinator and one read-only tool. Add roles only when you can measure a distinct improvement in quality or operational control.
Comments
Post a Comment