Fetch History

Retrieves conversation history for LLM based on conversation ID, enabling multi-turn conversations with context.

Quick Start

To get started:

  • Add the Fetch History block to your flow
  • Provide a history_name to identify the conversation
  • Set history_depth to control how many exchanges to retrieve
  • Provide the conversation_id via msg.payload.conversation_id
  • Receive the conversation history in msg.payload

Configuration

History Name (required)

A title or name for the conversation history to fetch.

History Depth (required)

The number of previous exchanges to retrieve. Set to 0 for all history.

Default: 0

Common Input Format

msg.payload.conversation_id (string)

The unique conversation identifier from the Create Conversation block.

Example: "conv_abc123xyz"

Common Output Format

msg.payload (object)

msg.payload contains the retrieved conversation history.

Example:

{
  "history": [
    {"user_query": "What is the warranty period?", "llm_response": "The warranty period is 12 months."},
    {"user_query": "Can I extend it?", "llm_response": "Yes, you can purchase an extended warranty."}
  ]
}

Example

Input (msg.payload)

{
  "conversation_id": "conv_abc123xyz"
}

Output (msg.payload)

{
  "history": [
    {"user_query": "What is the warranty period?", "llm_response": "The warranty period is 12 months."},
    {"user_query": "Can I extend it?", "llm_response": "Yes, you can purchase an extended warranty."}
  ]
}

Usage in Flows

  1. Use after Create Conversation to retrieve existing history
  2. Pass the retrieved history to LLM Query v2 via msg.payload.history
  3. Enable multi-turn conversations by maintaining context across queries

Errors

When the block fails, it raises an error. Use a Catch block in your flow to handle failures and inspect the error payload.

Common mistakes

  • Invalid conversation_id: Ensure the conversation ID exists and was created previously.
  • History depth too large: Setting very large depth values may impact performance.
  • Missing history_name: The history name is required to identify which conversation to fetch.

Best Practices

  • Set appropriate history_depth based on your use case to balance context and performance
  • Use consistent history_name values across your flow
  • Handle cases where conversation history may be empty (new conversations)
  • Consider clearing or archiving old conversations to manage storage