Skip to content

Commit ff498b4

Browse files
authored
Python: Updates (#11371)
### Motivation and Context Some code cleanup. <!-- 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 Some code cleanup. <!-- 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 ba01297 commit ff498b4

File tree

10 files changed

+42
-56
lines changed

10 files changed

+42
-56
lines changed

.github/workflows/generate-pr-description.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
id: comment-branch
1818

1919
- name: Set latest commit status as pending
20-
uses: myrotvorets/set-commit-status-action@master
20+
uses: myrotvorets/set-commit-status-action@v2.0.1
2121
with:
2222
sha: ${{ steps.comment-branch.outputs.head_sha }}
2323
token: ${{ secrets.GITHUB_TOKEN }}
@@ -36,7 +36,7 @@ jobs:
3636
AZURE_OPENAI_API_KEY: ${{ secrets.AZUREOPENAI__APIKEY }}
3737

3838
- name: Set latest commit status as ${{ job.status }}
39-
uses: myrotvorets/set-commit-status-action@master
39+
uses: myrotvorets/set-commit-status-action@v2.0.1
4040
if: always()
4141
with:
4242
sha: ${{ steps.comment-branch.outputs.head_sha }}

.github/workflows/python-integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ jobs:
533533
script: core.setFailed('Integration Tests Cancelled!')
534534

535535
- name: Microsoft Teams Notification
536-
uses: skitionek/notify-microsoft-teams@master
536+
uses: skitionek/notify-microsoft-teams@v1.0.8
537537
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
538538
with:
539539
webhook_url: ${{ secrets.MSTEAMS_WEBHOOK }}
@@ -543,7 +543,7 @@ jobs:
543543
title: "{title: ` ${{ env.run_type }}: ${{ env.date }} `, text: ` ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`}"
544544

545545
- name: Microsoft Teams Notification (Dry Run)
546-
uses: skitionek/notify-microsoft-teams@master
546+
uses: skitionek/notify-microsoft-teams@v1.0.8
547547
if: github.ref != 'refs/heads/main'
548548
with:
549549
webhook_url: NONE

.github/workflows/python-test-coverage-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
4040
- name: Pytest coverage comment
4141
id: coverageComment
42-
uses: MishaKav/pytest-coverage-comment@main
42+
uses: MishaKav/pytest-coverage-comment@v1.1.53
4343
with:
4444
github-token: ${{ secrets.GH_ACTIONS_PR_WRITE }}
4545
issue-number: ${{ env.PR_NUMBER }}

.github/workflows/python-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: uv run --frozen pytest --junitxml=pytest.xml ./tests/unit
4949
- name: Surface failing tests
5050
if: ${{ !matrix.experimental }}
51-
uses: pmeier/pytest-results-action@main
51+
uses: pmeier/pytest-results-action@v0.7.1
5252
with:
5353
path: python/pytest.xml
5454
summary: true

.github/workflows/typos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
persist-credentials: false
2626

2727
- name: Use custom config file
28-
uses: crate-ci/typos@master
28+
uses: crate-ci/typos@v1.31.1
2929
with:
3030
config: .github/_typos.toml
3131
write_changes: false

python/pip/README.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "semantic-kernel"
33
description = "Semantic Kernel Python SDK"
44
authors = [{ name = "Microsoft", email = "SK-Support@microsoft.com"}]
5-
readme = "pip/README.md"
5+
readme = "README.md"
66
# Version read from __version__ field in __init__.py by Flit
77
dynamic = ["version"]
88
requires-python = ">=3.10"

python/semantic_kernel/agents/autogen/autogen_conversable_agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async def invoke(
179179
cache: "AbstractCache | None" = None,
180180
max_turns: int | None = None,
181181
summary_method: str | Callable | None = ConversableAgent.DEFAULT_SUMMARY_METHOD,
182-
summary_args: dict | None = {},
182+
summary_args: dict | None = None,
183183
**kwargs: Any,
184184
) -> AsyncIterable[AgentResponseItem[ChatMessageContent]]:
185185
"""A direct `invoke` method for the ConversableAgent.
@@ -210,6 +210,9 @@ async def invoke(
210210
)
211211
assert thread.id is not None # nosec
212212

213+
if summary_args is None:
214+
summary_args = {}
215+
213216
if recipient is not None:
214217
if not isinstance(recipient, AutoGenConversableAgent):
215218
raise AgentInvokeException(

python/semantic_kernel/agents/azure_ai/agent_content_generation.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,23 @@ def get_function_call_contents(
207207
"""
208208
function_call_contents: list[FunctionCallContent] = []
209209
required_action = getattr(run, "required_action", None)
210-
if not required_action or not getattr(required_action, "submit_tool_outputs", False):
210+
submit_tool_outputs = getattr(required_action, "submit_tool_outputs", None)
211+
if not submit_tool_outputs or not hasattr(submit_tool_outputs, "tool_calls"):
211212
return function_call_contents
212-
for tool_call in required_action.submit_tool_outputs.tool_calls:
213-
tool: RunStepFunctionToolCall = tool_call
213+
tool_calls = getattr(submit_tool_outputs, "tool_calls", [])
214+
if not isinstance(tool_calls, (list, tuple)):
215+
return function_call_contents
216+
for tool_call in tool_calls:
217+
if not isinstance(tool_call, RunStepFunctionToolCall):
218+
continue
214219
fcc = FunctionCallContent(
215-
id=tool.id,
216-
index=getattr(tool, "index", None),
217-
name=tool.function.name,
218-
arguments=tool.function.arguments,
220+
id=tool_call.id,
221+
index=getattr(tool_call, "index", None),
222+
name=tool_call.function.name,
223+
arguments=tool_call.function.arguments,
219224
)
220225
function_call_contents.append(fcc)
221-
function_steps[tool.id] = fcc
226+
function_steps[tool_call.id] = fcc
222227
return function_call_contents
223228

224229

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) Microsoft. All rights reserved.
22

33

4+
from unittest.mock import MagicMock
5+
46
from azure.ai.projects.models import (
57
MessageDelta,
68
MessageDeltaChunk,
@@ -28,6 +30,7 @@
2830
RunStepDeltaFunction,
2931
RunStepDeltaFunctionToolCall,
3032
RunStepDeltaToolCallObject,
33+
RunStepFunctionToolCall,
3134
ThreadMessage,
3235
)
3336

@@ -256,27 +259,24 @@ def test_get_function_call_contents_no_action():
256259

257260

258261
def test_get_function_call_contents_submit_tool_outputs():
259-
class FakeFunction:
260-
name = "test_function"
261-
arguments = {"arg": "val"}
262+
fake_function = MagicMock()
263+
fake_function.name = "test_function"
264+
fake_function.arguments = {"arg": "val"}
265+
266+
fake_tool_call = MagicMock(spec=RunStepFunctionToolCall)
267+
fake_tool_call.id = "tool_id"
268+
fake_tool_call.function = fake_function
269+
270+
run = MagicMock()
271+
run.required_action.submit_tool_outputs.tool_calls = [fake_tool_call]
262272

263-
class FakeToolCall:
264-
id = "tool_id"
265-
function = FakeFunction()
266-
267-
run = type(
268-
"ThreadRunFake",
269-
(),
270-
{
271-
"required_action": type(
272-
"RequiredAction", (), {"submit_tool_outputs": type("FakeSubmit", (), {"tool_calls": [FakeToolCall()]})}
273-
)
274-
},
275-
)()
276273
function_steps = {}
277274
fc = get_function_call_contents(run, function_steps)
275+
278276
assert len(fc) == 1
279-
assert function_steps["tool_id"].function_name == "test_function"
277+
assert fc[0].id == "tool_id"
278+
assert fc[0].name == "test_function"
279+
assert fc[0].arguments == {"arg": "val"}
280280

281281

282282
def test_generate_function_call_content():

0 commit comments

Comments
 (0)