11# Copyright (c) Microsoft Corporation.
22# Licensed under the MIT License.
33
4- """Fluent builder and static factories for Agent construction.
4+ """Fluent builder and static factories for ChatAgent construction.
55
66This module provides ``AgentBuilder``, a single class offering two complementary
7- APIs for creating ``Agent `` instances:
7+ APIs for creating ``ChatAgent `` instances:
88
991. **Fluent builder** (recommended for readability):
1010 ``AgentBuilder(client).with_name(...).with_tools(...).build()``
1515
1616Design decisions:
1717 - Every ``with_*()`` setter returns ``self`` for method chaining.
18- - ``build()`` and the static factories all delegate to the ``Agent ``
18+ - ``build()`` and the static factories all delegate to the ``ChatAgent ``
1919 constructor; the builder simply accumulates keyword arguments.
2020 - ``create_agent_by_agentinfo`` resolves the chat client from the
2121 ``AgentFrameworkHelper`` attached to the ``AgentInfo``, so callers
2424Supported configuration axes:
2525 - Model parameters: temperature, top_p, max_tokens, frequency/presence penalty.
2626 - Structured output: ``response_format`` (Pydantic model).
27- - Tool binding: ``tools`` (MCP tools, callables, generic tool objects , dicts).
27+ - Tool binding: ``tools`` (MCP tools, callables, tool protocols , dicts).
2828 - Middleware: ``middleware`` (AgentMiddleware, ChatMiddleware, etc.).
2929 - Context providers: ``context_providers`` for injecting dynamic context.
3030 - Provider-specific options: ``additional_chat_options`` dict.
5050
5151
5252class AgentBuilder :
53- """Fluent builder for creating Agent instances with a chainable API.
53+ """Fluent builder for creating ChatAgent instances with a chainable API.
5454
5555 This class provides two ways to create agents:
5656 1. Fluent API with method chaining (recommended for readability)
@@ -90,7 +90,7 @@ def __init__(self, chat_client: SupportsChatGetResponse):
9090 """Initialize the builder with a chat client and default-None fields.
9191
9292 All configuration is stored as private attributes. None of them are
93- set to non-trivial defaults here; the ``Agent `` constructor applies
93+ set to non-trivial defaults here; the ``ChatAgent `` constructor applies
9494 its own defaults for any parameter that remains ``None``.
9595
9696 Args:
@@ -251,7 +251,7 @@ def with_middleware(
251251 """Set middleware for request/response processing.
252252
253253 Args:
254- middleware: Agent or chat middleware, or a list of them
254+ middleware: Middleware or list of middlewares
255255
256256 Returns:
257257 Self for method chaining
@@ -457,18 +457,18 @@ def with_kwargs(self, **kwargs: Any) -> "AgentBuilder":
457457 return self
458458
459459 def build (self ) -> Agent :
460- """Construct an ``Agent `` from the accumulated configuration.
460+ """Construct a ``ChatAgent `` from the accumulated configuration.
461461
462462 Processing steps:
463463 1. Collect every attribute set via ``with_*()`` calls.
464- 2. Pass them as keyword arguments to ``Agent (...)``.
464+ 2. Pass them as keyword arguments to ``ChatAgent (...)``.
465465 3. Return the fully constructed agent.
466466
467467 The returned agent can be used directly or as an async context manager
468468 (``async with agent: ...``) when tools require lifecycle management.
469469
470470 Returns:
471- An ``Agent `` instance ready for ``run()`` / ``run_stream()``.
471+ A ``ChatAgent `` instance ready for ``run()`` / ``run_stream()``.
472472
473473 Example:
474474 .. code-block:: python
@@ -484,7 +484,6 @@ def build(self) -> Agent:
484484 async with agent:
485485 response = await agent.run("Hello!")
486486 """
487- # Build default_options from model parameters
488487 options : dict [str , Any ] = {}
489488 if self ._frequency_penalty is not None :
490489 options ["frequency_penalty" ] = self ._frequency_penalty
@@ -571,7 +570,7 @@ def create_agent_by_agentinfo(
571570 additional_chat_options : dict [str , Any ] | None = None ,
572571 ** kwargs : Any ,
573572 ) -> Agent :
574- """Create an ``Agent `` from an ``AgentInfo`` metadata bundle.
573+ """Create a ``ChatAgent `` from an ``AgentInfo`` metadata bundle.
575574
576575 This factory resolves the chat client automatically by reading the
577576 ``AgentFrameworkHelper`` and ``ServiceConfig`` attached to the given
@@ -595,7 +594,7 @@ def create_agent_by_agentinfo(
595594 chat_message_store_factory: Factory function to create message stores
596595 conversation_id: ID for conversation tracking
597596 context_providers: Providers for additional context in conversations
598- middleware: Agent or chat middleware for request/response processing
597+ middleware: Middleware for request/response processing
599598 frequency_penalty: Penalize frequent token usage (-2.0 to 2.0)
600599 logit_bias: Modify likelihood of specific tokens
601600 max_tokens: Maximum tokens in the response
@@ -608,14 +607,14 @@ def create_agent_by_agentinfo(
608607 store: Whether to store conversation history
609608 temperature: Sampling temperature (0.0 to 2.0)
610609 tool_choice: Tool selection mode
611- tools: Tools available to the agent (MCP tools, callables, or generic tool objects )
610+ tools: Tools available to the agent (MCP tools, callables, or tool protocols )
612611 top_p: Nucleus sampling parameter
613612 user: User identifier for tracking
614613 additional_chat_options: Provider-specific options
615614 **kwargs: Additional keyword arguments
616615
617616 Returns:
618- Agent : Configured agent instance ready for use
617+ ChatAgent : Configured agent instance ready for use
619618
620619 Example:
621620 .. code-block:: python
@@ -722,9 +721,9 @@ def create_agent(
722721 additional_chat_options : dict [str , Any ] | None = None ,
723722 ** kwargs : Any ,
724723 ) -> Agent :
725- """Create a chat client agent .
724+ """Create a Chat Client Agent .
726725
727- Factory method that creates an Agent instance with the specified configuration.
726+ Factory method that creates a ChatAgent instance with the specified configuration.
728727 The agent uses a chat client to interact with language models and supports tools
729728 (MCP tools, callable functions), context providers, middleware, and both streaming
730729 and non-streaming responses.
@@ -738,7 +737,7 @@ def create_agent(
738737 chat_message_store_factory: Factory function to create message stores
739738 conversation_id: ID for conversation tracking
740739 context_providers: Providers for additional context in conversations
741- middleware: Agent or chat middleware for request/response processing
740+ middleware: Middleware for request/response processing
742741 frequency_penalty: Penalize frequent token usage (-2.0 to 2.0)
743742 logit_bias: Modify likelihood of specific tokens
744743 max_tokens: Maximum tokens in the response
@@ -751,14 +750,14 @@ def create_agent(
751750 store: Whether to store conversation history
752751 temperature: Sampling temperature (0.0 to 2.0)
753752 tool_choice: Tool selection mode ("auto", "required", "none", or specific tool)
754- tools: Tools available to the agent (MCP tools, callables, or generic tool objects )
753+ tools: Tools available to the agent (MCP tools, callables, or tool protocols )
755754 top_p: Nucleus sampling parameter
756755 user: User identifier for tracking
757756 additional_chat_options: Provider-specific options
758757 **kwargs: Additional keyword arguments
759758
760759 Returns:
761- Agent : Configured chat agent instance that can be used directly or with async context manager
760+ ChatAgent : Configured chat agent instance that can be used directly or with async context manager
762761
763762 Examples:
764763 Non-streaming example (from azure_response_client_basic.py):
@@ -833,10 +832,9 @@ def create_agent(
833832
834833 Note:
835834 When the agent has MCP tools or needs proper resource cleanup, use it with
836- ``async with`` to ensure proper initialization and cleanup via the Agent 's
835+ ``async with`` to ensure proper initialization and cleanup via the ChatAgent 's
837836 async context manager protocol.
838837 """
839- # Build default_options from model parameters
840838 options : dict [str , Any ] = {}
841839 if frequency_penalty is not None :
842840 options ["frequency_penalty" ] = frequency_penalty
0 commit comments