Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Agent Framework and ChatKit Integration

This package provides an integration layer between Microsoft Agent Framework and OpenAI ChatKit (Python). Specifically, it mirrors the Agent 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

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:

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.

Metadata

Release files for agent-framework-chatkit 1.0.0b251108

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-framework-chatkit 1.0.0b251108
File Size Uploaded
agent_framework_chatkit-1.0.0b251108.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-framework-chatkit 1.0.0b251108
File Interpreter ABI Platform
agent_framework_chatkit-1.0.0b251108-py3-none-any.whl Python 3 none any Details

Total release size: 24.6 kB

Release files / agent_framework_chatkit-1.0.0b251108.tar.gz

Download URL agent_framework_chatkit-1.0.0b251108.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d53b6403b439e423a3b0baf357c703d8af005ea4891d5b19d0ea3cb40a2c3113
BLAKE2b-256 checksum
How to use checksums
1f5ad1be8564498c41585d541986ea6406fa42e394a702f54f5e27bfb942d89b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.24

Release files / agent_framework_chatkit-1.0.0b251108-py3-none-any.whl

Download URL agent_framework_chatkit-1.0.0b251108-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cfc6a1f74e2660d0cc333ffb1a92e2e747259419ecd5a7c825aa32712d8b2416
BLAKE2b-256 checksum
How to use checksums
e4bc1f7621ad8057ef2d0e1bbfb479d7cde231029f6d04a34ad7c22757d02c0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.24

Release history Release notifications | RSS feed

This release

1.0.0b251108 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page