Principle:Microsoft Agent framework Agent Specialization
| Property | Value |
|---|---|
| Principle Name | Agent Specialization |
| SDK | Microsoft Agent Framework |
| Repository | Microsoft Agent Framework |
| Source Reference | python/packages/core/agent_framework/_clients.py:L438-517
|
| Import | Access via any chat client instance (e.g., from agent_framework.openai import OpenAIChatClient)
|
Overview
The Agent Specialization principle describes a factory pattern that creates specialized, named agents directly from a configured chat client with role-specific instructions. By invoking a single convenience method on a chat client, developers can produce multiple purpose-built agents that each carry their own name, system prompt, and tool set while sharing the same underlying LLM connection.
Description
Agent Specialization uses the client.as_agent() convenience method to create multiple agents from the same client, each with distinct names, instructions, and tool sets. This is the primary mechanism for creating participants in multi-agent orchestration scenarios (sequential, concurrent, group chat). Each specialized agent operates against the same LLM but with different system prompts defining their expertise domain.
The pattern eliminates the need to instantiate separate client objects when the only difference between agents is their behavioral configuration. A single client, once configured with credentials and model settings, serves as a factory for an arbitrary number of agents. Each agent produced by as_agent() is a fully independent Agent instance that can:
- Participate in multi-agent conversations with a unique name for attribution.
- Follow a role-specific instructions prompt that constrains its behavior to a particular expertise domain.
- Access a curated set of tools appropriate to its specialization.
- Maintain its own chat message store for conversation history isolation.
- Apply agent-specific middleware and context providers.
This approach naturally supports multi-perspective analysis. For example, a single client can produce a "writer" agent, a "reviewer" agent, and an "editor" agent, each with tailored prompts, which then collaborate through an orchestration pattern such as sequential handoff or group chat.
Theoretical Basis
The Agent Specialization principle is grounded in the Factory Method design pattern. The chat client acts as the factory, and client.as_agent(name="writer", instructions="...") is the factory method that produces an Agent instance. The caller does not need to know the internal construction details of the agent; it simply provides the specialization parameters and receives a ready-to-use instance.
Key theoretical aspects:
- Factory Method Pattern: The
as_agent()method encapsulates agent construction logic, allowing the client to produce agents without exposing the underlying wiring between client, options, middleware, and message stores. - Separation of Concerns: Infrastructure configuration (credentials, model endpoint, API version) is decoupled from behavioral configuration (name, instructions, tools). The client owns the former; each agent specialization owns the latter.
- Multi-Perspective Analysis: Multiple agents created from the same client enable diverse viewpoints on a shared problem. Each agent's instructions define a unique analytical lens, and orchestration patterns compose these perspectives into a coherent workflow.
Usage
API Signature
client.as_agent(
name="agent_name",
instructions="Role-specific system prompt.",
tools=[tool_a, tool_b],
)
Basic Example
from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
client = AzureOpenAIResponsesClient(credential=AzureCliCredential())
# Create specialized agents from the same client
writer = client.as_agent(
name="writer",
instructions="You are a creative writer. Write engaging content.",
)
reviewer = client.as_agent(
name="reviewer",
instructions="You are a code reviewer. Provide constructive feedback.",
)
Multi-Agent Orchestration Example
from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
client = AzureOpenAIResponsesClient(credential=AzureCliCredential())
analyst = client.as_agent(
name="analyst",
instructions="You analyze data and identify trends.",
)
strategist = client.as_agent(
name="strategist",
instructions="You develop business strategies based on analytical findings.",
)
critic = client.as_agent(
name="critic",
instructions="You challenge assumptions and identify risks in proposed strategies.",
)
# These agents can participate in sequential, concurrent, or group chat orchestration