Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion infra/vscode_web/endpoint-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
azure-ai-projects==1.0.0b12
azure-ai-projects==2.1.0
azure-identity==1.20.0
ansible-core~=2.17.0
2 changes: 1 addition & 1 deletion infra/vscode_web/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
azure-ai-projects==1.0.0b12
azure-ai-projects==2.1.0
azure-identity==1.20.0
ansible-core~=2.17.0
2 changes: 1 addition & 1 deletion src/backend-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"aiofiles==24.1.0",
"azure-ai-agents==1.2.0b3",
"azure-ai-agents==1.2.0b6",
"azure-appconfiguration==1.7.1",
"azure-identity==1.25.0",
"azure-monitor-opentelemetry==1.7.0",
Expand Down
8 changes: 4 additions & 4 deletions src/backend-api/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/processor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"agent-framework==1.0.0b260107",
"agent-framework==1.3.0",
"aiohttp==3.13.4",
"art==6.5",
"azure-ai-agents==1.2.0b5",
"azure-ai-agents==1.2.0b6",
"azure-ai-inference==1.0.0b9",
"azure-ai-projects==2.0.0b3",
"azure-ai-projects==2.1.0",
"azure-appconfiguration==1.7.2",
"azure-core==1.38.0",
"azure-cosmos==4.15.0",
Expand Down
101 changes: 46 additions & 55 deletions src/processor/src/libs/agent_framework/agent_builder.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""Fluent builder for constructing ChatAgent instances with chainable configuration."""
"""Fluent builder for constructing Agent instances with chainable configuration."""

from collections.abc import Callable, MutableMapping, Sequence
from typing import Any, Literal

from agent_framework import (
AggregateContextProvider,
ChatAgent,
ChatClientProtocol,
ChatMessageStoreProtocol,
Agent,
AgentMiddleware,
BaseChatClient,
ChatMiddleware,
ContextProvider,
Middleware,
FunctionTool,
ToolMode,
ToolProtocol,
)
from pydantic import BaseModel

Expand All @@ -23,7 +22,7 @@


class AgentBuilder:
"""Fluent builder for creating ChatAgent instances with a chainable API.
"""Fluent builder for creating Agent instances with a chainable API.

This class provides two ways to create agents:
1. Fluent API with method chaining (recommended for readability)
Expand Down Expand Up @@ -59,7 +58,7 @@ class AgentBuilder:
)
"""

def __init__(self, chat_client: ChatClientProtocol):
def __init__(self, chat_client: BaseChatClient):
"""Initialize the builder with a chat client.

Args:
Expand All @@ -70,14 +69,15 @@ def __init__(self, chat_client: ChatClientProtocol):
self._id: str | None = None
self._name: str | None = None
self._description: str | None = None
self._chat_message_store_factory: (
Callable[[], ChatMessageStoreProtocol] | None
) = None
self._chat_message_store_factory: Callable[[], Any] | None = None
self._conversation_id: str | None = None
self._context_providers: (
ContextProvider | list[ContextProvider] | AggregateContextProvider | None
self._context_providers: ContextProvider | list[ContextProvider] | None = None
self._middleware: (
AgentMiddleware
| ChatMiddleware
| list[AgentMiddleware | ChatMiddleware]
| None
) = None
self._middleware: Middleware | list[Middleware] | None = None
self._frequency_penalty: float | None = None
self._logit_bias: dict[str | int, float] | None = None
self._max_tokens: int | None = None
Expand All @@ -93,10 +93,10 @@ def __init__(self, chat_client: ChatClientProtocol):
ToolMode | Literal["auto", "required", "none"] | dict[str, Any] | None
) = "auto"
self._tools: (
ToolProtocol
FunctionTool
| Callable[..., Any]
| MutableMapping[str, Any]
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
| None
) = None
self._top_p: float | None = None
Expand Down Expand Up @@ -178,10 +178,10 @@ def with_max_tokens(self, max_tokens: int) -> "AgentBuilder":

def with_tools(
self,
tools: ToolProtocol
tools: FunctionTool
| Callable[..., Any]
| MutableMapping[str, Any]
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]],
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]],
) -> "AgentBuilder":
"""Set the tools available to the agent.

Expand Down Expand Up @@ -210,7 +210,8 @@ def with_tool_choice(
return self

def with_middleware(
self, middleware: Middleware | list[Middleware]
self,
middleware: AgentMiddleware | ChatMiddleware | list[AgentMiddleware | ChatMiddleware],
) -> "AgentBuilder":
"""Set middleware for request/response processing.

Expand All @@ -225,9 +226,7 @@ def with_middleware(

def with_context_providers(
self,
context_providers: ContextProvider
| list[ContextProvider]
| AggregateContextProvider,
context_providers: ContextProvider | list[ContextProvider],
) -> "AgentBuilder":
"""Set context providers for additional conversation context.

Expand Down Expand Up @@ -385,7 +384,7 @@ def with_store(self, store: bool) -> "AgentBuilder":
return self

def with_message_store_factory(
self, factory: Callable[[], ChatMessageStoreProtocol]
self, factory: Callable[[], Any]
) -> "AgentBuilder":
"""Set the message store factory.

Expand Down Expand Up @@ -422,11 +421,11 @@ def with_kwargs(self, **kwargs: Any) -> "AgentBuilder":
self._kwargs.update(kwargs)
return self

def build(self) -> ChatAgent:
"""Build and return the configured ChatAgent.
def build(self) -> Agent:
"""Build and return the configured Agent.

Returns:
ChatAgent: Configured agent instance ready for use
Agent: Configured agent instance ready for use

Example:
.. code-block:: python
Expand All @@ -442,7 +441,7 @@ def build(self) -> ChatAgent:
async with agent:
response = await agent.run("Hello!")
"""
return ChatAgent(
return Agent(
chat_client=self._chat_client,
instructions=self._instructions,
id=self._id,
Expand Down Expand Up @@ -477,14 +476,10 @@ def create_agent_by_agentinfo(
agent_info: AgentInfo,
*,
id: str | None = None,
chat_message_store_factory: Callable[[], ChatMessageStoreProtocol]
| None = None,
chat_message_store_factory: Callable[[], Any] | None = None,
conversation_id: str | None = None,
context_providers: ContextProvider
| list[ContextProvider]
| AggregateContextProvider
| None = None,
middleware: Middleware | list[Middleware] | None = None,
context_providers: ContextProvider | list[ContextProvider] | None = None,
middleware: AgentMiddleware | ChatMiddleware | list[AgentMiddleware | ChatMiddleware] | None = None,
frequency_penalty: float | None = None,
logit_bias: dict[str | int, float] | None = None,
max_tokens: int | None = None,
Expand All @@ -500,20 +495,20 @@ def create_agent_by_agentinfo(
| Literal["auto", "required", "none"]
| dict[str, Any]
| None = "auto",
tools: ToolProtocol
tools: FunctionTool
| Callable[..., Any]
| MutableMapping[str, Any]
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
| None = None,
top_p: float | None = None,
user: str | None = None,
additional_chat_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> ChatAgent:
) -> Agent:
"""Create an agent using AgentInfo configuration with full parameter support.

This method creates a chat client from the service configuration and then
creates a ChatAgent with the specified parameters. Agent name, description,
creates a Agent with the specified parameters. Agent name, description,
and instructions are taken from AgentInfo but can be overridden via kwargs.

Args:
Expand Down Expand Up @@ -543,7 +538,7 @@ def create_agent_by_agentinfo(
**kwargs: Additional keyword arguments

Returns:
ChatAgent: Configured agent instance ready for use
Agent: Configured agent instance ready for use

Example:
.. code-block:: python
Expand Down Expand Up @@ -611,20 +606,16 @@ def create_agent_by_agentinfo(

@staticmethod
def create_agent(
chat_client: ChatClientProtocol,
chat_client: BaseChatClient,
instructions: str | None = None,
*,
id: str | None = None,
name: str | None = None,
description: str | None = None,
chat_message_store_factory: Callable[[], ChatMessageStoreProtocol]
| None = None,
chat_message_store_factory: Callable[[], Any] | None = None,
conversation_id: str | None = None,
context_providers: ContextProvider
| list[ContextProvider]
| AggregateContextProvider
| None = None,
middleware: Middleware | list[Middleware] | None = None,
context_providers: ContextProvider | list[ContextProvider] | None = None,
middleware: AgentMiddleware | ChatMiddleware | list[AgentMiddleware | ChatMiddleware] | None = None,
frequency_penalty: float | None = None,
logit_bias: dict[str | int, float] | None = None,
max_tokens: int | None = None,
Expand All @@ -640,19 +631,19 @@ def create_agent(
| Literal["auto", "required", "none"]
| dict[str, Any]
| None = "auto",
tools: ToolProtocol
tools: FunctionTool
| Callable[..., Any]
| MutableMapping[str, Any]
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
| None = None,
top_p: float | None = None,
user: str | None = None,
additional_chat_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> ChatAgent:
) -> Agent:
"""Create a Chat Client Agent.

Factory method that creates a ChatAgent instance with the specified configuration.
Factory method that creates a Agent instance with the specified configuration.
The agent uses a chat client to interact with language models and supports tools
(MCP tools, callable functions), context providers, middleware, and both streaming
and non-streaming responses.
Expand Down Expand Up @@ -686,7 +677,7 @@ def create_agent(
**kwargs: Additional keyword arguments

Returns:
ChatAgent: Configured chat agent instance that can be used directly or with async context manager
Agent: Configured chat agent instance that can be used directly or with async context manager

Examples:
Non-streaming example (from azure_response_client_basic.py):
Expand Down Expand Up @@ -761,10 +752,10 @@ def create_agent(

Note:
When the agent has MCP tools or needs proper resource cleanup, use it with
``async with`` to ensure proper initialization and cleanup via the ChatAgent's
``async with`` to ensure proper initialization and cleanup via the Agent's
async context manager protocol.
"""
return ChatAgent(
return Agent(
chat_client=chat_client,
instructions=instructions,
id=id,
Expand Down
Loading
Loading