Skip to content

Commit 89ef228

Browse files
authored
Python: Per deprecation message and date remove add_chat_message from AzureAIAgent and OpenAIAssistantAgent (#11827)
### Motivation and Context Per the deprecation message on the method `add_chat_message(...)` currently on the `AzureAIAgent` and `OpenAIAssistantAgent` classes, we are removing the method in favor of passing in any messages directly to the `get_response(...)`, `invoke(...)` or `invoke_stream(...)`. The underlying thread abstraction handles adding the messages to the thread as part of invocation. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description Remove the methods per the deprecation message and date. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄
1 parent 97c2524 commit 89ef228

File tree

5 files changed

+0
-89
lines changed

5 files changed

+0
-89
lines changed

python/semantic_kernel/agents/azure_ai/azure_ai_agent.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from collections.abc import AsyncIterable, Awaitable, Callable, Iterable
66
from typing import TYPE_CHECKING, Any, ClassVar, Literal, TypeVar
77

8-
from typing_extensions import deprecated
9-
108
if sys.version_info >= (3, 12):
119
from typing import override # pragma: no cover
1210
else:
@@ -18,7 +16,6 @@
1816
AgentsApiResponseFormat,
1917
AgentsApiResponseFormatMode,
2018
ResponseFormatJsonSchemaType,
21-
ThreadMessage,
2219
ThreadMessageOptions,
2320
ToolDefinition,
2421
TruncationObject,
@@ -613,18 +610,3 @@ async def create_channel(self, thread_id: str | None = None) -> AgentChannel:
613610
assert thread.id is not None # nosec
614611

615612
return AzureAIChannel(client=self.client, thread_id=thread.id)
616-
617-
@deprecated(
618-
"Pass messages directly to get_response(...)/invoke(...) instead. This method will be removed after May 1st 2025." # noqa: E501
619-
)
620-
async def add_chat_message(self, thread_id: str, message: str | ChatMessageContent) -> "ThreadMessage | None":
621-
"""Add a chat message to the thread.
622-
623-
Args:
624-
thread_id: The ID of the thread
625-
message: The chat message to add
626-
627-
Returns:
628-
ThreadMessage | None: The thread message
629-
"""
630-
return await AgentThreadActions.create_message(client=self.client, thread_id=thread_id, message=message)

python/semantic_kernel/agents/open_ai/open_ai_assistant_agent.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from copy import copy
77
from typing import TYPE_CHECKING, Any, ClassVar, Literal
88

9-
from typing_extensions import deprecated
10-
119
from semantic_kernel.utils.feature_stage_decorator import release_candidate
1210

1311
if sys.version_info >= (3, 12):
@@ -59,7 +57,6 @@
5957
from openai.types.beta.assistant_tool_param import AssistantToolParam
6058
from openai.types.beta.code_interpreter_tool_param import CodeInterpreterToolParam
6159
from openai.types.beta.thread_create_params import Message as ThreadCreateMessage
62-
from openai.types.beta.threads.message import Message
6360
from openai.types.beta.threads.run_create_params import TruncationStrategy
6461

6562
from semantic_kernel.kernel import Kernel
@@ -440,30 +437,6 @@ async def create_channel(self, thread_id: str | None = None) -> AgentChannel:
440437

441438
# endregion
442439

443-
# region Message Handling
444-
445-
@deprecated(
446-
"Pass messages directly to get_response(...)/invoke(...) instead. This method will be removed after May 1st 2025." # noqa: E501
447-
)
448-
async def add_chat_message(
449-
self, thread_id: str, message: "str | ChatMessageContent", **kwargs: Any
450-
) -> "Message | None":
451-
"""Add a chat message to the thread.
452-
453-
Args:
454-
thread_id: The ID of the thread
455-
message: The chat message to add
456-
kwargs: Additional keyword arguments
457-
458-
Returns:
459-
The thread message or None
460-
"""
461-
return await AssistantThreadActions.create_message(
462-
client=self.client, thread_id=thread_id, message=message, **kwargs
463-
)
464-
465-
# endregion
466-
467440
# region Invocation Methods
468441

469442
@trace_agent_get_response

python/tests/unit/agents/azure_ai_agent/test_azure_ai_agent.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ async def test_azure_ai_agent_init_with_plugins_via_constructor(
3333
assert len(agent.kernel.plugins) == 1
3434

3535

36-
async def test_azure_ai_agent_add_chat_message(ai_project_client, ai_agent_definition):
37-
agent = AzureAIAgent(client=ai_project_client, definition=ai_agent_definition)
38-
with patch(
39-
"semantic_kernel.agents.azure_ai.agent_thread_actions.AgentThreadActions.create_message",
40-
):
41-
await agent.add_chat_message("threadId", ChatMessageContent(role="user", content="text")) # pass anything
42-
43-
4436
async def test_azure_ai_agent_get_response(ai_project_client, ai_agent_definition):
4537
agent = AzureAIAgent(client=ai_project_client, definition=ai_agent_definition)
4638

python/tests/unit/agents/openai_assistant/test_azure_assistant_agent.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,6 @@ def test_configure_response_format_invalid_input_type():
175175
assert "response_format must be a dictionary" in str(exc_info.value)
176176

177177

178-
@pytest.mark.parametrize(
179-
"message",
180-
[
181-
pytest.param(ChatMessageContent(role=AuthorRole.USER, content="text")),
182-
pytest.param("text"),
183-
],
184-
)
185-
async def test_open_ai_assistant_agent_add_chat_message(message):
186-
client = AsyncMock(spec=AsyncOpenAI)
187-
definition = AsyncMock(spec=Assistant)
188-
definition.id = "agent123"
189-
definition.name = "agentName"
190-
definition.description = "desc"
191-
definition.instructions = "test agent"
192-
agent = AzureAssistantAgent(client=client, definition=definition)
193-
with patch(
194-
"semantic_kernel.agents.open_ai.assistant_thread_actions.AssistantThreadActions.create_message",
195-
):
196-
await agent.add_chat_message("threadId", message)
197-
198-
199178
@pytest.mark.parametrize(
200179
"arguments, include_args",
201180
[

python/tests/unit/agents/openai_assistant/test_openai_assistant_agent.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,6 @@ def test_configure_response_format_invalid_input_type():
115115
assert "response_format must be a dictionary" in str(exc_info.value)
116116

117117

118-
@pytest.mark.parametrize(
119-
"message",
120-
[
121-
pytest.param(ChatMessageContent(role=AuthorRole.USER, content="text")),
122-
pytest.param("text"),
123-
],
124-
)
125-
async def test_open_ai_assistant_agent_add_chat_message(message, openai_client, assistant_definition):
126-
agent = OpenAIAssistantAgent(client=openai_client, definition=assistant_definition)
127-
with patch(
128-
"semantic_kernel.agents.open_ai.assistant_thread_actions.AssistantThreadActions.create_message",
129-
):
130-
await agent.add_chat_message("threadId", message)
131-
132-
133118
@pytest.mark.parametrize(
134119
"arguments, include_args",
135120
[

0 commit comments

Comments
 (0)