Skip to content

Python: Fix chat_response_cancellation sample to use Message objects#4532

Open
giles17 wants to merge 1 commit intomicrosoft:mainfrom
giles17:fix/chat-response-cancellation-message-type
Open

Python: Fix chat_response_cancellation sample to use Message objects#4532
giles17 wants to merge 1 commit intomicrosoft:mainfrom
giles17:fix/chat-response-cancellation-message-type

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Mar 6, 2026

The chat_response_cancellation.py sample was passing raw strings in a list to get_response(), which expects Message objects. This caused an AttributeError: 'str' object has no attribute 'role'.

Fix: Import Message from agent_framework and wrap the user prompt in Message(role="user", text="...").

Fixes #4491

The sample was passing raw strings in a list to get_response(), which
expects Message objects. This caused an AttributeError since strings
don't have a 'role' attribute.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 6, 2026 19:24
@github-actions github-actions bot changed the title Fix chat_response_cancellation sample to use Message objects Python: Fix chat_response_cancellation sample to use Message objects Mar 6, 2026
@giles17 giles17 enabled auto-merge March 6, 2026 19:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a runtime error in the chat_response_cancellation.py sample where a raw string was being passed in a list to client.get_response(messages=...), which expects Sequence[Message]. This caused an AttributeError: 'str' object has no attribute 'role' because the downstream code tries to access .role on each element.

Changes:

  • Import Message from agent_framework and wrap the user prompt string in a Message(role="user", text="...") object before passing it to get_response().

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Sample not working

3 participants