Whatever message this page gives is out now! Go check it out!

Send prompts to an LLM

Last update:
May 18, 2026

Introduction

Sending prompts is the core way to interact with an LLM in ColdFusion. A prompt is a message or set of messages that tells the model what you want it to do — answering a question, generating text, translating content, or performing a task.
ColdFusion's AI framework provides a unified and flexible way to send prompts, whether you want simple Q&A or advanced, multi-turn conversations.

Prompt types

Plain string prompt
The simplest way to interact with a model. Pass a single string, which is treated as a user message. Supported by both ChatModel.chat() and Agent.chat().

          <cfscript>
              // configure chat model
              chatModelConfig = {
                  provider : "openAI",
                  modelName : "gpt-5.4",
                  apiKey : "#application.apiKey#"
              }
              // instantiate chat model
              chatModel= ChatModel(chatModelConfig)
          
              // chat with model
              response = chatModel.chat("Summarize the key features of ColdFusion 2025.")
              writeDump(response)
              writeOutput(response.message)
          </cfscript>
      

Structured chat request (Agent only)

For more control, use a chat request struct. This separates the system message (which sets the assistant's persona, rules, or tone) from the user message (the actual question or instruction).
Note:
Note: Structured chat requests are only supported via Agent.chat(). ChatModel.chat() accepts plain strings only.

        <cfscript>
            // configure chat model
            chatModelConfig = {
                provider : "openAI",
                modelName : "gpt-5-nano",
                apiKey : "#application.apiKey#",
                temperature : 0.2
            }
            // instantiate chat model
            chatModel= ChatModel(chatModelConfig)
        
            agent=agent({
                chatModel: chatModel,
                description: "Converts code snippets between programming languages."
            });
        
             try {
                // chat with agent
                 response = agent.chat("Convert 'console.log(x)' to ColdFusion.");
                 writeDump(response)
                 writeOutput(response.message);
             } catch (any e) {
                 writeOutput("Error: " & e.message);
                 writedump(e);
             }
        </cfscript>
      
  • The system message defines how the assistant should behave.
  • The user message contains the prompt or question.

Use prompts with Agent

If you use an Agent (for memory, tools, or advanced features), you can send prompts as:
  • A plain string uses the current system persona and memory context
  • A chat request struct overrides the persona for that specific call
Plain string with persistent system persona:

      

<cfscript>
            // configure chat model
            chatModelConfig = {
                provider : "Anthropic",
                modelName : "claude-sonnet-4-6",
                apiKey : "#application.anthropicKey#"
                
            }

            // instantiate chat model
            chatModel= ChatModel(chatModelConfig)

            // 2. Create an Agent
            agent = Agent({ CHATMODEL : chatModel });

                    
            chatRequest = {
                systemMessage: "You are a ColdFusion developer. Reply in 2 lines.",
                userMessage: "What is ColdFusion CFC"
            };


            //agent.chat(chatRequest);
            response=agent.chat(chatRequest);
            writeOutput(response.message);
</cfscript>
            
Output
A ColdFusion Component (CFC) is a reusable, object-oriented building block in ColdFusion that encapsulates functions (methods) and variables (properties) within a `.cfc` file, enabling modular and maintainable code. It supports OOP concepts like inheritance, interfaces, and access control, making it ideal for building services, DAOs, and business logic layers.
One-off persona override using a struct:

                 <cfscript>
                    // configure chat model
                    chatModelConfig = {
                        provider : "openAI",
                        modelName : "gpt-5-nano",
                        apiKey : "#application.apiKey#",
                        temperature : 0.2
                    }
                    // instantiate chat model
                    chatModel= ChatModel(chatModelConfig)
                
                    chatRequest = {
                        chatModel: chatModel,
                        SYSTEMMESSAGE : "You are a stock trader.",
                        USERMESSAGE   : { MESSAGE : "Should I buy or sell tech stocks?" }
                    };
                    response = agent.chat(chatRequest);
                    writeOutput(response.message);
                </cfscript>
            
Output
Great question! Here's my take as a stock trader: **Current Tech Stock Considerations:** 📈 **Reasons to BUY:** - AI and cloud computing sectors continue strong growth - Long-term tech adoption trends remain intact - Some valuations have corrected from highs - Strong balance sheets in major tech companies 📉 **Reasons to SELL or be CAUTIOUS:** - High interest rate environment pressures growth stock valuations - Regulatory risks increasing globally - Some tech stocks still trading at premium valuations - Market volatility and macroeconomic uncertainty

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page