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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

### Bugs Fixed

- Mitigate AgentThread management for AzureAIClient agents.
- Mitigate AgentSession management for AzureAIClient agents.


## 1.0.0b11 (2026-02-10)
Expand All @@ -44,7 +44,7 @@
### Features Added

- Integrated with Foundry Tools
- Add persistence for agent thread and checkpoint
- Add persistence for agent session and checkpoint
- Fixed WorkflowAgent concurrency issue
- Support Human-in-the-Loop

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,43 @@
# pylint: disable=docstring-should-be-keyword
__path__ = __import__("pkgutil").extend_path(__path__, __name__)

from typing import Callable, Optional, Union, overload
from typing import TYPE_CHECKING, Callable, Optional, Union, overload

from agent_framework import AgentProtocol, BaseAgent, Workflow, WorkflowBuilder
from azure.core.credentials_async import AsyncTokenCredential
from azure.core.credentials import TokenCredential
from agent_framework import BaseAgent, SupportsAgentRun, Workflow, WorkflowBuilder

from azure.ai.agentserver.core.application import PackageMetadata, set_current_app # pylint: disable=import-error,no-name-in-module
from azure.ai.agentserver.core.application import ( # pylint: disable=import-error,no-name-in-module
PackageMetadata,
set_current_app,
)
from azure.core.credentials import TokenCredential
from azure.core.credentials_async import AsyncTokenCredential

from ._version import VERSION
from ._agent_framework import AgentFrameworkAgent
from ._ai_agent_adapter import AgentFrameworkAIAgentAdapter
from ._workflow_agent_adapter import AgentFrameworkWorkflowAdapter
from ._foundry_tools import FoundryToolsChatMiddleware
from .persistence import AgentThreadRepository, CheckpointRepository
from ._version import VERSION
from .persistence import AgentSessionRepository, CheckpointRepository

if TYPE_CHECKING:
from ._agent_framework import AgentFrameworkAgent
from ._ai_agent_adapter import AgentFrameworkAIAgentAdapter
from ._workflow_agent_adapter import AgentFrameworkWorkflowAdapter


@overload
def from_agent_framework(
agent: Union[BaseAgent, AgentProtocol],
agent: Union[BaseAgent, SupportsAgentRun],
/,
credentials: Optional[Union[AsyncTokenCredential, TokenCredential]] = None,
thread_repository: Optional[AgentThreadRepository]=None
session_repository: Optional[AgentSessionRepository]=None
) -> "AgentFrameworkAIAgentAdapter":
"""
Create an Agent Framework AI Agent Adapter from an AgentProtocol or BaseAgent.
Create an Agent Framework AI Agent Adapter from a SupportsAgentRun or BaseAgent.

:param agent: The agent to adapt.
:type agent: Union[BaseAgent, AgentProtocol]
:type agent: Union[BaseAgent, SupportsAgentRun]
:param credentials: Optional asynchronous token credential for authentication.
:type credentials: Optional[Union[AsyncTokenCredential, TokenCredential]]
:param thread_repository: Optional thread repository for agent thread management.
:type thread_repository: Optional[AgentThreadRepository]
:param session_repository: Optional session repository for agent session management.
:type session_repository: Optional[AgentSessionRepository]

:return: An instance of AgentFrameworkAIAgentAdapter.
:rtype: AgentFrameworkAIAgentAdapter
Expand All @@ -47,7 +52,7 @@ def from_agent_framework(
workflow: Union[WorkflowBuilder, Callable[[], Workflow]],
/,
credentials: Optional[Union[AsyncTokenCredential, TokenCredential]] = None,
thread_repository: Optional[AgentThreadRepository] = None,
session_repository: Optional[AgentSessionRepository] = None,
checkpoint_repository: Optional[CheckpointRepository] = None,
) -> "AgentFrameworkWorkflowAdapter":
"""
Expand All @@ -63,8 +68,8 @@ def from_agent_framework(
:type workflow: Union[WorkflowBuilder, Callable[[], Workflow]]
:param credentials: Optional asynchronous token credential for authentication.
:type credentials: Optional[Union[AsyncTokenCredential, TokenCredential]]
:param thread_repository: Optional thread repository for agent thread management.
:type thread_repository: Optional[AgentThreadRepository]
:param session_repository: Optional session repository for agent session management.
:type session_repository: Optional[AgentSessionRepository]
:param checkpoint_repository: Optional checkpoint repository for workflow checkpointing.
Use ``InMemoryCheckpointRepository``, ``FileCheckpointRepository``, or
``FoundryCheckpointRepository`` for Azure AI Foundry managed storage.
Expand All @@ -75,23 +80,23 @@ def from_agent_framework(
...

def from_agent_framework(
agent_or_workflow: Union[BaseAgent, AgentProtocol, WorkflowBuilder, Callable[[], Workflow]],
agent_or_workflow: Union[BaseAgent, SupportsAgentRun, WorkflowBuilder, Callable[[], Workflow]],
/,
credentials: Optional[Union[AsyncTokenCredential, TokenCredential]] = None,
thread_repository: Optional[AgentThreadRepository] = None,
session_repository: Optional[AgentSessionRepository] = None,
checkpoint_repository: Optional[CheckpointRepository] = None,
) -> "AgentFrameworkAgent":
"""
Create an Agent Framework Adapter from either an AgentProtocol/BaseAgent or a
Create an Agent Framework Adapter from either a SupportsAgentRun/BaseAgent or a
WorkflowAgent.
One of agent or workflow must be provided.

:param agent_or_workflow: The agent to adapt.
:type agent_or_workflow: Optional[Union[BaseAgent, AgentProtocol]]
:type agent_or_workflow: Optional[Union[BaseAgent, SupportsAgentRun]]
:param credentials: Optional asynchronous token credential for authentication.
:type credentials: Optional[Union[AsyncTokenCredential, TokenCredential]]
:param thread_repository: Optional thread repository for agent thread management.
:type thread_repository: Optional[AgentThreadRepository]
:param session_repository: Optional session repository for agent session management.
:type session_repository: Optional[AgentSessionRepository]
:param checkpoint_repository: Optional checkpoint repository for workflow checkpointing.
Use ``InMemoryCheckpointRepository``, ``FileCheckpointRepository``, or
``FoundryCheckpointRepository`` for Azure AI Foundry managed storage.
Expand All @@ -103,27 +108,33 @@ def from_agent_framework(
"""

if isinstance(agent_or_workflow, WorkflowBuilder):
from ._workflow_agent_adapter import AgentFrameworkWorkflowAdapter

return AgentFrameworkWorkflowAdapter(
workflow_factory=agent_or_workflow.build,
credentials=credentials,
thread_repository=thread_repository,
session_repository=session_repository,
checkpoint_repository=checkpoint_repository,
)
if isinstance(agent_or_workflow, Callable): # type: ignore
from ._workflow_agent_adapter import AgentFrameworkWorkflowAdapter

return AgentFrameworkWorkflowAdapter(
workflow_factory=agent_or_workflow,
credentials=credentials,
thread_repository=thread_repository,
session_repository=session_repository,
checkpoint_repository=checkpoint_repository,
)
# raise TypeError("workflow must be a WorkflowBuilder or callable returning a Workflow")

if isinstance(agent_or_workflow, (AgentProtocol, BaseAgent)):
if isinstance(agent_or_workflow, (SupportsAgentRun, BaseAgent)):
from ._ai_agent_adapter import AgentFrameworkAIAgentAdapter

return AgentFrameworkAIAgentAdapter(agent_or_workflow,
credentials=credentials,
thread_repository=thread_repository)
session_repository=session_repository)
raise TypeError("You must provide one of the instances of type "
"[AgentProtocol, BaseAgent, WorkflowBuilder or callable returning a Workflow]")
"[SupportsAgentRun, BaseAgent, WorkflowBuilder or callable returning a Workflow]")


__all__ = [
Expand Down
Loading