Conversation Flow
The Conversation Flow
component is an inheritable class that enables custom turn-taking logic, transcript preprocessing, and memory/RAG integrations before LLM processing.
Key Features:​
- Custom transcript preprocessing
- Turn-based conversation management
- Memory and RAG integration hooks
- Flexible LLM processing pipeline
- Streaming response support
Example Implementation:​
from videosdk.agents import Agent, ConversationFlow, ChatContext
class MyConversationFlow(ConversationFlow):
def __init__(self, agent, stt=None, llm=None, tts=None):
super().__init__(agent, stt, llm, tts)
async def run(self, transcript: str) -> AsyncIterator[str]:
"""Main conversation loop: handle a user turn."""
await self.on_turn_start(transcript)
# Pre-process transcript: clean, normalize, validate input
# Apply custom business logic, content filtering
# sample impl
processed_transcript = transcript.lower().strip()
self.agent.chat_context.add_message(role=ChatRole.USER, content=processed_transcript)
# Use process_with_llm method for invoking llm after pre processing transcript
async for response_chunk in self.process_with_llm():
yield response_chunk
await self.on_turn_end()
async def on_turn_start(self, transcript: str) -> None:
"""Called at the start of a user turn."""
# Fetch relevant context from memory/database
# Perform RAG retrieval for enhanced responses
# Initialize turn-specific variables
# Log conversation analytics
self.is_turn_active = True
async def on_turn_end(self) -> None:
"""Called at the end of a user turn."""
# Store conversation in memory/database
# Update user preferences and context
# Perform cleanup operations
# Log turn completion metrics
self.is_turn_active = False
Use Cases:​
- RAG Implementation - Retrieve relevant documents and context before LLM processing
- Memory Management - Store and recall conversation history across sessions
- Content Filtering - Apply safety checks and content moderation on input/output
- Analytics & Logging - Track conversation metrics and user behavior patterns
- Business Logic Integration - Add domain-specific processing and validation rules
- Multi-step Workflows - Implement complex conversation flows with state management
The key methods allow you to inject custom logic at different stages of the conversation flow, enabling sophisticated AI agent behaviors while maintaining clean separation of concerns.
note
Conversation Flow works with Cascading Pipeline currently.
Got a Question? Ask us on discord