Skip to content

Best way to store structured conversation context #1299

@rafaelpierre

Description

@rafaelpierre

Question

I was wondering what's the best practice to store conversation context for multiturn use cases.

Just for disambiguation purposes - I'm referring here to arbitrary, structured context that I want to persist for individual sessions, specially for multiturn conversational use cases. This is not related to the conversation history per se.

To make it a bit more concrete - let's say I have a use case where I want to implement agents for a Customer Service use case, where I want to ask some questions to users to understand if they fulfill the needs to be routed to a human agent.

Let's say I have a ConversationContext class which inherits from pydantic.BaseModel:

class ConversationContext(BaseModel):
   intent: Literal["unknown", "insurance", "mortgage", "credit_card"]
   vat_registration: int

My idea is to update this context as the conversation turns go.

Initially I assumed that the context object passed to the runner would be the way to go. Now reading the documentation a bit closer, I don't think that's the case - given that the RunContextWrapper is not really shared/changed by the LLM.

I had two ideas:

  1. Serializing/deserializing this ConversationContext object and including it as part of the system prompt and/or conversation history - but that sounds too... prone to hallucination / non-deterministic?

  2. Creating a function_tool that reads the existing ConversationContext from an external DB, and updates it if needed

Is anyone implementing something similar? If yes, any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions