Draft: OpenAI chatkit support #3198
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3098
Heyy @DouweM, Hope ur're doing well
I have started working on the integrating of OpenAI's ChatKit framework with Pydantic AI.
ChatKit operates differently from other UI protocols in several key ways:
Unlike simple request-response patterns, ChatKit works with persistent threads where each conversation is considered a sequence of different thread items (user messages, assistant messages, tool calls, widgets, etc.).
It supports advanced UI elements beyond text:
It also already provides comprehensive TypeScript definitions on the frontend and Python types in their official library, which I'm leveraging for type safety.
I've started implementing the adapter by importing types directly from the official
chatkitPython library:The core adapter structure follows Pydantic AI's
BaseAdapterpattern but with ChatKit-specific considerations:ModelMessageformat (currently in progress)Before continuing the implementation, I have some questions about the desired scope and approach:
1. Session Management Responsibility
Since we're making Pydantic AI agents ChatKit-protocol compatible, who should handle session management?
Option A: Full ChatKit Backend Implementation
ChatKitServerOption B: Adapter-Only Approach
2. Memory Store Integration
ChatKit's server implementation includes a
MemoryStoreinterface for persisting conversations. Should we:Option A: Provide ChatKit-Compatible Memory Store
Option B: Custom State Management
3. Protocol Compatibility Level
How closely should we follow ChatKit's backend implementation?
I would greatly appreciate your advice on the best path forward and on which specific ChatKit features or behaviors we should prioritize
Thanks in advance ^^!