All Products
Search
Document Center

Intelligent Media Services:Add conversational memory for AI agents

Last Updated:Dec 08, 2025

This topic describes how to enable AI agents to utilize previous interactions to achieve more coherent conversations based on the context.

What is conversational memory

Conversational memory enables a system to record and retrieve previous interactions over one or several conversation sessions. This feature allows the agent to recall past messages and use them as references in ongoing and future interactions, helping the agent better understand and respond to users' needs.

How to add conversational memory

Call the StartAIAgentInstance or GenerateAIAgentCall operation to start an AI agent instance. Configure AIAgentConfig.LlmConfig.LlmHistory to pass context information and previous messages to the agent. For more information about the AIAgentConfig parameter, see AIAgentConfig.

The following table describes the data structure of the LlmHistory parameter.

Item

Type

Description

Sample value

LlmHistory

Array

The context information and messages during past interactions with large language models (LLMs) or multimodal large language models (MLLMs).

  • Role

String

Specifies the role of the conversation participant. Valid values:

  • user

  • assistant

  • system

  • function

  • plugin

  • tool

user

  • Content

String

Stores the conversation text, capturing the specific expressions or responses of the role.

Hello

Example

[{
  "Role": "user",
  "Content": "I am in Beijing. Please introduce the history of Beijing."
},{
  "Role": "assistant",
  "Content": "Beijing has a history of over 3,000 years. It became the national political center starting from the Yuan Dynasty and further developed into a world-class metropolis during the Ming and Qing Dynasties. As the capital of multiple dynasties, Beijing witnessed the long history and cultural prosperity of China.",
},{
  "Role": "user",
  "Content": "Introduce the attractions here."
},{
  "Role": "assistant",
  "Content": "Beijing has many famous attractions. The Forbidden City is the world's largest ancient palace complex, showcasing the splendor of ancient Chinese royalty. The Great Wall, particularly the Badaling section, is one of China's symbols, attracting countless tourists with its magnificent scenery and long history."
}]
Note

For information about how to retrieve the conversation records, see Call records of AI agents. You must reconstruct the retrieved records into the specified format.

After you pass the LlmHistory parameter to the agent, it can better understand your queries and generate accurate and context-relevant responses.

For example, you can query:

How is the climate here?

The agent will respond without asking your location:

Beijing has a temperate semi-humid and semi-arid climate with distinct seasons. Winters are cold and dry, summers are hot and rainy, and springs and autumns are relatively short but pleasant. The annual average temperature is about 12°C, with summer highs reaching over 35°C and winter lows dropping to around -10°C.