Agent Framework: Basic Setup
The smallest possible Microsoft Agent Framework setup: one shared AIAgent, one RunAsync call.
Table of Contents
What is AIAgent?
Registering the Agent
Calling the Agent
Try It
What is AIAgent?
AIAgent is a model-agnostic facade over a chat-completion backend. You hand it a list of
ChatMessage objects (system/user/assistant turns) and it hands back a response - either
all at once via RunAsync, or incrementally via RunStreamingAsync. It doesn't
care whether the model behind it is served through Azure AI Foundry, plain Azure OpenAI, or something
else entirely - that's decided once, at registration time.
See the Foundry Integration example for how this site's agent is actually backed.
Registering the Shared Agent
This site registers AIAgent once, as a singleton, in
Services/AIServiceCollectionExtensions.cs:
Loading Monaco Editor...
Calling the Agent
Once registered, any component or service can inject AIAgent directly for the rawest
possible usage - no history, no streaming, just a question and an answer:
Loading Monaco Editor...
This is exactly what ArticleSummarizer does (with a couple of extra ChatOptions
for temperature and output length), and roughly what ChatService does under the hood before
it adds streaming and per-request model overrides.
Try It
This box injects AIAgent directly (not IChatService) to show the framework's
primitive shape before any app-level wrapper is layered on.
References
For more detailed information and advanced scenarios, check out these helpful resources:
Microsoft Agent Framework overview
Official docs for the AIAgent abstraction and the wider Agent Framework.Microsoft.Extensions.AI
The underlying ChatMessage / ChatOptions / IChatClient abstractions AIAgent builds on.agent-framework on GitHub
Source, samples, and issue tracker for the open-source framework.