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 Agent Init

From Leeroopedia
Revision as of 11:30, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Microsoft_Agent_framework_Agent_Init.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Property Value
Implementation Name Agent Init
SDK Microsoft Agent Framework
Repository agent-framework
Source File python/packages/core/agent_framework/_agents.py
Line Range L1377-1426
Import from agent_framework import Agent
Type Class constructor (__init__)

Overview

The Agent.__init__ method is the constructor for the central Agent class in the Microsoft Agent Framework. It binds together a chat client, system instructions, and optional tools into a configured agent instance ready for execution via run(). The Agent class extends BaseAgent[OptionsCoT] and is generic over OptionsCoT, enabling type-safe propagation of model-specific options throughout the agent lifecycle.

Code Reference

Source Location

Property Value
File python/packages/core/agent_framework/_agents.py
Class Agent
Base Classes BaseAgent[OptionsCoT], Generic[OptionsCoT]
Lines 1377-1426

Signature

class Agent(BaseAgent[OptionsCoT], Generic[OptionsCoT]):
    def __init__(
        self,
        client: SupportsChatGetResponse[OptionsCoT],
        instructions: str = "",
        *,
        id: str | None = None,
        name: str | None = None,
        description: str | None = None,
        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[
            AgentMiddleware
            | AgentMiddlewareCallable
            | ChatMiddleware
            | ChatMiddlewareCallable
            | FunctionMiddleware
            | FunctionMiddlewareCallable
        ] | None = None,
        function_invocation_configuration: FunctionInvocationConfiguration | None = None,
        **kwargs: Any,
    ) -> None:

Import Statement

from agent_framework import Agent

I/O Contract

Inputs

Parameter Type Default Description
client SupportsChatGetResponse[OptionsCoT] (required) The chat client that provides LLM inference. Must implement the SupportsChatGetResponse protocol.
instructions str "" System prompt string that defines the agent's behavior, persona, and constraints.
id None None Optional unique identifier for the agent instance.
name None None Optional human-readable name for identification and tracing.
description None None Optional description of the agent's purpose and capabilities.
tools Callable | Sequence[FunctionTool | Callable] | None None Tools the agent can invoke. Accepts a single tool, a plain callable, or a sequence of either. Callable values are automatically wrapped into FunctionTool instances.
default_options None None Model-specific options (e.g., temperature, max tokens) generic over the options type parameter.
chat_message_store_factory None None Factory for creating message stores that persist or cache conversation history.
context_provider None None Injectable component that supplies additional runtime context during agent execution.
middleware AgentMiddlewareCallable | ChatMiddleware | ChatMiddlewareCallable | FunctionMiddleware | FunctionMiddlewareCallable] | None None Middleware pipeline that intercepts and transforms agent, chat, or function invocation behavior.
function_invocation_configuration None None Configuration controlling how tool functions are invoked (e.g., parallel execution, error handling).
**kwargs Any Additional keyword arguments forwarded to the base class.

Output

Type Description
Agent[OptionsCoT] A fully configured agent instance ready for execution via agent.run() or within an async context manager.

Usage Examples

Minimal Agent

from agent_framework import Agent
from agent_framework.openai import OpenAIResponsesClient

client = OpenAIResponsesClient()
agent = Agent(
    client=client,
    instructions="You are a helpful assistant.",
    name="assistant",
)

Agent with Tools

from agent_framework import Agent
from agent_framework.openai import OpenAIResponsesClient

client = OpenAIResponsesClient()
agent = Agent(
    client=client,
    instructions="You are a helpful assistant.",
    name="assistant",
    tools=[get_weather],
)

Agent with Middleware

from agent_framework import Agent
from agent_framework.openai import OpenAIResponsesClient

client = OpenAIResponsesClient()
agent = Agent(
    client=client,
    instructions="You are a helpful assistant.",
    name="assistant",
    tools=[get_weather],
    middleware=[logging_middleware, auth_middleware],
)

Factory Method Alternative

agent = client.as_agent(
    instructions="You are a helpful assistant.",
    tools=[get_weather],
)

Related Pages

Page Connections

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