Collection Agent
What this page is for
Use the AI agent to interact with collection content, manage chunks, and perform automated collection maintenance tasks through natural language.
Endpoints
Chat (streaming)
POST /api/collections/:collectionId/agent/chat— SSE streaming chatPOST /api/collections/:collectionId/agent/chat/sync— synchronous chat
Collection cleaning
POST /api/collections/:collectionId/agent/clean— SSE streaming clean operation
Session management
POST /api/collections/:collectionId/agent/sessions— create sessionGET /api/collections/:collectionId/agent/sessions— list sessionsGET /api/collections/:collectionId/agent/sessions/:sessionId— get session with messagesPATCH /api/collections/:collectionId/agent/sessions/:sessionId— update session titleDELETE /api/collections/:collectionId/agent/sessions/:sessionId— delete session
System prompts
GET /api/collections/:collectionId/agent/prompts/global— get global promptPATCH /api/collections/:collectionId/agent/prompts/global— set global promptDELETE /api/collections/:collectionId/agent/prompts/global— reset to defaultGET /api/collections/:collectionId/agent/prompt— get collection-specific promptPATCH /api/collections/:collectionId/agent/prompt— set collection-specific promptDELETE /api/collections/:collectionId/agent/prompt— remove collection override
How it works
The collection agent is an AI assistant with tools to search, read, and modify chunks within a collection. It streams responses via Server-Sent Events (SSE) so you see thinking, tool calls, and results in real time.
SSE event types
| Event | Description |
|---|---|
thinking | Agent reasoning in progress |
tool_call | Agent is invoking a tool |
tool_result | Tool execution result |
message | Final text response |
error | Error occurred |
done | Stream complete |
Steps
- Create an agent session for your collection.
- Send a chat message with the session ID.
- The agent searches the collection, reasons about your request, and responds.
- For maintenance tasks, use the clean endpoint to detect and remove dirty chunks.
Example
Create a session
curl -X POST http://localhost:3000/api/collections/<collectionId>/agent/sessions \
-H "Content-Type: application/json" \
-H "X-User-ID: user-1" \
-d '{ "title": "Quality review" }'
Chat with the agent (sync mode)
curl -X POST http://localhost:3000/api/collections/<collectionId>/agent/chat/sync \
-H "Content-Type: application/json" \
-H "X-User-ID: user-1" \
-d '{
"message": "Find chunks with low quality scores and suggest improvements",
"sessionId": "<sessionId>"
}'
Clean collection
curl -X POST http://localhost:3000/api/collections/<collectionId>/agent/clean \
-H "X-User-ID: user-1"
SSE events stream progress: clean_progress, dirty_chunk_found, dirty_chunk_deleted, clean_complete.
Verify
- Agent sessions are created and listed correctly.
- Chat responses include tool calls and meaningful answers.
- Collection cleaning identifies and removes low-quality chunks.
Next steps
- Chat Playground — simple RAG chat without agent capabilities.
- Collections — manual collection management.