Whatever message this page gives is out now! Go check it out!
ChatModel()) itself. A stateless ChatModel() has no memory; memory is only available when you use Agent().| Type | Parameter | Description |
|---|---|---|
messageWindowChatMemory | maxMessages | Retains the last N messages in history. Simple and predictable — oldest messages are dropped when the limit is reached. |
tokenWindowChatMemory | maxTokens | Retains messages up to a maximum token count. Useful when you need to stay within a provider's context window limit. Oldest messages are dropped to stay within the token budget. |
messageWindowChatMemory for most use cases. Use tokenWindowChatMemory when working with models that have strict context window limits and you need precise control over token usage.persistenceStore is specified, history is held in the server's JVM memory. It is fast and requires no external setup, but history is lost when the ColdFusion server restarts or the application session ends. Suitable for development and short-lived sessions.
<cfscript>
chatModelConfig = {
provider : "openAI",
modelName : "gpt-5-nano",
apiKey : "#application.apiKey#"
}
chatModel = ChatModel(chatModelConfig);
agent = Agent({
CHATMODEL : chatModel,
CHATMEMORY : {
TYPE : "messageWindowChatMemory",
MAXMESSAGES : 20,
PERUSER : true
}
});
response1 = agent.chat("Why is the sky blue?", "user1");
writeDump(var=response1.message, label="User1");
</cfscript>
CHATMEMORY by the cache name you assigned it.
agent = Agent({
CHATMODEL : chatModel,
CHATMEMORY : {
TYPE : "messageWindowChatMemory",
MAXMESSAGES : 20,
PERUSER : true,
PERSISTENCESTORE : "myRedisCache" // cache name from CF Admin > Caching. Persistencestore values can be REDIS/MEMCACHED/EHCACHE
}
});
| Store | When to use |
|---|---|
| Redis | Recommended for production and clustered deployments. Fast, durable, supports TTL. |
| Memcache | High-throughput, low-latency use cases. Note: data is volatile and not durable across restarts. |
| Ehcache | Single-server deployments. Configured and managed within ColdFusion. |
PERUSER : true isolates each user's conversation history. Each unique userId passed to agent.chat() gets its own memory context. Without this, all calls share the same global memory.
// User 1's conversation
agent.chat("My name is Alice.", "user-alice");
// User 2's conversation — completely separate history
agent.chat("My name is Bob.", "user-bob");
// Alice's follow-up — only recalls Alice's history
response = agent.chat("What is my name?", "user-alice");
// Returns: "Alice"
| Parameter | Type | Required | Description |
|---|---|---|---|
| TYPE | String | Yes | Memory window strategy. messageWindowChatMemory or tokenWindowChatMemory. |
| MAXMESSAGES | Number | Conditional | Maximum number of messages to retain. Required when TYPE is messageWindowChatMemory. |
| MAXTOKENS | Number | Conditional | Maximum number of tokens to retain. Required when TYPE is tokenWindowChatMemory. |
| PERUSER | Boolean | No | When true, memory is scoped per userId. When false or omitted, all calls share one global memory. Default: false. |
| PERSISTENCESTORE | String | No | Name of the cache store configured in ColdFusion Administrator (Caching page). If omitted, in-memory storage is used. |
<cfscript>
chatModelConfig = {
provider : "openAI",
modelName : "gpt-5-nano",
apiKey : "#application.apiKey#"
}
chatModel = ChatModel(chatModelConfig);
agent = Agent({
CHATMODEL : chatModel,
CHATMEMORY : {
TYPE : "messageWindowChatMemory",
MAXMESSAGES : 20,
PERUSER : true
}
});
agent.chat("My name is Alice and I live in Paris.", "user123");
response = agent.chat("What is my name and where do I live?", "user123");
writeOutput(response.message); // Your name is Alice, and you live in Paris.
</cfscript>
<cfscript>
chatModelConfig = {
provider : "openAI",
modelName : "gpt-5-nano",
apiKey : "#application.apiKey#"
}
chatModel = ChatModel(chatModelConfig);
agent = Agent({
CHATMODEL : chatModel,
CHATMEMORY : {
TYPE : "tokenWindowChatMemory",
MAXTOKENS : 4000,
PERUSER : true,
PERSISTENCESTORE : "myRedisCache"
}
});
agent.chat("Summarize the quarterly sales report for Q1.", "user456");
response = agent.chat("Now compare it with Q2.", "user456");
writeOutput(response.message);
</cfscript>
agent = Agent({
CHATMODEL : chatModel,
CHATMEMORY : {
TYPE : "messageWindowChatMemory",
MAXMESSAGES : 10
// PERUSER omitted — all users share one memory context
}
});