Skip to content

Commit 268f922

Browse files
Merge pull request #280 from microsoft/revert-272-psl-cmupgrade
Revert "fix: Refactor code structure for improved readability and maintainability"
2 parents be9d690 + 01df24f commit 268f922

29 files changed

Lines changed: 1334 additions & 1821 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
azure-ai-projects==2.1.0
1+
azure-ai-projects==1.0.0b12
22
azure-identity==1.20.0
33
ansible-core~=2.17.0

infra/vscode_web/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
azure-ai-projects==2.1.0
1+
azure-ai-projects==1.0.0b12
22
azure-identity==1.20.0
33
ansible-core~=2.17.0

src/processor/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.12"
77
dependencies = [
8-
"agent-framework==1.3.0",
8+
"agent-framework==1.0.0b260107",
99
"aiohttp==3.13.5",
1010
"art==6.5",
11-
"azure-ai-agents==1.2.0b6",
11+
"azure-ai-agents==1.2.0b5",
1212
"azure-ai-inference==1.0.0b9",
1313
"azure-ai-projects==2.1.0",
1414
"azure-appconfiguration==1.8.0",

src/processor/src/libs/agent_framework/agent_builder.py

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4-
"""Fluent builder for constructing Agent instances with chainable configuration."""
4+
"""Fluent builder for constructing ChatAgent instances with chainable configuration."""
55

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

99
from agent_framework import (
10-
Agent,
11-
AgentMiddleware,
12-
BaseChatClient,
13-
ChatMiddleware,
10+
AggregateContextProvider,
11+
ChatAgent,
12+
ChatClientProtocol,
13+
ChatMessageStoreProtocol,
1414
ContextProvider,
15-
FunctionTool,
15+
Middleware,
1616
ToolMode,
17+
ToolProtocol,
1718
)
1819
from pydantic import BaseModel
1920

@@ -22,7 +23,7 @@
2223

2324

2425
class AgentBuilder:
25-
"""Fluent builder for creating Agent instances with a chainable API.
26+
"""Fluent builder for creating ChatAgent instances with a chainable API.
2627
2728
This class provides two ways to create agents:
2829
1. Fluent API with method chaining (recommended for readability)
@@ -58,7 +59,7 @@ class AgentBuilder:
5859
)
5960
"""
6061

61-
def __init__(self, chat_client: BaseChatClient):
62+
def __init__(self, chat_client: ChatClientProtocol):
6263
"""Initialize the builder with a chat client.
6364
6465
Args:
@@ -69,15 +70,14 @@ def __init__(self, chat_client: BaseChatClient):
6970
self._id: str | None = None
7071
self._name: str | None = None
7172
self._description: str | None = None
72-
self._chat_message_store_factory: Callable[[], Any] | None = None
73+
self._chat_message_store_factory: (
74+
Callable[[], ChatMessageStoreProtocol] | None
75+
) = None
7376
self._conversation_id: str | None = None
74-
self._context_providers: ContextProvider | list[ContextProvider] | None = None
75-
self._middleware: (
76-
AgentMiddleware
77-
| ChatMiddleware
78-
| list[AgentMiddleware | ChatMiddleware]
79-
| None
77+
self._context_providers: (
78+
ContextProvider | list[ContextProvider] | AggregateContextProvider | None
8079
) = 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: BaseChatClient):
9393
ToolMode | Literal["auto", "required", "none"] | dict[str, Any] | None
9494
) = "auto"
9595
self._tools: (
96-
FunctionTool
96+
ToolProtocol
9797
| Callable[..., Any]
9898
| MutableMapping[str, Any]
99-
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
99+
| Sequence[ToolProtocol | 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: FunctionTool
181+
tools: ToolProtocol
182182
| Callable[..., Any]
183183
| MutableMapping[str, Any]
184-
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]],
184+
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]],
185185
) -> "AgentBuilder":
186186
"""Set the tools available to the agent.
187187
@@ -210,8 +210,7 @@ def with_tool_choice(
210210
return self
211211

212212
def with_middleware(
213-
self,
214-
middleware: AgentMiddleware | ChatMiddleware | list[AgentMiddleware | ChatMiddleware],
213+
self, middleware: Middleware | list[Middleware]
215214
) -> "AgentBuilder":
216215
"""Set middleware for request/response processing.
217216
@@ -226,7 +225,9 @@ def with_middleware(
226225

227226
def with_context_providers(
228227
self,
229-
context_providers: ContextProvider | list[ContextProvider],
228+
context_providers: ContextProvider
229+
| list[ContextProvider]
230+
| AggregateContextProvider,
230231
) -> "AgentBuilder":
231232
"""Set context providers for additional conversation context.
232233
@@ -384,7 +385,7 @@ def with_store(self, store: bool) -> "AgentBuilder":
384385
return self
385386

386387
def with_message_store_factory(
387-
self, factory: Callable[[], Any]
388+
self, factory: Callable[[], ChatMessageStoreProtocol]
388389
) -> "AgentBuilder":
389390
"""Set the message store factory.
390391
@@ -421,11 +422,11 @@ def with_kwargs(self, **kwargs: Any) -> "AgentBuilder":
421422
self._kwargs.update(kwargs)
422423
return self
423424

424-
def build(self) -> Agent:
425-
"""Build and return the configured Agent.
425+
def build(self) -> ChatAgent:
426+
"""Build and return the configured ChatAgent.
426427
427428
Returns:
428-
Agent: Configured agent instance ready for use
429+
ChatAgent: Configured agent instance ready for use
429430
430431
Example:
431432
.. code-block:: python
@@ -441,7 +442,7 @@ def build(self) -> Agent:
441442
async with agent:
442443
response = await agent.run("Hello!")
443444
"""
444-
return Agent(
445+
return ChatAgent(
445446
chat_client=self._chat_client,
446447
instructions=self._instructions,
447448
id=self._id,
@@ -476,10 +477,14 @@ def create_agent_by_agentinfo(
476477
agent_info: AgentInfo,
477478
*,
478479
id: str | None = None,
479-
chat_message_store_factory: Callable[[], Any] | None = None,
480+
chat_message_store_factory: Callable[[], ChatMessageStoreProtocol]
481+
| None = None,
480482
conversation_id: str | None = None,
481-
context_providers: ContextProvider | list[ContextProvider] | None = None,
482-
middleware: AgentMiddleware | ChatMiddleware | list[AgentMiddleware | ChatMiddleware] | None = None,
483+
context_providers: ContextProvider
484+
| list[ContextProvider]
485+
| AggregateContextProvider
486+
| None = None,
487+
middleware: Middleware | list[Middleware] | None = None,
483488
frequency_penalty: float | None = None,
484489
logit_bias: dict[str | int, float] | None = None,
485490
max_tokens: int | None = None,
@@ -495,20 +500,20 @@ def create_agent_by_agentinfo(
495500
| Literal["auto", "required", "none"]
496501
| dict[str, Any]
497502
| None = "auto",
498-
tools: FunctionTool
503+
tools: ToolProtocol
499504
| Callable[..., Any]
500505
| MutableMapping[str, Any]
501-
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
506+
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
502507
| None = None,
503508
top_p: float | None = None,
504509
user: str | None = None,
505510
additional_chat_options: dict[str, Any] | None = None,
506511
**kwargs: Any,
507-
) -> Agent:
512+
) -> ChatAgent:
508513
"""Create an agent using AgentInfo configuration with full parameter support.
509514
510515
This method creates a chat client from the service configuration and then
511-
creates a Agent with the specified parameters. Agent name, description,
516+
creates a ChatAgent with the specified parameters. Agent name, description,
512517
and instructions are taken from AgentInfo but can be overridden via kwargs.
513518
514519
Args:
@@ -538,7 +543,7 @@ def create_agent_by_agentinfo(
538543
**kwargs: Additional keyword arguments
539544
540545
Returns:
541-
Agent: Configured agent instance ready for use
546+
ChatAgent: Configured agent instance ready for use
542547
543548
Example:
544549
.. code-block:: python
@@ -606,16 +611,20 @@ def create_agent_by_agentinfo(
606611

607612
@staticmethod
608613
def create_agent(
609-
chat_client: BaseChatClient,
614+
chat_client: ChatClientProtocol,
610615
instructions: str | None = None,
611616
*,
612617
id: str | None = None,
613618
name: str | None = None,
614619
description: str | None = None,
615-
chat_message_store_factory: Callable[[], Any] | None = None,
620+
chat_message_store_factory: Callable[[], ChatMessageStoreProtocol]
621+
| None = None,
616622
conversation_id: str | None = None,
617-
context_providers: ContextProvider | list[ContextProvider] | None = None,
618-
middleware: AgentMiddleware | ChatMiddleware | list[AgentMiddleware | ChatMiddleware] | None = None,
623+
context_providers: ContextProvider
624+
| list[ContextProvider]
625+
| AggregateContextProvider
626+
| None = None,
627+
middleware: Middleware | list[Middleware] | None = None,
619628
frequency_penalty: float | None = None,
620629
logit_bias: dict[str | int, float] | None = None,
621630
max_tokens: int | None = None,
@@ -631,19 +640,19 @@ def create_agent(
631640
| Literal["auto", "required", "none"]
632641
| dict[str, Any]
633642
| None = "auto",
634-
tools: FunctionTool
643+
tools: ToolProtocol
635644
| Callable[..., Any]
636645
| MutableMapping[str, Any]
637-
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
646+
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
638647
| None = None,
639648
top_p: float | None = None,
640649
user: str | None = None,
641650
additional_chat_options: dict[str, Any] | None = None,
642651
**kwargs: Any,
643-
) -> Agent:
652+
) -> ChatAgent:
644653
"""Create a Chat Client Agent.
645654
646-
Factory method that creates a Agent instance with the specified configuration.
655+
Factory method that creates a ChatAgent instance with the specified configuration.
647656
The agent uses a chat client to interact with language models and supports tools
648657
(MCP tools, callable functions), context providers, middleware, and both streaming
649658
and non-streaming responses.
@@ -677,7 +686,7 @@ def create_agent(
677686
**kwargs: Additional keyword arguments
678687
679688
Returns:
680-
Agent: Configured chat agent instance that can be used directly or with async context manager
689+
ChatAgent: Configured chat agent instance that can be used directly or with async context manager
681690
682691
Examples:
683692
Non-streaming example (from azure_response_client_basic.py):
@@ -752,10 +761,10 @@ def create_agent(
752761
753762
Note:
754763
When the agent has MCP tools or needs proper resource cleanup, use it with
755-
``async with`` to ensure proper initialization and cleanup via the Agent's
764+
``async with`` to ensure proper initialization and cleanup via the ChatAgent's
756765
async context manager protocol.
757766
"""
758-
return Agent(
767+
return ChatAgent(
759768
chat_client=chat_client,
760769
instructions=instructions,
761770
id=id,

src/processor/src/libs/agent_framework/agent_framework_helper.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
)
2828

2929
if TYPE_CHECKING:
30-
from agent_framework.azure import DurableAIAgentClient
31-
32-
# TODO: agent-framework 1.3.0 removed these azure clients with no replacement.
33-
# from agent_framework.azure import AzureOpenAIAssistantsClient
34-
# from agent_framework.azure import AzureOpenAIChatClient
35-
# from agent_framework.azure import AzureOpenAIResponsesClient
30+
from agent_framework.azure import (
31+
AzureAIAgentClient,
32+
AzureOpenAIAssistantsClient,
33+
AzureOpenAIChatClient,
34+
AzureOpenAIResponsesClient,
35+
)
3636

3737

3838
class ClientType(Enum):
@@ -147,7 +147,7 @@ def create_client(
147147
env_file_path: str | None = None,
148148
env_file_encoding: str | None = None,
149149
instruction_role: str | None = None,
150-
) -> Any:
150+
) -> "AzureOpenAIChatClient":
151151
pass
152152

153153
@overload
@@ -171,7 +171,7 @@ def create_client(
171171
async_client: object | None = None,
172172
env_file_path: str | None = None,
173173
env_file_encoding: str | None = None,
174-
) -> Any:
174+
) -> "AzureOpenAIAssistantsClient":
175175
pass
176176

177177
@overload
@@ -193,7 +193,7 @@ def create_client(
193193
env_file_path: str | None = None,
194194
env_file_encoding: str | None = None,
195195
instruction_role: str | None = None,
196-
) -> Any:
196+
) -> "AzureOpenAIResponsesClient":
197197
pass
198198

199199
@overload
@@ -233,7 +233,7 @@ def create_client(
233233
async_credential: object | None = None,
234234
env_file_path: str | None = None,
235235
env_file_encoding: str | None = None,
236-
) -> "DurableAIAgentClient":
236+
) -> "AzureAIAgentClient":
237237
pass
238238

239239
@staticmethod
@@ -443,12 +443,9 @@ def create_client(
443443
retry_config=retry_config,
444444
)
445445
elif client_type == ClientType.AzureOpenAIAgent:
446-
try:
447-
from agent_framework.azure import DurableAIAgentClient
448-
except ImportError:
449-
from agent_framework.azure import AzureAIAgentClient as DurableAIAgentClient
446+
from agent_framework.azure import AzureAIAgentClient
450447

451-
return DurableAIAgentClient(
448+
return AzureAIAgentClient(
452449
project_client=project_client,
453450
agent_id=agent_id,
454451
agent_name=agent_name,

src/processor/src/libs/agent_framework/agent_info.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"""Pydantic model describing an agent participant with Jinja2 template rendering."""
55

66
from typing import Any, Callable, MutableMapping, Sequence
7-
8-
from agent_framework import FunctionTool
7+
from agent_framework import ToolProtocol
98
from jinja2 import Template
109
from openai import BaseModel
1110
from pydantic import Field
@@ -21,10 +20,10 @@ class AgentInfo(BaseModel):
2120
agent_instruction: str | None = Field(default=None)
2221
agent_framework_helper: AgentFrameworkHelper | None = Field(default=None)
2322
tools: (
24-
FunctionTool
23+
ToolProtocol
2524
| Callable[..., Any]
2625
| MutableMapping[str, Any]
27-
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
26+
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
2827
| None
2928
) = Field(default=None)
3029

0 commit comments

Comments
 (0)