Skip to content

Python: Fix ChatKit integration sample startup and weather widgets - #9579

Draft
Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
microsoft:mainfrom
1aifanatic:contrib/python-chatkit-sample-function-results
Draft

Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
microsoft:mainfrom
1aifanatic:contrib/python-chatkit-sample-function-results

Conversation

@1aifanatic

@1aifanatic Naveen Chatlapalli (1aifanatic) commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

The ChatKit end-to-end sample (python/samples/05-end-to-end/chatkit-integration/app.py) has drifted from the current core API (details and reproduction in #9578):

  1. It imports the removed FunctionResultContent, so app.py fails with ImportError at startup.
  2. It returned a WeatherResponse(str) subclass so WeatherData would ride along on content.result. Tool results are now normalized to list[Content], so that attribute is always lost and the weather widget never renders.
  3. Role.USER no longer exists (Role is a NewType), which breaks title generation and the city_selected action.

Description & Review Guide

  • What are the major changes?
    • get_weather takes a FunctionInvocationContext and appends its WeatherData to a request-scoped weather_results list read from ctx.kwargs. respond() and action() pass that list via function_invocation_kwargs, the pattern from samples/02-agents/tools/function_tool_with_kwargs.py. The structured data never reaches the model, and the per-request list keeps concurrent requests isolated.
    • Remove the WeatherResponse subclass and the FunctionResultContent imports. Detect the city selector marker with content.type == "function_result".
    • Replace Role.USER with "user".
    • action() no longer needs an intercepting stream, so it passes the agent stream straight to stream_agent_response.
  • What is the impact of these changes? Sample only. The app imports again, and the weather and city-selector widgets render as the README describes.
  • What do you want reviewers to focus on? Whether passing a request-scoped collector via function_invocation_kwargs is the pattern you want this sample to teach for tool-to-UI side data. An alternative is returning a JSON string and parsing it, which would expose structured data to the model.

Verified locally by driving respond() and action() with a scripted chat client (the core tests' MockBaseChatClient, so tools run through the real function-invocation layer):

Flow main This PR
import app.py ImportError: FunctionResultContent ok
respond() → get_weather — weather widget emitted
respond() → show_city_selector — selector widget emitted
action(city_selected) → get_weather — weather widget emitted

Pyright on app.py goes from 4 errors to 0. ruff format --check passes. ruff check reports the same two pre-existing E501 lines as main (a long NOTE comment and a # fmt: skip line), neither of which this PR touches.

Related Issue

Fixes #9578

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Claude Code helped find the breakages, implement the fix, build the scripted-client verification harness, and draft this description and the linked issue.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

🤖 Generated with Claude Code

The sample imported the removed FunctionResultContent type, so app.py
failed with ImportError at startup. It also relied on a str subclass
(WeatherResponse) surviving as the function result to carry WeatherData
to the widget renderer, but tool results are now normalized to
list[Content], so the weather widget could never render, and
Role.USER no longer exists, which broke title generation and the city
selector action.

Pass a request-scoped weather_results list to get_weather through
function_invocation_kwargs (read from FunctionInvocationContext.kwargs,
never exposed to the model), detect the city selector marker via
content.type, and use role="user".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused sample fixes align with current invocation and streaming contracts, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Updates the Python ChatKit sample to current Agent Framework APIs, restoring startup and weather widgets for #9578.

Changes:

  • Passes weather widget data through a request-scoped tool invocation collector.
  • Replaces removed imports and role constants with current APIs.
  • Updates city-selector detection and simplifies action streaming.
File Description
python/​samples/​05-end-to-end/​chatkit-integration/​app.py Fixes API compatibility and weather widget data handling.

Review effort: Balanced

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Oct 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The sample is updated consistently with the current function-result, role, and invocation-context APIs. The request-scoped weather_results collector keeps widget data isolated from the model and from concurrent requests.

This branch was successfully deployed

1 active deployment
github-app-auth — a2f0a849 Deployed Oct 21, 2026 by 1aifanatic via add_label #25861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: ChatKit integration sample fails at startup and never renders weather widgets

3 participants