Fix chat_response_cancellation sample to use Message objects (#4532)

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>
This commit is contained in:
Giles Odigwe
2026-03-09 16:59:41 -07:00
committed by GitHub
Unverified
parent 6cb2289a16
commit e2f0bc814e
@@ -2,6 +2,7 @@
import asyncio
from agent_framework import Message
from agent_framework.openai import OpenAIChatClient
from dotenv import load_dotenv
@@ -28,7 +29,7 @@ async def main() -> None:
client = OpenAIChatClient()
try:
task = asyncio.create_task(client.get_response(messages=["Tell me a fantasy story."]))
task = asyncio.create_task(client.get_response(messages=[Message(role="user", text="Tell me a fantasy story.")]))
await asyncio.sleep(1)
task.cancel()
await task