Skip to content

Python: Add thread_id to assistant message to avoid duplication #11221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2025

Conversation

moonbox3
Copy link
Contributor

Motivation and Context

The current OpenAI assistant get_response and invoke methods don't add the current thread_id to the CMC's metadata, therefore during a thread.on_new_message(...) call, the assistant's message will get added again.

Description

Add the thread_id to the metadata so we don't add the assistant's response again.

Todo: add agent integration tests and check messages so we have coverage for this.

Contribution Checklist

@moonbox3 moonbox3 requested a review from a team as a code owner March 26, 2025 22:02
@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label Mar 26, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 26, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel/agents/open_ai
   assistant_thread_actions.py3365683%107, 110, 113, 189, 191, 228–234, 405, 463, 480, 572–600, 614–623, 659–673, 685–686, 757, 762, 794
   open_ai_assistant_agent.py2302788%93, 110–111, 119–124, 131–141, 152–158, 315, 328, 364, 527, 631, 731
TOTAL21235246888% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3336 5 💤 0 ❌ 0 🔥 1m 47s ⏱️

@moonbox3 moonbox3 added this pull request to the merge queue Mar 27, 2025
Merged via the queue into microsoft:main with commit a72be1f Mar 27, 2025
28 checks passed
@moonbox3 moonbox3 deleted the assistant-agent-thread-fix branch March 27, 2025 00:12
glorious-beard pushed a commit to glorious-beard/semantic-kernel that referenced this pull request Apr 6, 2025
…osoft#11221)

### Motivation and Context

The current OpenAI assistant get_response and invoke methods don't add
the current thread_id to the CMC's metadata, therefore during a
`thread.on_new_message(...)` call, the assistant's message will get
added again.

<!-- 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

Add the `thread_id` to the metadata so we don't add the assistant's
response again.

**Todo**: add agent integration tests and check messages so we have
coverage for this.

<!-- 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 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants