
Description
Use when connecting AI SDK for Python streams to AI SDK UI useChat clients.
SKILL.md
ai-python-ui-adapter
Frontend:
const chat = useChat({
transport: new DefaultChatTransport({ api: "/api/chat" }),
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
});
Use chat.sendMessage(...) to send user input. Use
chat.addToolApprovalResponse(...) from approval buttons.
Backend request:
class ChatRequest(pydantic.BaseModel):
messages: list[ai.ui.ai_sdk.UIMessage]
messages, approvals = ai.ui.ai_sdk.to_messages(request.messages)
ai.ui.ai_sdk.apply_approvals(approvals)
Backend stream:
async def body():
async with agent.run(model, messages) as stream:
async def events():
async for event in stream:
if (
isinstance(event, ai.events.HookEvent)
and event.hook.status == "pending"
):
ai.defer_hook(event.hook)
yield event
async for chunk in ai.ui.ai_sdk.to_sse(events()):
yield chunk
return StreamingResponse(
body(),
headers=ai.ui.ai_sdk.UI_MESSAGE_STREAM_HEADERS,
)
The adapter handles UIMessage parsing, message IDs, tool state, approvals,
subagent MessageBundle values, and AI SDK UI stream events.
You handle the HTTP route, auth, storage, session lookup, frontend rendering, and when to defer hooks.
For saved UI history, use:
ui_messages = ai.ui.ai_sdk.to_ui_messages(messages)
More skills from the ai-python repository
View all 9 skillsai-python-basics
build AI agents with Python SDK
Jul 29AgentsAI SDKLLMPythonai-python-custom-loop
build custom agent loops in Python
Jul 29AgentsAI SDKPythonai-python-custom-provider
implement custom AI SDK providers
Jul 29AI SDKPythonai-python-durable-execution
add durable execution to AI agents
Jul 29AgentsAI SDKPythonai-python-serverless-execution
build serverless AI SDK endpoints
Jul 29AI SDKPythonServerlessai-python-streaming-tools
stream AI SDK Python tool outputs
Jul 29AgentsAI SDKPython
More from Vercel Labs
View publisheragent-browser
automate browser interactions for AI agents
agent-browser
Jul 20AgentsAutomationBrowser Automationagentcore
run browser automation on AWS Bedrock
agent-browser
Jul 17AutomationAWSBrowser Automationcore
navigate and interact with web pages
agent-browser
Jul 26AgentsBrowser AutomationNavigationderive-client
reverse engineer internal APIs from browser traffic
agent-browser
Jul 20API DevelopmentAutomationBrowser AutomationWeb Scrapingdogfood
perform exploratory testing on web applications
agent-browser
Jul 17Browser AutomationDebuggingQATestingelectron
automate Electron desktop applications
agent-browser
Jul 17AgentsBrowser AutomationDesktop