dataflow.api.routes.conversation_routes¶
Conversation management API routes.
This module provides FastAPI routes for managing conversations between users and agents. It supports operations like creating, listing, retrieving, and deleting conversations, as well as adding messages to existing conversations.
The conversation system provides persistence for chat history, enabling users to continue conversations across sessions. It also includes integration with the credits system for tracking usage and enforcing limits.
Key features: - Conversation CRUD operations - Message management - Usage tracking and credits - Pagination for conversation listing - Agent integration
Typical usage example:
# Client-side code to create and use a conversation import requests
# Create a new conversation response = requests.post(
“http://localhost:8000/api/conversations”, json={
“title”: “My Conversation”, “agent_id”: “agent-123”, “metadata”: {“topic”: “AI Ethics”}
}, headers={“Authorization”: “Bearer YOUR_TOKEN”}
)
conversation_id = response.json()[“id”]
# Add a message to the conversation response = requests.post(
f”http://localhost:8000/api/conversations/{conversation_id}/messages”, json={
“content”: “Tell me about AI ethics”, “role”: “user”
}, headers={“Authorization”: “Bearer YOUR_TOKEN”}
)
Functions¶
|
Add a message to a conversation and get a response. |
|
Get conversation details and state. |
|
List conversations for the current user. |
Module Contents¶
- async dataflow.api.routes.conversation_routes.add_message(thread_id, message, user_id=Depends(require_auth))¶
Add a message to a conversation and get a response.
- async dataflow.api.routes.conversation_routes.get_conversation(thread_id, user_id=Depends(require_auth))¶
Get conversation details and state.
- async dataflow.api.routes.conversation_routes.list_conversations(user_id=Depends(require_auth), offset=Query(0, ge=0), limit=Query(20, ge=1, le=100))¶
List conversations for the current user.
This endpoint retrieves a paginated list of conversations belonging to the authenticated user. Results can be paginated using offset and limit parameters.
- Parameters:
- Returns:
Object containing conversations list and pagination metadata
- Return type:
- Raises:
HTTPException – If there’s an error retrieving the conversations
Examples
GET /api/conversations?offset=0&limit=20