Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
78da4ce
feat: Add ChatKit integration with a new frontend application
ekzhu Oct 7, 2025
2c95252
Merge branch 'main' into chatkit
ekzhu Oct 7, 2025
43a5b29
git ignore
ekzhu Oct 7, 2025
06d38b3
fix mypy
ekzhu Oct 7, 2025
e8bbb73
Merge branch 'main' into chatkit
ekzhu Oct 9, 2025
a869e33
add mising file
ekzhu Oct 9, 2025
6d76540
Merge branch 'main' into chatkit
ekzhu Oct 9, 2025
d0781cb
minimal frontend for chatkit sample
ekzhu Oct 9, 2025
5587b2d
update ignore files
ekzhu Oct 9, 2025
c68f1b2
Merge branch 'main' into chatkit
ekzhu Oct 9, 2025
4c81a49
Merge branch 'main' into chatkit
ekzhu Oct 13, 2025
b4d7e10
version
ekzhu Oct 15, 2025
f97d1dd
Merge branch 'main' into chatkit
ekzhu Oct 15, 2025
c0d602c
merge
ekzhu Oct 17, 2025
b76df00
set python version lowerbound on chatkit
ekzhu Oct 17, 2025
9651987
update project settings for chatkit
ekzhu Oct 17, 2025
32fb89c
update setup
ekzhu Oct 17, 2025
02fb969
update setup
ekzhu Oct 17, 2025
414eee5
update setup
ekzhu Oct 17, 2025
0f5c525
Merge branch 'main' into chatkit
ekzhu Oct 17, 2025
f8cc62c
update setup
ekzhu Oct 17, 2025
0e35290
Merge branch 'main' into chatkit
ekzhu Oct 21, 2025
671200f
weather widget
ekzhu Oct 21, 2025
aafac95
add select city widget sample
ekzhu Oct 21, 2025
a02235d
Merge branch 'main' into chatkit
ekzhu Oct 23, 2025
cfa5bdf
remove widget helper
ekzhu Oct 23, 2025
a565232
update chatkit to include file attachments and cover more thread item…
ekzhu Oct 23, 2025
f10c390
Merge branch 'main' into chatkit
ekzhu Oct 23, 2025
804f92a
update readme with mermaid diagram
ekzhu Oct 23, 2025
b87b60c
update diagram
ekzhu Oct 23, 2025
326583d
update instructions
ekzhu Nov 4, 2025
fd9d902
merge
ekzhu Nov 4, 2025
1ad75bb
update chatkit dependency
ekzhu Nov 4, 2025
c54f2a6
fix converter imports
ekzhu Nov 4, 2025
9526c51
move to demos/
ekzhu Nov 4, 2025
984a617
move to demos/ -- rename references
ekzhu Nov 4, 2025
13a70dc
Merge branch 'main' into chatkit
ekzhu Nov 4, 2025
478ee62
support multiple session instead of using global variable in sample
ekzhu Nov 4, 2025
d06a776
support chunk streaming
ekzhu Nov 4, 2025
0cf7cc9
fix tests
ekzhu Nov 4, 2025
e2f6b89
Update python/samples/demos/chatkit-integration/store.py
ekzhu Nov 5, 2025
8961cde
use local host
ekzhu Nov 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,12 @@ agents.md

# AI
.claude/
WARP.md
WARP.md

# Frontend
**/frontend/node_modules/
**/frontend/.vite/
**/frontend/dist/

# Database files
*.db
2 changes: 1 addition & 1 deletion python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: check-json
name: Check JSON files
files: \.json$
exclude: ^.*\.vscode\/.*
exclude: ^.*\.vscode\/.*|^python/demos/samples/chatkit-integration/frontend/(tsconfig.*\.json|package-lock\.json)$
- id: end-of-file-fixer
name: Fix End of File
files: \.py$
Expand Down
3 changes: 3 additions & 0 deletions python/packages/chatkit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chatkit-python
openai-chatkit-advanced-samples
chatkit-js
21 changes: 21 additions & 0 deletions python/packages/chatkit/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
87 changes: 87 additions & 0 deletions python/packages/chatkit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Agent Framework and ChatKit Integration

This package provides an integration layer between Microsoft Agent Framework
and [OpenAI ChatKit (Python)](https://github.com/openai/chatkit-python/).
Specifically, it mirrors the [Agent SDK integration](https://github.com/openai/chatkit-python/blob/main/docs/server.md#agents-sdk-integration), and provides the following helpers:

- `stream_agent_response`: A helper to convert a streamed `AgentRunResponseUpdate`
from a Microsoft Agent Framework agent that implements `AgentProtocol` to ChatKit events.
- `ThreadItemConverter`: A extendable helper class to convert ChatKit thread items to
`ChatMessage` objects that can be consumed by an Agent Framework agent.
- `simple_to_agent_input`: A helper function that uses the default implementation
of `ThreadItemConverter` to convert a ChatKit thread to a list of `ChatMessage`,
useful for getting started quickly.

## Installation

```bash
pip install agent-framework-chatkit --pre
```

This will install `agent-framework-core` and `openai-chatkit` as dependencies.

## Example Usage

Here's a minimal example showing how to integrate Agent Framework with ChatKit:

```python
from collections.abc import AsyncIterator
from typing import Any

from azure.identity import AzureCliCredential
from fastapi import FastAPI, Request
from fastapi.responses import Response, StreamingResponse

from agent_framework import ChatAgent
from agent_framework.azure import AzureOpenAIChatClient
from agent_framework.chatkit import simple_to_agent_input, stream_agent_response

from chatkit.server import ChatKitServer
from chatkit.types import ThreadMetadata, UserMessageItem, ThreadStreamEvent

# You'll need to implement a Store - see the sample for a SQLiteStore implementation
from your_store import YourStore # type: ignore[import-not-found] # Replace with your Store implementation

# Define your agent with tools
agent = ChatAgent(
chat_client=AzureOpenAIChatClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
tools=[], # Add your tools here
)

# Create a ChatKit server that uses your agent
class MyChatKitServer(ChatKitServer[dict[str, Any]]):
async def respond(
self,
thread: ThreadMetadata,
input_user_message: UserMessageItem | None,
context: dict[str, Any],
) -> AsyncIterator[ThreadStreamEvent]:
if input_user_message is None:
return

# Convert ChatKit message to Agent Framework format
agent_messages = await simple_to_agent_input(input_user_message)

# Run the agent and stream responses
response_stream = agent.run_stream(agent_messages)

# Convert agent responses back to ChatKit events
async for event in stream_agent_response(response_stream, thread.id):
yield event

# Set up FastAPI endpoint
app = FastAPI()
chatkit_server = MyChatKitServer(YourStore()) # type: ignore[misc]

@app.post("/chatkit")
async def chatkit_endpoint(request: Request):
result = await chatkit_server.process(await request.body(), {"request": request})

if hasattr(result, '__aiter__'): # Streaming
return StreamingResponse(result, media_type="text/event-stream") # type: ignore[arg-type]
else: # Non-streaming
return Response(content=result.json, media_type="application/json") # type: ignore[union-attr]
```

For a complete end-to-end example with a full frontend, see the [weather agent sample](../../samples/demos/chatkit-integration/README.md).
25 changes: 25 additions & 0 deletions python/packages/chatkit/agent_framework_chatkit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) Microsoft. All rights reserved.

"""Agent Framework and ChatKit Integration.

This package provides an integration layer between Microsoft Agent Framework
and OpenAI ChatKit (Python). It mirrors the Agent SDK integration and provides
helpers to convert between Agent Framework and ChatKit types.
"""

import importlib.metadata

from ._converter import ThreadItemConverter, simple_to_agent_input
from ._streaming import stream_agent_response

try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0" # Fallback for development mode

__all__ = [
"ThreadItemConverter",
"__version__",
"simple_to_agent_input",
"stream_agent_response",
]
Loading