Skip to content
Merged
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==2.1.0
azure-ai-projects==1.0.0b12
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==2.1.0
azure-ai-projects==1.0.0b12
azure-identity==1.20.0
ansible-core~=2.17.0
4 changes: 2 additions & 2 deletions src/processor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"agent-framework==1.3.0",
"agent-framework==1.0.0b260107",
"aiohttp==3.13.5",
"art==6.5",
"azure-ai-agents==1.2.0b6",
"azure-ai-agents==1.2.0b5",
"azure-ai-inference==1.0.0b9",
"azure-ai-projects==2.1.0",
"azure-appconfiguration==1.8.0",
Expand Down
101 changes: 55 additions & 46 deletions src/processor/src/libs/agent_framework/agent_builder.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

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

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

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

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


class AgentBuilder:
"""Fluent builder for creating Agent instances with a chainable API.
"""Fluent builder for creating ChatAgent 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 @@ -58,7 +59,7 @@ class AgentBuilder:
)
"""

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

Args:
Expand All @@ -69,15 +70,14 @@ def __init__(self, chat_client: BaseChatClient):
self._id: str | None = None
self._name: str | None = None
self._description: str | None = None
self._chat_message_store_factory: Callable[[], Any] | None = None
self._chat_message_store_factory: (
Callable[[], ChatMessageStoreProtocol] | None
) = None
self._conversation_id: str | None = None
self._context_providers: ContextProvider | list[ContextProvider] | None = None
self._middleware: (
AgentMiddleware
| ChatMiddleware
| list[AgentMiddleware | ChatMiddleware]
| None
self._context_providers: (
ContextProvider | list[ContextProvider] | AggregateContextProvider | 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: BaseChatClient):
ToolMode | Literal["auto", "required", "none"] | dict[str, Any] | None
) = "auto"
self._tools: (
FunctionTool
ToolProtocol
| Callable[..., Any]
| MutableMapping[str, Any]
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
| Sequence[ToolProtocol | 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: FunctionTool
tools: ToolProtocol
| Callable[..., Any]
| MutableMapping[str, Any]
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]],
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]],
) -> "AgentBuilder":
"""Set the tools available to the agent.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Factory method that creates a Agent instance with the specified configuration.
Factory method that creates a ChatAgent 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 @@ -677,7 +686,7 @@ def create_agent(
**kwargs: Additional keyword arguments

Returns:
Agent: Configured chat agent instance that can be used directly or with async context manager
ChatAgent: 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 @@ -752,10 +761,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 Agent's
``async with`` to ensure proper initialization and cleanup via the ChatAgent's
async context manager protocol.
"""
return Agent(
return ChatAgent(
chat_client=chat_client,
instructions=instructions,
id=id,
Expand Down
27 changes: 12 additions & 15 deletions src/processor/src/libs/agent_framework/agent_framework_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
)

if TYPE_CHECKING:
from agent_framework.azure import DurableAIAgentClient

# TODO: agent-framework 1.3.0 removed these azure clients with no replacement.
# from agent_framework.azure import AzureOpenAIAssistantsClient
# from agent_framework.azure import AzureOpenAIChatClient
# from agent_framework.azure import AzureOpenAIResponsesClient
from agent_framework.azure import (
AzureAIAgentClient,
AzureOpenAIAssistantsClient,
AzureOpenAIChatClient,
AzureOpenAIResponsesClient,
)


class ClientType(Enum):
Expand Down Expand Up @@ -147,7 +147,7 @@ def create_client(
env_file_path: str | None = None,
env_file_encoding: str | None = None,
instruction_role: str | None = None,
) -> Any:
) -> "AzureOpenAIChatClient":
pass

@overload
Expand All @@ -171,7 +171,7 @@ def create_client(
async_client: object | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> Any:
) -> "AzureOpenAIAssistantsClient":
pass

@overload
Expand All @@ -193,7 +193,7 @@ def create_client(
env_file_path: str | None = None,
env_file_encoding: str | None = None,
instruction_role: str | None = None,
) -> Any:
) -> "AzureOpenAIResponsesClient":
pass

@overload
Expand Down Expand Up @@ -233,7 +233,7 @@ def create_client(
async_credential: object | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> "DurableAIAgentClient":
) -> "AzureAIAgentClient":
pass

@staticmethod
Expand Down Expand Up @@ -443,12 +443,9 @@ def create_client(
retry_config=retry_config,
)
elif client_type == ClientType.AzureOpenAIAgent:
try:
from agent_framework.azure import DurableAIAgentClient
except ImportError:
from agent_framework.azure import AzureAIAgentClient as DurableAIAgentClient
from agent_framework.azure import AzureAIAgentClient

return DurableAIAgentClient(
return AzureAIAgentClient(
project_client=project_client,
agent_id=agent_id,
agent_name=agent_name,
Expand Down
7 changes: 3 additions & 4 deletions src/processor/src/libs/agent_framework/agent_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"""Pydantic model describing an agent participant with Jinja2 template rendering."""

from typing import Any, Callable, MutableMapping, Sequence

from agent_framework import FunctionTool
from agent_framework import ToolProtocol
from jinja2 import Template
from openai import BaseModel
from pydantic import Field
Expand All @@ -21,10 +20,10 @@ class AgentInfo(BaseModel):
agent_instruction: str | None = Field(default=None)
agent_framework_helper: AgentFrameworkHelper | None = Field(default=None)
tools: (
FunctionTool
ToolProtocol
| Callable[..., Any]
| MutableMapping[str, Any]
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
| None
) = Field(default=None)

Expand Down
Loading
Loading