11# Copyright (c) Microsoft Corporation.
22# Licensed under the MIT License.
33
4- """Fluent builder for constructing ChatAgent instances with chainable configuration."""
4+ """Fluent builder for constructing Agent instances with chainable configuration."""
55
66from collections .abc import Callable , MutableMapping , Sequence
77from typing import Any , Literal
88
99from agent_framework import (
10- AggregateContextProvider ,
11- ChatAgent ,
12- ChatClientProtocol ,
13- ChatMessageStoreProtocol ,
10+ Agent ,
11+ AgentMiddleware ,
12+ BaseChatClient ,
13+ ChatMiddleware ,
1414 ContextProvider ,
15- Middleware ,
15+ FunctionTool ,
1616 ToolMode ,
17- ToolProtocol ,
1817)
1918from pydantic import BaseModel
2019
2322
2423
2524class AgentBuilder :
26- """Fluent builder for creating ChatAgent instances with a chainable API.
25+ """Fluent builder for creating Agent instances with a chainable API.
2726
2827 This class provides two ways to create agents:
2928 1. Fluent API with method chaining (recommended for readability)
@@ -59,7 +58,7 @@ class AgentBuilder:
5958 )
6059 """
6160
62- def __init__ (self , chat_client : ChatClientProtocol ):
61+ def __init__ (self , chat_client : BaseChatClient ):
6362 """Initialize the builder with a chat client.
6463
6564 Args:
@@ -70,14 +69,15 @@ def __init__(self, chat_client: ChatClientProtocol):
7069 self ._id : str | None = None
7170 self ._name : str | None = None
7271 self ._description : str | None = None
73- self ._chat_message_store_factory : (
74- Callable [[], ChatMessageStoreProtocol ] | None
75- ) = None
72+ self ._chat_message_store_factory : Callable [[], Any ] | None = None
7673 self ._conversation_id : str | None = None
77- self ._context_providers : (
78- ContextProvider | list [ContextProvider ] | AggregateContextProvider | None
74+ self ._context_providers : ContextProvider | list [ContextProvider ] | None = None
75+ self ._middleware : (
76+ AgentMiddleware
77+ | ChatMiddleware
78+ | list [AgentMiddleware | ChatMiddleware ]
79+ | None
7980 ) = None
80- self ._middleware : Middleware | list [Middleware ] | None = None
8181 self ._frequency_penalty : float | None = None
8282 self ._logit_bias : dict [str | int , float ] | None = None
8383 self ._max_tokens : int | None = None
@@ -93,10 +93,10 @@ def __init__(self, chat_client: ChatClientProtocol):
9393 ToolMode | Literal ["auto" , "required" , "none" ] | dict [str , Any ] | None
9494 ) = "auto"
9595 self ._tools : (
96- ToolProtocol
96+ FunctionTool
9797 | Callable [..., Any ]
9898 | MutableMapping [str , Any ]
99- | Sequence [ToolProtocol | Callable [..., Any ] | MutableMapping [str , Any ]]
99+ | Sequence [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ]]
100100 | None
101101 ) = None
102102 self ._top_p : float | None = None
@@ -178,10 +178,10 @@ def with_max_tokens(self, max_tokens: int) -> "AgentBuilder":
178178
179179 def with_tools (
180180 self ,
181- tools : ToolProtocol
181+ tools : FunctionTool
182182 | Callable [..., Any ]
183183 | MutableMapping [str , Any ]
184- | Sequence [ToolProtocol | Callable [..., Any ] | MutableMapping [str , Any ]],
184+ | Sequence [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ]],
185185 ) -> "AgentBuilder" :
186186 """Set the tools available to the agent.
187187
@@ -210,7 +210,8 @@ def with_tool_choice(
210210 return self
211211
212212 def with_middleware (
213- self , middleware : Middleware | list [Middleware ]
213+ self ,
214+ middleware : AgentMiddleware | ChatMiddleware | list [AgentMiddleware | ChatMiddleware ],
214215 ) -> "AgentBuilder" :
215216 """Set middleware for request/response processing.
216217
@@ -225,9 +226,7 @@ def with_middleware(
225226
226227 def with_context_providers (
227228 self ,
228- context_providers : ContextProvider
229- | list [ContextProvider ]
230- | AggregateContextProvider ,
229+ context_providers : ContextProvider | list [ContextProvider ],
231230 ) -> "AgentBuilder" :
232231 """Set context providers for additional conversation context.
233232
@@ -385,7 +384,7 @@ def with_store(self, store: bool) -> "AgentBuilder":
385384 return self
386385
387386 def with_message_store_factory (
388- self , factory : Callable [[], ChatMessageStoreProtocol ]
387+ self , factory : Callable [[], Any ]
389388 ) -> "AgentBuilder" :
390389 """Set the message store factory.
391390
@@ -422,11 +421,11 @@ def with_kwargs(self, **kwargs: Any) -> "AgentBuilder":
422421 self ._kwargs .update (kwargs )
423422 return self
424423
425- def build (self ) -> ChatAgent :
426- """Build and return the configured ChatAgent .
424+ def build (self ) -> Agent :
425+ """Build and return the configured Agent .
427426
428427 Returns:
429- ChatAgent : Configured agent instance ready for use
428+ Agent : Configured agent instance ready for use
430429
431430 Example:
432431 .. code-block:: python
@@ -442,7 +441,7 @@ def build(self) -> ChatAgent:
442441 async with agent:
443442 response = await agent.run("Hello!")
444443 """
445- return ChatAgent (
444+ return Agent (
446445 chat_client = self ._chat_client ,
447446 instructions = self ._instructions ,
448447 id = self ._id ,
@@ -477,14 +476,10 @@ def create_agent_by_agentinfo(
477476 agent_info : AgentInfo ,
478477 * ,
479478 id : str | None = None ,
480- chat_message_store_factory : Callable [[], ChatMessageStoreProtocol ]
481- | None = None ,
479+ chat_message_store_factory : Callable [[], Any ] | None = None ,
482480 conversation_id : str | None = None ,
483- context_providers : ContextProvider
484- | list [ContextProvider ]
485- | AggregateContextProvider
486- | None = None ,
487- middleware : Middleware | list [Middleware ] | None = None ,
481+ context_providers : ContextProvider | list [ContextProvider ] | None = None ,
482+ middleware : AgentMiddleware | ChatMiddleware | list [AgentMiddleware | ChatMiddleware ] | None = None ,
488483 frequency_penalty : float | None = None ,
489484 logit_bias : dict [str | int , float ] | None = None ,
490485 max_tokens : int | None = None ,
@@ -500,20 +495,20 @@ def create_agent_by_agentinfo(
500495 | Literal ["auto" , "required" , "none" ]
501496 | dict [str , Any ]
502497 | None = "auto" ,
503- tools : ToolProtocol
498+ tools : FunctionTool
504499 | Callable [..., Any ]
505500 | MutableMapping [str , Any ]
506- | Sequence [ToolProtocol | Callable [..., Any ] | MutableMapping [str , Any ]]
501+ | Sequence [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ]]
507502 | None = None ,
508503 top_p : float | None = None ,
509504 user : str | None = None ,
510505 additional_chat_options : dict [str , Any ] | None = None ,
511506 ** kwargs : Any ,
512- ) -> ChatAgent :
507+ ) -> Agent :
513508 """Create an agent using AgentInfo configuration with full parameter support.
514509
515510 This method creates a chat client from the service configuration and then
516- creates a ChatAgent with the specified parameters. Agent name, description,
511+ creates a Agent with the specified parameters. Agent name, description,
517512 and instructions are taken from AgentInfo but can be overridden via kwargs.
518513
519514 Args:
@@ -543,7 +538,7 @@ def create_agent_by_agentinfo(
543538 **kwargs: Additional keyword arguments
544539
545540 Returns:
546- ChatAgent : Configured agent instance ready for use
541+ Agent : Configured agent instance ready for use
547542
548543 Example:
549544 .. code-block:: python
@@ -611,20 +606,16 @@ def create_agent_by_agentinfo(
611606
612607 @staticmethod
613608 def create_agent (
614- chat_client : ChatClientProtocol ,
609+ chat_client : BaseChatClient ,
615610 instructions : str | None = None ,
616611 * ,
617612 id : str | None = None ,
618613 name : str | None = None ,
619614 description : str | None = None ,
620- chat_message_store_factory : Callable [[], ChatMessageStoreProtocol ]
621- | None = None ,
615+ chat_message_store_factory : Callable [[], Any ] | None = None ,
622616 conversation_id : str | None = None ,
623- context_providers : ContextProvider
624- | list [ContextProvider ]
625- | AggregateContextProvider
626- | None = None ,
627- middleware : Middleware | list [Middleware ] | None = None ,
617+ context_providers : ContextProvider | list [ContextProvider ] | None = None ,
618+ middleware : AgentMiddleware | ChatMiddleware | list [AgentMiddleware | ChatMiddleware ] | None = None ,
628619 frequency_penalty : float | None = None ,
629620 logit_bias : dict [str | int , float ] | None = None ,
630621 max_tokens : int | None = None ,
@@ -640,19 +631,19 @@ def create_agent(
640631 | Literal ["auto" , "required" , "none" ]
641632 | dict [str , Any ]
642633 | None = "auto" ,
643- tools : ToolProtocol
634+ tools : FunctionTool
644635 | Callable [..., Any ]
645636 | MutableMapping [str , Any ]
646- | Sequence [ToolProtocol | Callable [..., Any ] | MutableMapping [str , Any ]]
637+ | Sequence [FunctionTool | Callable [..., Any ] | MutableMapping [str , Any ]]
647638 | None = None ,
648639 top_p : float | None = None ,
649640 user : str | None = None ,
650641 additional_chat_options : dict [str , Any ] | None = None ,
651642 ** kwargs : Any ,
652- ) -> ChatAgent :
643+ ) -> Agent :
653644 """Create a Chat Client Agent.
654645
655- Factory method that creates a ChatAgent instance with the specified configuration.
646+ Factory method that creates a Agent instance with the specified configuration.
656647 The agent uses a chat client to interact with language models and supports tools
657648 (MCP tools, callable functions), context providers, middleware, and both streaming
658649 and non-streaming responses.
@@ -686,7 +677,7 @@ def create_agent(
686677 **kwargs: Additional keyword arguments
687678
688679 Returns:
689- ChatAgent : Configured chat agent instance that can be used directly or with async context manager
680+ Agent : Configured chat agent instance that can be used directly or with async context manager
690681
691682 Examples:
692683 Non-streaming example (from azure_response_client_basic.py):
@@ -761,10 +752,10 @@ def create_agent(
761752
762753 Note:
763754 When the agent has MCP tools or needs proper resource cleanup, use it with
764- ``async with`` to ensure proper initialization and cleanup via the ChatAgent 's
755+ ``async with`` to ensure proper initialization and cleanup via the Agent 's
765756 async context manager protocol.
766757 """
767- return ChatAgent (
758+ return Agent (
768759 chat_client = chat_client ,
769760 instructions = instructions ,
770761 id = id ,
0 commit comments