Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Agent framework BaseChatClient As Agent

From Leeroopedia
Property Value
Implementation Name BaseChatClient As Agent
SDK Microsoft Agent Framework
Repository Microsoft Agent Framework
Source File python/packages/core/agent_framework/_clients.py
Line Range L438-517
Import Access via any chat client instance (e.g., from agent_framework.openai import OpenAIChatClient)
Type Factory method on BaseChatClient

Overview

The BaseChatClient.as_agent() method is a convenience factory that creates a fully configured Agent instance from an existing chat client. Rather than constructing an agent from scratch, callers invoke as_agent() on any chat client instance, passing specialization parameters such as name, instructions, and tools. The method wires the agent to the client's LLM connection, producing an agent ready for independent use or participation in multi-agent orchestration.

Code Reference

Source Location

Property Value
File python/packages/core/agent_framework/_clients.py
Method as_agent()
Defined On BaseChatClient
Lines 438-517

Signature

def as_agent(
    self,
    *,
    id: str | None = None,
    name: str | None = None,
    description: str | None = None,
    instructions: str = "",
    tools: FunctionTool | Callable | Sequence[FunctionTool | Callable] | None = None,
    default_options: OptionsCoT | None = None,
    chat_message_store_factory: ChatMessageStoreFactory | None = None,
    context_provider: ContextProvider | None = None,
    middleware: Sequence[...] | None = None,
    function_invocation_configuration: FunctionInvocationConfiguration | None = None,
    **kwargs: Any,
) -> Agent[OptionsCoT]:

Import Statement

from agent_framework.openai import OpenAIChatClient
# or
from agent_framework.azure import AzureOpenAIResponsesClient

I/O Contract

Inputs

Parameter Type Default Description
id None None Optional unique identifier for the agent.
name None None The name of the agent, used for attribution in multi-agent conversations.
description None None An optional human-readable description of the agent's purpose.
instructions str "" Role-specific system prompt that defines the agent's expertise domain and behavioral constraints.
tools Callable | Sequence[FunctionTool | Callable] | None None Tools the agent can invoke. Accepts a single tool, a callable, or a sequence of tools/callables.
default_options None None Default chat completion options (e.g., temperature, max tokens) for this agent.
chat_message_store_factory None None Factory for creating the agent's conversation history store, enabling history isolation per agent.
context_provider None None Provider for injecting additional context into the agent's requests.
middleware None None Middleware pipeline applied to the agent's request/response cycle.
function_invocation_configuration None None Configuration controlling how the agent invokes function tools.
**kwargs Any Additional keyword arguments forwarded to the Agent constructor.

Output

Type Description
Agent[OptionsCoT] A fully configured Agent instance that uses this chat client as its LLM backend. The agent is ready for independent invocation or participation in multi-agent orchestration patterns.

Usage Examples

Creating Specialized Agents

from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential

client = AzureOpenAIResponsesClient(credential=AzureCliCredential())

# Create specialized agents
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.",
)

# Each agent can be used independently
response = await writer.run("Write a poem about AI")

Agent with Tools

from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential

client = AzureOpenAIResponsesClient(credential=AzureCliCredential())

researcher = client.as_agent(
    name="researcher",
    instructions="You are a research assistant. Use the provided tools to find information.",
    tools=[web_search, document_lookup],
)

Related Pages

Sources

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment