Here's a prompt designed specifically for utilizing conversation history stored in memory:
conversation_prompt = f"""
You are an AI assistant analyzing user queries in the context of previous conversation history.
Your task is to provide relevant responses based on both the current query and past interactions.
CONVERSATION HISTORY:
{conversation_history}
CURRENT USER QUERY:
{input_text}
ADDITIONAL CONTEXT:
{context_on_user_query}
Instructions:
1. First, analyze if the current query starts a new conversation topic:
- If it's completely unrelated to previous topics, treat it as a new conversation
- If it references or continues previous topics, use relevant history
2. When using conversation history:
- Only reference directly relevant previous exchanges
- Prioritize most recent relevant interactions
- Ignore historical information that doesn't directly relate to current query
3. Response construction rules:
- Respond in {dia_lang}
- If the query continues previous topic:
* Use relevant history to maintain context
* Reference specific previous exchanges if applicable
- If it's a new topic:
* Start fresh without referencing previous exchanges
* Use only current query and provided context
4. Insufficient information handling:
- If neither history nor current context provides enough information:
* Clearly state this in {dia_lang}
* Specify what additional information is needed
Output format:
- If continuing previous topic:
"Based on our previous discussion about [topic], [your response]"
- If new topic:
"[direct response to new query]"
- If insufficient information:
"Для полного ответа не хватает информации о [specify missing details]"
Remember:
- Only use relevant history
- Stay focused on the current query
- Maintain conversation coherence
- Respond in {dia_lang}
"""
# Example usage:
input_text = "а роли какие"
conversation_history = [
{"role": "user", "content": "Расскажи про специалиста по расчету себестоимости"},
{"role": "assistant", "content": "Это специалист, который занимается расчетом себестоимости продукции..."}
]
context_on_user_query = "Additional context about cost accounting specialist"
dia_lang = "Russian"
# Format the conversation history for the prompt
formatted_history = "\n".join([
f"User: {exchange['content']}" if exchange['role'] == 'user'
else f"Assistant: {exchange['content']}"
for exchange in conversation_history
])
# Construct the prompt
prompt = conversation_prompt.format(
conversation_history=formatted_history,
input_text=input_text,
context_on_user_query=context_on_user_query,
dia_lang=dia_lang
)
Key Features:
-
Conversation Topic Detection:
- Identifies if query is new or continues previous topic
- Prevents inappropriate context carry-over
- Maintains conversation coherence
-
History Relevance Filtering:
- Uses only directly relevant historical exchanges
- Prioritizes recent interactions
- Ignores unrelated historical information
-
Structured Response Format:
- Different formats for continuing vs. new topics
- Clear indication of insufficient information
- Maintains language consistency
-
Context Integration:
- Combines conversation history with current context
- Preserves conversation flow
- Handles context transitions
Example Response Formats:
# Continuing previous topic:
"Based on our previous discussion about cost accounting specialist, relevant roles include..."
# New topic:
"А какие роли у специалиста по расчету себестоимости?"
# Insufficient information:
"Для полного ответа не хватает информации о конкретных аспектах ролей"
Benefits:
-
Improved Coherence:
- Maintains logical conversation flow
- Prevents context confusion
- Handles topic transitions smoothly
-
Better Context Utilization:
- Effectively uses relevant history
- Integrates current context
- Maintains conversation relevance
-
Clear Response Structure:
- Consistent formatting
- Clear indication of context usage
- Explicit handling of information gaps
-
Flexible History Integration:
- Adapts to conversation flow
- Handles both new and continuing topics
- Maintains contextual relevance
This prompt structure helps the LLM effectively utilize conversation history while maintaining focus and relevance in responses.