If you are having trouble creating a reliable prompt, it is often helpful to break the problem down into a few smaller prompts. The chaining and business logic that connects these smaller prompts will be considered an agent.
For example, if we are building an AI doctor, it might be helpful to split this into a few individual prompts for appointment scheduling, surgery preparation, and questions about medicine. You might even want to run a prompt on multiple LLM models from OpenAI, Anthropic, and Google, and then use the outputs to create a final answer.
Agents are ideal for:
LLM Model Synthesis: Gathering insights from multiple medical and choosing the best possible answer.
Data Processing Pipelines: Refining, filtering, or transforming data using multiple models in sequence.
Complex Support Automation: Automating logical decision-making across different models to allow for unit testing and deterministic results.
Gather the prompts required for your agent. Refer to the Getting Started Guide to learn how to create new prompts.
In this example, we will create a an AI doctor that is comprised of 3 prompts.
The “rephrase-question” prompt will refine a question for better clarity.
Copy
Ask AI
[SYSTEM MESSAGE]The patient has asked a question for the AI doctor.Sometimes the patient uses confusing words. Re-write the question in a way that is most understandable for medical professionals.[USER MESSAGE]{question}
The “ai-doctor” prompt will analyze the user’s symptoms and provides a diagnosis.
Copy
Ask AI
[SYSTEM MESSAGE]As an AI doctor, follow these key guidelines:- Analyze user symptoms to offer relevant health information.- Base advice on established medical knowledge; avoid unverified claims.- Emphasize your AI nature and the importance of professional medical consultation.- Maintain user privacy, in line with HIPAA.- Refrain from diagnosing or prescribing.- Communicate with empathy, but encourage users to seek real-world medical advice.Your role is to inform and guide, not to replace professional healthcare.[USER MESSAGE]{question}
The “choose-best-answer” prompt will select the best response from a list. We will run #2 on multiple different models to get the best result.
Copy
Ask AI
[SYSTEM MESSAGE]You are an AI helping to train medical students. They are taking a quiz. Each student provides you an answer. Your job is to return back the "true" answer.To find the true answer, use the aggregation of all their answers to pick the best.[USER MESSAGE]{answers}
Construct an agent to execute your chained prompts one after the other.
This agent will take in a user query, rephrase it to something more specific, run the enriched question through the AI doctor prompt multiple times, and then return the best result.
Navigate to Registry → Agents.
Click Create Agent.
Set up input variables. Click on Input Variables in the top left, and add user_question. Here we can also add a sample value for testing purposes: “Why does my stomach hurt?”
Create the first agent step that will take in the user query and rephrase it to something more detailed.
Name the step: “Enriched Question”.
Click Add Node and set Node Type to Prompt Template.
Select the previously created “rephrase-question” prompt.
Match the input variable user_question to the input variable in the prompt.
Run the AI doctor. Create 3 more steps that use the “ai-doctor” prompt. These steps should all be connected to our first “Enriched Question” node.
To change the model, select “ai-doctor” and click the pencil icon next to the model engine.
Combine the three answers. Use node type: “Combine”. Connect the 3 parallel AI doctor nodes to this combination step.
Create a final node called “Best Answer” using the prompt “choose-best-answer”. Connect it to the combination node created previously.
Mark the “Best Answer” node as an “Output Node” by clicking the three dots on the node. The output node is the final node to run in an agent and will be treated as the “return” statement.
Try clicking “Run” to test it and don’t forget to Save the configuration!