跳到主要内容

Group Chats API

/api/group-chats - Group chat management endpoints

Overview

The Group Chats API provides multi-agent collaborative chat functionality, supporting multiple agents working together in the same session. It uses a file-based storage system and supports a dual-view architecture for different perspectives on conversations.

Core Concepts

Dual-View System

Group chats support two distinct views for messages:

ViewFile SourceContentDescription
User Viewmessages.ui.jsonlClean message streamWhat users see in the UI, without tool call details
Agent View<agent-id>/messages.rollout.jsonlRaw agent messagesComplete agent history including tool calls

When a user sends a message:

  1. All agents in the group chat think in parallel
  2. User view shows "Agent is thinking..." status
  3. Each agent provides their response when ready
  4. Tool calls happen in the background, hidden from user view

Participant Types

TypeIdentifierDescription
humanUser IDHuman users who send messages via UI
agentAgent IDAI agents like Claude, GPT, etc.

Endpoint List

Group Chat CRUD

MethodPathDescription
GET/api/group-chatsList group chats
POST/api/group-chatsCreate group chat
GET/api/group-chats/:idGet group chat details
PATCH/api/group-chats/:idUpdate group chat
DELETE/api/group-chats/:idDelete group chat

Member Management

MethodPathDescription
GET/api/group-chats/:id/membersList members
POST/api/group-chats/:id/membersAdd member
DELETE/api/group-chats/:id/members/:midRemove member

Session Management

MethodPathDescription
GET/api/group-chats/:id/sessionsList sessions
POST/api/group-chats/:id/sessionsCreate session
GET/api/group-chats/:id/sessions/:sidGet session details
PATCH/api/group-chats/:id/sessions/:sidUpdate session
DELETE/api/group-chats/:id/sessions/:sidDelete session
GET/api/group-chats/:id/sessions/:sid/agentsList session agents

Message Management

MethodPathDescription
GET/api/group-chats/:id/sessions/:sid/messagesList messages
POST/api/group-chats/:id/sessions/:sid/messagesSend message

File Management

MethodPathDescription
GET/api/group-chats/:id/filesList files
POST/api/group-chats/:id/filesUpload file
GET/api/group-chats/:id/files/:nameDownload file
DELETE/api/group-chats/:id/files/:nameDelete file

Picture Management

MethodPathDescription
GET/api/group-chats/:id/picturesList pictures
POST/api/group-chats/:id/picturesUpload picture
GET/api/group-chats/:id/pictures/:nameDownload picture
DELETE/api/group-chats/:id/pictures/:nameDelete picture

WebSocket

MethodPathDescription
GET/api/group-chats/:id/sessions/:sid/wsWebSocket connection

Detailed Description

GET /api/group-chats

List group chats.

Query Parameters:

ParameterTypeRequiredDefaultDescription
workspace_pathstringNo-Workspace path
include_globalboolNotrueInclude global group chats
created_bystringNo-Filter by creator

Response:

{
"group_chats": [
{
"id": "gc-abc123",
"name": "Project Discussion",
"description": "Discuss project implementation",
"workspace_path": "/path/to/project",
"created_at": "2024-01-01T10:00:00Z",
"member_count": 3,
"session_count": 2
}
]
}

POST /api/group-chats

Create a group chat.

Request Body:

{
"name": "Project Discussion",
"description": "Discuss project implementation",
"workspace_path": "/path/to/project",
"members": [
{
"agent_id": "CLAUDE_CODE",
"role": "developer"
},
{
"agent_id": "my-reviewer",
"role": "reviewer"
}
]
}

GET /api/group-chats/:id

Get group chat details.

Response:

{
"id": "gc-abc123",
"name": "Project Discussion",
"description": "Discuss project implementation",
"workspace_path": "/path/to/project",
"created_at": "2024-01-01T10:00:00Z",
"updated_at": "2024-01-01T14:00:00Z",
"members": [
{
"id": "member-1",
"agent_id": "CLAUDE_CODE",
"role": "developer",
"joined_at": "2024-01-01T10:00:00Z"
},
{
"id": "member-2",
"agent_id": "my-reviewer",
"role": "reviewer",
"joined_at": "2024-01-01T10:00:00Z"
}
],
"session_count": 2
}

GET /api/group-chats/:id/sessions/:sid/messages

List session messages. Supports multiple views.

Query Parameters:

ParameterTypeRequiredDefaultDescription
viewstringNouiView type: ui or agent
agent_idstringConditional-Agent ID (required when view=agent)
limitintNo50Number of messages to return
beforestringNo-Pagination cursor

View Types:

  • ui: User-friendly view, suitable for frontend rendering
  • agent: Agent view, includes raw messages and tool calls

Response (ui view):

{
"messages": [
{
"id": "msg-1",
"sender": {
"type": "user",
"name": "User"
},
"content": "Please review this code",
"timestamp": "2024-01-01T10:00:00Z"
},
{
"id": "msg-2",
"sender": {
"type": "agent",
"agent_id": "CLAUDE_CODE",
"name": "Claude Code"
},
"content": "I'll review the code...",
"timestamp": "2024-01-01T10:00:05Z",
"status": "completed"
}
],
"has_more": false
}

Response (agent view):

{
"messages": [
{
"id": "msg-1",
"role": "user",
"content": "Please review this code"
},
{
"id": "msg-2",
"role": "assistant",
"content": "I'll review the code...",
"tool_calls": [
{
"id": "call-1",
"type": "Read",
"parameters": {"file_path": "/src/main.ts"},
"result": "..."
}
]
}
]
}

UI Message Types:

type UIMessageType =
| "user" // User message
| "agent_thinking" // Agent is thinking
| "agent_response" // Agent response
| "system" // System messages (member joined/left, etc.)

POST /api/group-chats/:id/sessions/:sid/messages

Send a message to the group chat. Automatically triggers all agent responses.

Request Body:

{
"content": "Please implement this feature",
"attachments": [
{
"type": "file",
"name": "spec.md"
}
]
}

Response:

{
"message_id": "msg-abc123",
"triggered_agents": ["CLAUDE_CODE", "my-reviewer"]
}

GET /api/group-chats/:id/sessions/:sid/ws

WebSocket connection for real-time communication.

Query Parameters:

ParameterTypeRequiredDescription
workspace_pathstringNoWorkspace path
member_typestringNoMember type
member_idstringNoMember ID

WebSocket Message Types:

// Server → Client
interface ServerMessage {
type:
| "message" // New message
| "agent_thinking" // Agent thinking
| "agent_response" // Agent response
| "typing_indicator" // Typing indicator
| "error"; // Error
data: any;
}

// Client → Server
interface ClientMessage {
type:
| "send_message" // Send message
| "switch_view" // Switch view
| "subscribe" // Subscribe to events
| "unsubscribe"; // Unsubscribe from events
data: any;
}

POST /api/group-chats/:id/files

Upload a file.

Request: multipart/form-data

FieldTypeDescription
filefileFile content

Response:

{
"filename": "document.pdf",
"size": 102400,
"url": "/api/group-chats/gc-abc123/files/document.pdf"
}

POST /api/group-chats/:id/pictures

Upload a picture. Only accepts image formats.

Supported Formats: image/jpeg, image/png, image/gif, image/webp

Response:

{
"filename": "screenshot.png",
"size": 51200,
"width": 1920,
"height": 1080,
"url": "/api/group-chats/gc-abc123/pictures/screenshot.png"
}

Group Chat Storage

Group chat data is stored in the workspace directory using a file-based approach:

<workspace>/.viben/group-chats/
└── <group-chat-id>/
├── config.yaml # Group chat configuration
├── files/ # Shared files (group files)
├── pictures/ # Shared pictures (group album)
└── sessions/ # Conversation records
└── <session-id>/
├── config.yaml # Session configuration
├── messages.ui.jsonl # User view messages (append-only)
├── responses.jsonl # Current round agent responses (cleared each round)
└── agents/
└── <agent-id>/
├── messages.rollout.jsonl # Agent message history (with tool calls)
└── subagents/ # Sub-agent messages (if any)
└── agent-<subagent-id>.jsonl

Key Files Explained

FileLifecyclePurpose
messages.ui.jsonlappend-onlyComplete conversation history for user view
responses.jsonlcleared each roundTemporary storage for current round agent responses
messages.rollout.jsonlappend-onlyFull agent message history (including tool calls)
subagents/agent-*.jsonlappend-onlySub-agent message records (following Claude Code design)

The responses.jsonl Lifecycle

The responses.jsonl file plays a crucial role in multi-agent coordination:

  1. User sends message: responses.jsonl is cleared
  2. Agents process: Each agent thinks and generates a response
  3. Agent completes: Response is appended to responses.jsonl
  4. Next round: When user sends next message, responses.jsonl is read to build context for each agent (showing what other agents said)

This mechanism allows each agent to see what other agents responded in the previous round, enabling coherent multi-agent discussions.

Message Building Logic

When sending messages to agents, the Gateway constructs context that includes other agents' previous responses:

Example: 3 agents (Claude, Cursor, Codex)

User Round 1: "Please review this code"
-> To Claude: "Please review this code"
-> To Cursor: "Please review this code"
-> To Codex: "Please review this code"

After agents respond, responses.jsonl contains all 3 responses.

User Round 2: "How should I fix it?"
-> To Claude:
[Cursor]: I found 2 bugs...

[Codex]: I suggest refactoring...

[User]: How should I fix it?

-> To Cursor:
[Claude]: The code has 3 issues...

[Codex]: I suggest refactoring...

[User]: How should I fix it?

View Switching

Users can switch between different views in the UI:

ViewData SourceCan Send MessagesDescription
Group Chat View (default)messages.ui.jsonlYesClean message stream, normal user interaction
Agent Viewagents/<id>/messages.rollout.jsonlNo (read-only)View specific agent's tool calls and processing

Switching Behavior:

  • Switching maintains position in the same conversation round
  • Agent view disables the message input box
  • User must manually switch views; no automatic switching

Comparison with Regular Chat Sessions

AspectRegular Chat SessionGroup Chat
Participants1 user + 1 agent1 user + N agents
Agent ResponseSequentialParallel
Tool CallsShown in UIHidden in background
StorageDatabaseFile system
ViewSingleSwitchable