Skip to content

Commit 942e809

Browse files
authored
Fix compatibility with agent-framework-core 1.0.0rc4 and openai 2.x (#201)
* Fix compatibility with agent-framework-core 1.0.0rc4 and openai 2.x Update microsoft-agents-a365-tooling-extensions-agentframework to use renamed APIs introduced in agent-framework-core 1.0.0rc4: - ChatAgent -> RawAgent - ChatMessage -> Message - ChatMessageStoreProtocol -> BaseHistoryProvider - Constructor kwarg chat_client= -> client= - Store method list_messages() -> get_messages() Upgrade constraints and lock file: - agent-framework-azure-ai: >=1.0.0b251114 -> >=1.0.0rc4 (1.0.0rc4) - agent-framework-core: 1.0.0b260130 -> 1.0.0rc4 - openai: >=1.0.0 -> >=2.0.0 (2.28.0, required by rc4) - openai-agents: 0.3.3 -> 0.4.2 - semantic-kernel: 1.39.4 -> 1.41.0 Update integration test (test_agentframework_trace_processor.py) and unit tests to use the new API names. * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix docstring and return type issues in McpToolRegistrationService - Correct return type of add_tool_servers_to_agent from Optional[RawAgent] to RawAgent - Update docstring to reference RawAgent instead of stale chat agent - Fix docstring example to use string role user instead of undefined Role.USER ---------
1 parent c9af672 commit 942e809

File tree

6 files changed

+77
-60
lines changed

6 files changed

+77
-60
lines changed

libraries/microsoft-agents-a365-tooling-extensions-agentframework/microsoft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from datetime import datetime, timezone
77
from typing import Any, List, Optional, Sequence, Union
88

9-
from agent_framework import ChatAgent, ChatMessage, ChatMessageStoreProtocol, MCPStreamableHTTPTool
9+
from agent_framework import RawAgent, Message, BaseHistoryProvider, MCPStreamableHTTPTool
1010
from agent_framework.azure import AzureOpenAIChatClient
1111
from agent_framework.openai import OpenAIChatClient
1212
import httpx
@@ -62,9 +62,9 @@ async def add_tool_servers_to_agent(
6262
auth_handler_name: str,
6363
turn_context: TurnContext,
6464
auth_token: Optional[str] = None,
65-
) -> Optional[ChatAgent]:
65+
) -> RawAgent:
6666
"""
67-
Add MCP tool servers to a chat agent (mirrors .NET implementation).
67+
Add MCP tool servers to a RawAgent (mirrors .NET implementation).
6868
6969
Args:
7070
chat_client: The chat client instance (Union[OpenAIChatClient, AzureOpenAIChatClient])
@@ -76,7 +76,10 @@ async def add_tool_servers_to_agent(
7676
auth_token: Optional bearer token for authentication
7777
7878
Returns:
79-
ChatAgent instance with MCP tools registered, or None if creation failed
79+
RawAgent instance with MCP tools registered.
80+
81+
Raises:
82+
Exception: If agent creation fails.
8083
"""
8184
try:
8285
# Exchange token if not provided
@@ -148,9 +151,9 @@ async def add_tool_servers_to_agent(
148151
)
149152
continue
150153

151-
# Create the ChatAgent
152-
agent = ChatAgent(
153-
chat_client=chat_client,
154+
# Create the RawAgent
155+
agent = RawAgent(
156+
client=chat_client,
154157
tools=all_tools,
155158
instructions=agent_instructions,
156159
)
@@ -164,25 +167,25 @@ async def add_tool_servers_to_agent(
164167

165168
def _convert_chat_messages_to_history(
166169
self,
167-
chat_messages: Sequence[ChatMessage],
170+
chat_messages: Sequence[Message],
168171
) -> List[ChatHistoryMessage]:
169172
"""
170-
Convert Agent Framework ChatMessage objects to ChatHistoryMessage format.
173+
Convert Agent Framework Message objects to ChatHistoryMessage format.
171174
172-
This internal helper method transforms Agent Framework's native ChatMessage
175+
This internal helper method transforms Agent Framework's native Message
173176
objects into the ChatHistoryMessage format expected by the MCP platform's
174177
real-time threat protection endpoint.
175178
176179
Args:
177-
chat_messages: Sequence of ChatMessage objects to convert.
180+
chat_messages: Sequence of Message objects to convert.
178181
179182
Returns:
180183
List of ChatHistoryMessage objects ready for the MCP platform.
181184
182185
Note:
183186
- If message_id is None, a new UUID is generated
184187
- Role is extracted via the .value property of the Role object
185-
- Timestamp is set to current UTC time (ChatMessage has no timestamp)
188+
- Timestamp is set to current UTC time (Message has no timestamp)
186189
- Messages with empty or whitespace-only content are filtered out and
187190
logged at WARNING level. This is because ChatHistoryMessage requires
188191
non-empty content for validation. The filtered messages will not be
@@ -225,7 +228,7 @@ def _convert_chat_messages_to_history(
225228

226229
async def send_chat_history_messages(
227230
self,
228-
chat_messages: Sequence[ChatMessage],
231+
chat_messages: Sequence[Message],
229232
turn_context: TurnContext,
230233
tool_options: Optional[ToolOptions] = None,
231234
) -> OperationResult:
@@ -236,7 +239,7 @@ async def send_chat_history_messages(
236239
and delegation to the core tooling service.
237240
238241
Args:
239-
chat_messages: Sequence of Agent Framework ChatMessage objects to send.
242+
chat_messages: Sequence of Agent Framework Message objects to send.
240243
Can be empty - the request will still be sent to register
241244
the user message from turn_context.activity.text.
242245
turn_context: TurnContext from the Agents SDK containing conversation info.
@@ -257,7 +260,7 @@ async def send_chat_history_messages(
257260
258261
Example:
259262
>>> service = McpToolRegistrationService()
260-
>>> messages = [ChatMessage(role=Role.USER, text="Hello")]
263+
>>> messages = [Message(role="user", text="Hello")]
261264
>>> result = await service.send_chat_history_messages(messages, turn_context)
262265
>>> if result.succeeded:
263266
... print("Chat history sent successfully")
@@ -304,18 +307,18 @@ async def send_chat_history_messages(
304307

305308
async def send_chat_history_from_store(
306309
self,
307-
chat_message_store: ChatMessageStoreProtocol,
310+
chat_message_store: BaseHistoryProvider,
308311
turn_context: TurnContext,
309312
tool_options: Optional[ToolOptions] = None,
310313
) -> OperationResult:
311314
"""
312-
Send chat history from a ChatMessageStore to the MCP platform.
315+
Send chat history from a BaseHistoryProvider to the MCP platform.
313316
314317
This is a convenience method that extracts messages from the store
315318
and delegates to send_chat_history_messages().
316319
317320
Args:
318-
chat_message_store: ChatMessageStore containing the conversation history.
321+
chat_message_store: BaseHistoryProvider containing the conversation history.
319322
turn_context: TurnContext from the Agents SDK containing conversation info.
320323
tool_options: Optional configuration for the request.
321324
@@ -339,7 +342,7 @@ async def send_chat_history_from_store(
339342
raise ValueError("turn_context cannot be None")
340343

341344
# Extract messages from the store
342-
messages = await chat_message_store.list_messages()
345+
messages = await chat_message_store.get_messages()
343346

344347
# Delegate to the primary implementation
345348
return await self.send_chat_history_messages(

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ constraint-dependencies = [
8181
"azure-monitor-opentelemetry-exporter >= 1.0.0b39",
8282

8383
# --- AI Frameworks ---
84-
"agent-framework-azure-ai >= 1.0.0b251114",
84+
"agent-framework-azure-ai >= 1.0.0rc4",
8585
"langchain >= 0.1.0",
8686
"langchain-core >= 0.1.0",
8787
"openai-agents >= 0.2.6",
@@ -103,7 +103,7 @@ constraint-dependencies = [
103103
# --- Development & Testing ---
104104
"black >= 23.0.0",
105105
"mypy >= 1.0.0",
106-
"openai >= 1.0.0",
106+
"openai >= 2.0.0",
107107
"pytest >= 7.0.0",
108108
"pytest-asyncio >= 0.21.0",
109109
"pytest-cov>=7.0.0",

tests/observability/extensions/agentframework/integration/test_agentframework_trace_processor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# AgentFramework SDK
2020
try:
21-
from agent_framework import ChatAgent, ai_function
21+
from agent_framework import RawAgent, ai_function
2222
from agent_framework.azure import AzureOpenAIChatClient
2323
from agent_framework.observability import setup_observability
2424
from azure.identity import AzureCliCredential
@@ -80,8 +80,8 @@ def test_agentframework_trace_processor_integration(self, azure_openai_config, a
8080
)
8181

8282
# Create agent framework agent
83-
agent = ChatAgent(
84-
chat_client=chat_client,
83+
agent = RawAgent(
84+
client=chat_client,
8585
instructions="You are a helpful assistant.",
8686
tools=[],
8787
)
@@ -149,8 +149,8 @@ def test_agentframework_trace_processor_with_tool_calls(
149149
)
150150

151151
# Create agent framework agent
152-
agent = ChatAgent(
153-
chat_client=chat_client,
152+
agent = RawAgent(
153+
client=chat_client,
154154
instructions="You are a helpful agent framework assistant.",
155155
tools=[add_numbers],
156156
)

tests/tooling/extensions/agentframework/services/test_mcp_tool_registration_service.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def test_httpx_client_has_authorization_header(
9696
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.MCPStreamableHTTPTool"
9797
),
9898
patch(
99-
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.ChatAgent"
99+
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.RawAgent"
100100
),
101101
patch(
102102
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.Utility.resolve_agent_identity",
@@ -156,7 +156,7 @@ async def test_httpx_client_has_user_agent_header(
156156
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.MCPStreamableHTTPTool"
157157
),
158158
patch(
159-
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.ChatAgent"
159+
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.RawAgent"
160160
),
161161
patch(
162162
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.Utility.resolve_agent_identity",
@@ -214,7 +214,7 @@ async def test_httpx_client_has_correct_timeout(
214214
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.MCPStreamableHTTPTool"
215215
),
216216
patch(
217-
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.ChatAgent"
217+
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.RawAgent"
218218
),
219219
patch(
220220
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.Utility.resolve_agent_identity",
@@ -277,7 +277,7 @@ async def test_mcp_tool_receives_http_client_not_headers(
277277
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.MCPStreamableHTTPTool"
278278
) as mock_mcp_tool,
279279
patch(
280-
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.ChatAgent"
280+
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.RawAgent"
281281
),
282282
patch(
283283
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.Utility.resolve_agent_identity",
@@ -339,7 +339,7 @@ async def test_httpx_client_added_to_internal_list_for_cleanup(
339339
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.MCPStreamableHTTPTool"
340340
),
341341
patch(
342-
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.ChatAgent"
342+
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.RawAgent"
343343
),
344344
patch(
345345
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.Utility.resolve_agent_identity",
@@ -498,7 +498,7 @@ async def test_full_client_lifecycle_single_server(
498498
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.MCPStreamableHTTPTool"
499499
),
500500
patch(
501-
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.ChatAgent"
501+
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.RawAgent"
502502
),
503503
patch(
504504
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.Utility.resolve_agent_identity",
@@ -582,7 +582,7 @@ async def test_full_client_lifecycle_multiple_servers(
582582
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.MCPStreamableHTTPTool"
583583
),
584584
patch(
585-
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.ChatAgent"
585+
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.RawAgent"
586586
),
587587
patch(
588588
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.Utility.resolve_agent_identity",
@@ -678,7 +678,7 @@ async def test_cleanup_called_twice_after_creating_clients(
678678
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.MCPStreamableHTTPTool"
679679
),
680680
patch(
681-
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.ChatAgent"
681+
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.RawAgent"
682682
),
683683
patch(
684684
"microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_registration_service.Utility.resolve_agent_identity",

tests/tooling/extensions/agentframework/services/test_send_chat_history.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def sample_chat_messages(self, mock_role, mock_assistant_role):
6565

6666
@pytest.fixture
6767
def mock_chat_message_store(self, sample_chat_messages):
68-
"""Create a mock ChatMessageStoreProtocol."""
68+
"""Create a mock BaseHistoryProvider."""
6969
store = AsyncMock()
70-
store.list_messages = AsyncMock(return_value=sample_chat_messages)
70+
store.get_messages = AsyncMock(return_value=sample_chat_messages)
7171
return store
7272

7373
@pytest.fixture
@@ -238,7 +238,7 @@ async def test_send_chat_history_from_store_with_store_success(
238238

239239
# Assert
240240
assert result.succeeded is True
241-
mock_chat_message_store.list_messages.assert_called_once()
241+
mock_chat_message_store.get_messages.assert_called_once()
242242
service._mcp_server_configuration_service.send_chat_history.assert_called_once()
243243

244244
@pytest.mark.asyncio
@@ -260,7 +260,7 @@ async def test_send_chat_history_from_store_delegates_to_messages_async(
260260

261261
# Assert
262262
assert result.succeeded is True
263-
mock_chat_message_store.list_messages.assert_called_once()
263+
mock_chat_message_store.get_messages.assert_called_once()
264264
mock_messages_method.assert_called_once_with(
265265
chat_messages=sample_chat_messages,
266266
turn_context=mock_turn_context,
@@ -424,10 +424,10 @@ async def test_send_chat_history_messages_role_value_conversion(
424424
async def test_send_chat_history_from_store_propagates_store_exception(
425425
self, service, mock_turn_context
426426
):
427-
"""Test that exceptions from chat_message_store.list_messages() propagate (CRM-001)."""
427+
"""Test that exceptions from chat_message_store.get_messages() propagate (CRM-001)."""
428428
# Arrange
429429
mock_store = AsyncMock()
430-
mock_store.list_messages = AsyncMock(side_effect=RuntimeError("Store connection failed"))
430+
mock_store.get_messages = AsyncMock(side_effect=RuntimeError("Store connection failed"))
431431

432432
# Act & Assert
433433
with pytest.raises(RuntimeError, match="Store connection failed"):

0 commit comments

Comments
 (0)