lab / agent framework basics

Agent Framework: Basic Setup

The smallest possible Microsoft Agent Framework setup: one shared AIAgent, one RunAsync call.

Contents

Microsoft Agent Framework is 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:

An unhandled error has occurred. Reload ๐Ÿ—™

Reconnecting… Still reconnecting… Connection lost Session paused Session expired

The connection to the server dropped. This usually only takes a moment.

No answer yet. Trying again in 0s.

Couldn't reach the server. Check your connection, then try again.

This tab sat idle, so the server set the session aside. Pick up where you left off.

The server no longer has this session. Reload the page to start fresh.