Whatever message this page gives is out now! Go check it out!
Agent() function in ColdFusion turns a stateless LLMModel (created with ChatModel()) into a full conversational AI agent. It adds test:"You are a travel assistant.", applied persistently across all subsequent calls.Agent(), which must include a CHATMODEL (the LLMModel instance). Optionally add:TOOLS: A list of ColdFusion CFCs or MCP clients the AI can use. See Deploy and administer.CHATMEMORY: Configuration for how conversation history is stored and managed.| Method | Description |
|---|---|
agent.chat(message) | Sends a message using the current persona and memory context. |
agent.chat(message, userId) | Same as above, but memory is scoped to a specific user/session. |
agent.chat(chatRequestStruct) | Allows explicit system and user messages for that call. |
agent.chat(chatRequestStruct, userId) | Combines rich request struct with per-user memory. |
agent.systemMessage(messageString) | Sets a persistent system-level instruction for all subsequent calls. |
agent.systemMessage() requires CHATMEMORY to be configured to work correctly. If CHATMEMORY is not set, the system message is accepted without error but not sent to the provider. Use a chatRequest struct as an alternative when not using memory.
<cfscript>
// 1. Create the LLMModel
chatModel = ChatModel({
PROVIDER : "openAi",
APIKEY : "#application.apiKey#",
MODELNAME : "gpt-4o-mini"
});
// 2. Create an Agent
agent = Agent({ CHATMODEL : chatModel });
// Method 1: Plain string
response1 = agent.chat("What is the capital of Japan?");
writeOutput(response1.message);
// Method 2: chatRequest struct (overrides persona for this call)
chatRequest = {
SYSTEMMESSAGE : "You are a poet. Reply in 2 lines.",
USERMESSAGE : { MESSAGE : "Tell me about the ocean." }
};
response2 = agent.chat(chatRequest);
writeOutput(response2.message);
// Method 3: Persistent system message
agent.systemMessage("You are a scientist. Be concise.");
response3 = agent.chat("Why is the sky blue?");
writeOutput(response3.message);
// Method 4: Override system message for one call
chatRequest2 = {
SYSTEMMESSAGE : "You are a pirate. Use pirate speak.",
USERMESSAGE : { MESSAGE : "What is gravity?" }
};
response4 = agent.chat(chatRequest2);
writeOutput(response4.message);
</cfscript>