Skip to content

Commit 3968aed

Browse files
fix: Refactor code structure for improved readability and maintainability
2 parents 05cc25d + d7055f2 commit 3968aed

29 files changed

Lines changed: 1821 additions & 1334 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
azure-ai-projects==1.0.0b12
1+
azure-ai-projects==2.1.0
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==1.0.0b12
1+
azure-ai-projects==2.1.0
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.0.0b260107",
8+
"agent-framework==1.3.0",
99
"aiohttp==3.13.5",
1010
"art==6.5",
11-
"azure-ai-agents==1.2.0b5",
11+
"azure-ai-agents==1.2.0b6",
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: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
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

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

99
from 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
)
1918
from pydantic import BaseModel
2019

@@ -23,7 +22,7 @@
2322

2423

2524
class 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,

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

Lines changed: 15 additions & 12 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 (
31-
AzureAIAgentClient,
32-
AzureOpenAIAssistantsClient,
33-
AzureOpenAIChatClient,
34-
AzureOpenAIResponsesClient,
35-
)
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
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-
) -> "AzureOpenAIChatClient":
150+
) -> Any:
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-
) -> "AzureOpenAIAssistantsClient":
174+
) -> Any:
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-
) -> "AzureOpenAIResponsesClient":
196+
) -> Any:
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-
) -> "AzureAIAgentClient":
236+
) -> "DurableAIAgentClient":
237237
pass
238238

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

448-
return AzureAIAgentClient(
451+
return DurableAIAgentClient(
449452
project_client=project_client,
450453
agent_id=agent_id,
451454
agent_name=agent_name,

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

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

66
from typing import Any, Callable, MutableMapping, Sequence
7-
from agent_framework import ToolProtocol
7+
8+
from agent_framework import FunctionTool
89
from jinja2 import Template
910
from openai import BaseModel
1011
from pydantic import Field
@@ -20,10 +21,10 @@ class AgentInfo(BaseModel):
2021
agent_instruction: str | None = Field(default=None)
2122
agent_framework_helper: AgentFrameworkHelper | None = Field(default=None)
2223
tools: (
23-
ToolProtocol
24+
FunctionTool
2425
| Callable[..., Any]
2526
| MutableMapping[str, Any]
26-
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
27+
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
2728
| None
2829
) = Field(default=None)
2930

0 commit comments

Comments
 (0)