跳到主要内容

基础聊天

最简单的用例——流式 AI 对话,自动滚动、停止按钮与键盘处理。用 AgentsKit 十行内搞定。

AgentsKit — BasicChat
Assistant
Hi! I'm your AI assistant. Ask me anything about streaming, React hooks, or how AgentsKit works under the hood.

配合 AgentsKit

import { useChat, ChatContainer, Message, InputBar } from '@agentskit/react'
import { anthropic } from '@agentskit/adapters'
import '@agentskit/react/theme'

function Chat() {
const chat = useChat({ adapter: anthropic({ apiKey: 'key', model: 'claude-sonnet-4-6' }) })
return (
<ChatContainer>
{chat.messages.map(msg => <Message key={msg.id} message={msg} />)}
<InputBar chat={chat} />
</ChatContainer>
)
}