Skip to main content

Unified useChat Hook

The useGroupChat hook is deprecated. All chat functionality is now handled by the unified useChat hook from @baleybots/react.

What changed

Previously, useChat handled single-agent client-side chat, and useGroupChat handled multi-agent server-side chat. Now useChat supports both modes:

  • Client mode (default) -- runs the agent locally, same as before
  • Server mode -- activated by setting apiUrl, replaces useGroupChat

Migration

Basic server-mode chat

// Before
import { useGroupChat } from '@baleybots/react';

const { messages, sendMessage } = useGroupChat({
apiUrl: 'https://your-api.com/chat',
chatId: 'conversation-123',
});

// After
import { useChat } from '@baleybots/react';

const { segments, sendStreaming } = useChat({
apiUrl: 'https://your-api.com/chat',
chatId: 'conversation-123',
});

Multi-agent status tracking

If you relied on agent status from useGroupChat, enable multiAgent:

const { segments, agents, sendStreaming } = useChat({
apiUrl: 'https://your-api.com/chat',
chatId: 'conversation-123',
multiAgent: true,
});

// agents: AgentStatus[] with { agentId, agentName, status }

Mentions

Pass mentions through the sendStreaming options:

// Before
sendMessage('Hello @agent-1', { mentions: ['agent-1'] });

// After
sendStreaming('Hello @agent-1', { mentions: ['agent-1'] });

Key differences

useGroupChat (deprecated)useChat (unified)
messages (UIChatMessage[])segments (StreamSegment[])
sendMessagesendStreaming or send
Always server modeClient or server mode (based on apiUrl)
Agent status built-inOpt-in with multiAgent: true

Rendering segments

If you were rendering messages, switch to segments:

// Before
{messages.map(msg => (
<div key={msg.id}>
<b>{msg.role}:</b> {msg.content}
</div>
))}

// After
{segments.map(segment => {
if (segment.type === 'user') {
return <div key={segment.id}><b>You:</b> {segment.content}</div>;
}
if (segment.type === 'text') {
return <div key={segment.id}><b>Assistant:</b> {segment.content}</div>;
}
return null;
})}