Agent Framework: Basic Setup
The smallest possible Microsoft Agent Framework setup: one shared AIAgent, one RunAsync call.
Contents
Microsoft.Agents.AI (the AIAgent abstraction)
layered on top of Microsoft.Extensions.AI (ChatMessage, ChatOptions, and friends).
This site registers exactly one shared AIAgent singleton, and every AI feature here
either calls it directly or goes through a thin wrapper around 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:
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:
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 overviewOfficial docs for the AIAgent abstraction and the wider Agent Framework.
- Microsoft.Extensions.AIThe underlying ChatMessage / ChatOptions / IChatClient abstractions AIAgent builds on.
- agent-framework on GitHubSource, samples, and issue tracker for the open-source framework.