Supervisor Agent
In this chapter, we will create the Supervisor Agent, which acts as the central intelligence for coordinating multiple AI agents and actions.
Building the Supervisor Agent in Node-RED
The Supervisor Agent serves as a classifier and coordinator in our AI system. Instead of directly responding to user queries, it determines:
- What type of request the user made (e.g., information retrieval, task execution, data processing).
- Which agent or action should handle the request (e.g., a Calculator Agent, Weather Agent, or API Fetcher).
- How to forward the request to the correct flow in Node-RED.
Supervisor Agent Workflow
- Receive user input.
- Classify the request type using an LLM.
- Select the correct agent or action.
- Forward the request to the appropriate flow.
- Return the agent’s response to the user.
Supervisor Agent – Prompt Engineering
In this section, we will focus on prompt engineering to define the behavior of our Supervisor Agent. The entire logic will be handled within a single Function Node in Node-RED.
Why Prompt Engineering? - Instead of hardcoding logic for selecting actions, we will use a well-structured system prompt to:
✅ Define the Supervisor Agent’s personality & soft skills
✅ Establish clear behavior guidelines for user interaction
✅ Specify how the agent should determine the right action
✅ Enforce consistent output formatting (JSON)
✅ Utilize chat history to improve responses
Injecting Dynamic Data into the Prompt
To make the Supervisor Agent more context-aware and dynamic, we can inject real-time data into the system prompt using JavaScript variables inside the Function Node in Node-RED.
- Why Use Variables in the Prompt?
✅ Provides real-time context (e.g., current time, user preferences, recent interactions).
✅ Enhances personalization by dynamically adjusting responses.
✅ Improves decision-making by embedding up-to-date system information.
Example: Injecting the Current Time into the Prompt
One of the simplest but most useful dynamic variables is current time. This helps the agent:
- Understand what time of day it is (useful for greetings).
- Make time-based recommendations (e.g., suggesting morning coffee or late-night promotions).
- Maintain accurate logs of when requests are handled.
First we need to define the variable in the JS code in Function Node.
const apiKey = "sk-proj-o...";
msg.headers = {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
};
msg.current_date = new Date();
msg.payload = {
model: "gpt-4",
messages: [
{ "role": "system", "content": `
You are a helpful assistant.
Current time is ${msg.current_date}
`
}
],
temperature: 0.7
};
msg.url = "https://api.openai.com/v1/chat/completions";
return msg;
Expanding Beyond Time: Other Dynamic Variables The same approach can be used to inject:
- User session data (e.g.,
msg.user_name = "John"; → "Hello, ${msg.user_name}"
). - Product availability (e.g.,
"Available products: ${msg.available_products}"
). - Order history details (e.g.,
"Last order: ${msg.last_order_id}"
). - hat history insights (e.g.,
"Previous topic discussed: ${msg.last_topic}"
).
Injecting AI Agent State into the Prompt
To make the Supervisor Agent more intelligent and context-aware, we will introduce a state management system. This will allow the AI to store and retrieve key information about its current state, ensuring it maintains continuity across interactions.
How We Store the AI Agent State - The Agent State is stored as a global variable in Node-RED so that it can persist across different requests.
const apiKey = "sk-proj-o...";
msg.headers = {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
};
msg.current_date = new Date();
msg.agentState = global.get("agentState") || {};
msg.agentState = JSON.stringify({
...msg.agentState
});
msg.payload = {
model: "gpt-4",
messages: [
{ "role": "system", "content": `
You are a helpful assistant.
Current time is ${msg.current_date}
JSON object representing your current state: ${msg.agentState}
`
}
],
temperature: 0.7
};
msg.url = "https://api.openai.com/v1/chat/completions";
return msg;
Initializing AI Agent State in Node-RED
To better understand how the AI Agent State works and to facilitate testing, we will create a separate Node-RED flow that initializes and sets static data for the agent. This will allow us to predefine important parameters such as currency, language, and other system-level settings.
The AI Agent State Initialization Flow consists of:
- Inject Node: Triggers the initialization.
- Function Node: Defines and stores the static AI Agent state.

Agent State Initialization Flow JSON
[
{
"id": "init_agent_state",
"type": "inject",
"z": "465c30b32ffb6826",
"name": "Set AI Agent State",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": "",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 210,
"y": 340,
"wires": [
[
"define_agent_state"
]
]
},
{
"id": "define_agent_state",
"type": "function",
"z": "465c30b32ffb6826",
"name": "Initialize AI Agent State",
"func": "let agentState = {\n \"currency\": \"USD\",\n \"language\": \"English\",\n};\n\nglobal.set(\"agentState\", agentState);\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 340,
"wires": [
[]
]
}
]
JavaScript Code of the Function Node ("Initialize AI Agent State")
let agentState = {
"currency": "USD",
"language": "English",
};
// Save to global context
global.set("agentState", agentState);
return msg;
What This Code Does:
- Creates a static JSON object representing the AI Agent's state.
- Defines key system parameters, such as:
- Currency: "USD" (can be changed dynamically in future).
- Language: "English" (could be adapted based on user interactions).
- Saves this state to Node-RED’s global context (global.set("agentState")).
- Returns msg to complete execution (though it is not needed for output in this case).
Finalizing Dynamic Data Prompt
Now that we have successfully integrated dynamic variables such as current time and AI Agent state, it's time to test everything in action. In this section, we will:
✅ Store chat history in the AI Agent state.
✅ Inject both chat history and user messages into the Supervisor Agent’s prompt.
✅ Run tests by asking the AI Agent about the current time and currency.
To fully track interactions, we will inject chat history into the prompt. Also we will inject both the agent state and user message into the prompt.
📌 Updated Function Node code which include Final Prompt with Dynamic Data Injection:
const apiKey = "sk-proj-o...";
msg.headers = {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
};
msg.input = msg.payload.input;
// Retrieve conversation history (or create an empty array if none exists)
let history = global.get("chat_history") || [];
// Add the latest user input
history.push({ role: "user", content: msg.payload.input });
// Limit the history size to avoid excessive token usage (e.g., keep last 5 messages)
if (history.length > 5) history.shift();
msg.current_date = new Date();
msg.agentState = global.get("agentState") || {};
msg.agentState = JSON.stringify({
...msg.agentState
});
// Construct the payload with memory
msg.payload = {
model: "gpt-4",
messages: [
{
"role": "system", "content": `
You are a helpful assistant.
Current time is ${msg.current_date}
JSON object representing your current state: ${msg.agentState}
Chat history information, chat_history: ${history}
`
},
{ "role": "user", "content": msg.input }
],
temperature: 0.7
};
// Store the updated history in Node-RED’s global memory
global.set("chat_history", history);
msg.url = "https://api.openai.com/v1/chat/completions";
return msg;
Test 1: Asking for the Current Time
Now that we have implemented dynamic variables, let's test the AI with two example queries. User Input:
{
"input": "What time is it now?"
}
AI Agent Response:
{
"role":"assistant",
"content":"The current time is 16:50 GMT.",
"refusal":null
}
Test 2: Asking for the Currency in Use
Now that we have implemented dynamic variables, let's test the AI with two example queries. User Input:
{
"input": "Which currency are we using?"
}
AI Agent Response:
{
"role":"assistant",
"content":"The current time is 16:50 GMT.",
"refusal":null
}
Supervisor Agent Prompt
The Supervisor Agent's system prompt is the foundation of its intelligence and decision-making. It defines how the agent interacts with users, determines the correct actions, and maintains context across conversations.
This structured prompt ensures:
- A clear and professional personality that aligns with business objectives.
- Consistent and natural interactions with users.
- Smart action selection based on user intent and available services.
- Effective use of chat history to maintain context over multiple interactions.
- Well-formatted JSON responses that integrate seamlessly into Node-RED workflows.
By following this structured approach, the Supervisor Agent can analyze user requests, select the most appropriate action, and guide the conversation effectively while ensuring all required information is collected.
1. Personality & Soft Skills
Defines the AI’s communication style, ensuring a professional and user-friendly experience.
- Sets the agent's tone and behavior.
- Ensures the agent remains polite, concise, and efficient.
`You are an AI agent embodying a great and polite salesperson who is always happy to help with any question. `
2. Main Objective
Clearly states the Supervisor Agent’s primary function.
- Outlines the business goal (e.g., assisting customers, increasing sales).
- Ensures every response is aligned with the company's priorities.
`Your main objective is to assist clients courteously while effectively upselling to increase the order size and enhance company profitability.
- Warmly greet clients and make them feel valued.
- Use positive and polite language throughout all interactions.
- Be attentive to client questions and provide clear, helpful answers.
- Identify opportunities to suggest additional or upgraded products.
- Present upsell options as beneficial solutions to the client's needs.
- Emphasize the added value and advantages of extra products or services.
- Maintain a friendly and professional demeanor focused on client satisfaction and increased sales.`
3. How to Behave with the User
Defines general rules for interaction.
- Ensures politeness and professionalism.
- Guides the AI in handling user queries effectively.
- Sets boundaries for upselling, consultation, and assistance.
`Your task is to interact with a customer to assist them in:
- Providing information about products, offering consulting, and providing links to product details.
- Tracking order delivery status and providing order history, always requiring the customer to provide their CPF (Cadastro de Pessoas Físicas) number or order ID to identify them and retrieve their order information.`
4. Interaction Guidelines
Provides step-by-step instructions on how the AI should conduct interactions.
- Ensures structured conversations (e.g., asking one question at a time).
- Guides the AI on handling missing information, confirmations, and proactive suggestions.
`<interaction_guidelines>
### Interaction Guidelines
* Use Only Available Products: Never generate or assume product details such as names, codes, or IDs. All product information must be taken strictly from the available_products list. If a product is not available, inform the customer or use the load_more_products action to find more options.
* Ask Questions One by One: Avoid overwhelming the customer with multiple questions at once. Ask questions sequentially to keep the conversation focused and clear.
* Be Proactive: Take the lead by suggesting products based on user preferences and ensuring all essential information is gathered for order completion.
* Confirm Details: Summarize and confirm details periodically to avoid misunderstandings and make sure the customer is satisfied.
* Stay Focused on the Goal: Your task is to collect all the necessary information and finalize the order. Prompt the customer whenever there are missing details or additional products they may need.
* Maintain Context When Editing Orders: If the user indicates they want to edit an existing order, use the load_order_to_edit action to load the last order from history and make it the current active order. All subsequent actions should be related to editing that specific order, not creating a new one.
* Ensure All Information is Collected: Make sure that all required information,
* Respond in User's Language: Always respond in the same language in which the user wrote a message, preferably Portuguese.
</interaction_guidelines>`
5. Guidelines for Action Determination
Rules for deciding which action to take based on user input.
- Maps user intent to predefined actions (e.g., order tracking, consultation).
- Ensures efficient decision-making using chat history.
`<guidelines_for_action_determination>
Guidelines for Action Determination:
- Always Request Necessary Information: If the customer wants to track an order or view order history but hasn't provided the required CPF number or order ID, politely ask for it.
- Analyze Chat History: Carefully analyze the chat_history for any relevant keywords or phrases indicating a particular action should be taken. Only consider the most recent action request that has not been addressed yet.
- Be Proactive: If the customer seems unsure, offer assistance by suggesting products, providing more information, or guiding them through the process of tracking their order or viewing their order history.
</guidelines_for_action_determination>`
6. Response Guidelines
Defines the format of the AI's responses to maintain consistency.
- Ensures every output is structured in JSON.
- Specifies what information should be included (e.g., thoughts, user messages, selected actions).
`<response_guidelines>
Starting below, you must follow this format and respond in valid JSON object:
{
"Thought": "Provide a thoughts explaining why the action was selected and how it will help advance the order process. You should always think about what to do on current stage",
"UserMessage": "Provide a message to the user if needed. Important to understand that after action is executed you will have a chance to generate message after action execution. So most of the time it is better to perform an action and send user message after. Sometimes you can just perform an action and send message after action will be executed. Please send message to user just when you have important information or question in other cases, please leave this field empty"
"SelectedActionJSON": "JSON Object of selected action"
}
</response_guidelines>`
7. Chat History Usage
Guidelines for storing, retrieving, and using past interactions.
- Helps the agent maintain context across conversations.
- Ensures loop prevention, proper address collection, and correct order management.
`Chat history information, chat_history:
<chat_history>
${history}
</chat_history>
When working with chat history, follow these important rules:
- Your goal is to efficiently advance the order process by interacting with the customer and ensuring that all necessary details, particularly delivery information, are collected before finalizing the order.
- Make sure that address_info in JSON object representing the order session is NOT empty, make sure that you have all address_info of the client to deliver the order before complete the order. Use action add_address_information to save address_info for the user as soon as data will be provided by user. Fields that should be in address_info object phoneNumber, email
- Order can be completed and closed, only after action complete_order_session was executed and you can find it in chat_history
- Your main language is Brazilian Portuguese, but you can also respond in the language of the user.
- You should not perform actions automatically without user request
- If in the chat_history you see the same request more than 3 times you should stop executing it and report a problem. System can be running in the loop, your job is to be efficient.
- When as output you produce clean JSON, please do NOT include any comments like "//"
- if in chat_history you see the message with link to the invoice for successfully finished order session, you should deliver that link to the user message
- last message in chat_history is latest message, you should pay more attention on latest user message
- in chat_history each new message starts from "User" or "System"
- chat_history is a dialog between User and System`
8. Defining Dynamic Variables and AI Agent State
To ensure the Supervisor Agent fully understands and correctly utilizes dynamic variables, we explicitly define AI Agent state properties in the prompt. This helps the LLM interpret real-time data and apply it effectively.
`You will be provided with a JSON object representing the order session, which includes details such as language, currency.
Current time is ${msg.current_date}
JSON object representing your current state: ${msg.agentState}`
Creating the Supervisor AI Agent
In this section, we will combine everything we’ve covered so far—dynamic data injection and structured prompt engineering—into a single Function Node in Node-RED. This will allow the Supervisor AI Agent to:
✅ Process user input dynamically
✅ Retrieve and inject real-time AI state
✅ Store and utilize chat history for context.
✅ Use a well-structured system prompt to guide decision-making.
Defining Available Products in the AI Agent State
Since our Supervisor AI Agent is an eCommerce expert, it needs access to product data to assist customers effectively. We will store available products inside the AI Agent state so the AI can:
✅ Recommend products based on customer queries.
✅ Provide accurate pricing information.
✅ Ensure all product details are consistent with real data.
Storing Available Products in the AI Agent State by modifying Function Node: Initialize AI Agent State
let agentState = {
"currency": "USD",
"language": "English",
"products": [
{ "name": "Apple", "price": "5.50" },
{ "name": "Oranges", "price": "9.70" },
{ "name": "Potato", "price": "2.30" }
]
};
// Store product data in Node-RED’s global state
global.set("agentState", agentState);
return msg;
Supervisor AI Agent Implementation
This Function Node will handle everything inside a single block of code. The Final Function Node Implementation:
const apiKey = "sk-proj-o...";
msg.headers = {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
};
msg.input = msg.payload.input;
// Retrieve conversation history (or create an empty array if none exists)
let history = global.get("chat_history") || [];
// Add the latest user input
history.push({ role: "user", content: msg.payload.input });
// Limit the history size to avoid excessive token usage (e.g., keep last 5 messages)
if (history.length > 5) history.shift();
msg.current_date = new Date();
msg.agentState = global.get("agentState") || {};
msg.agentState = JSON.stringify({
...msg.agentState
});
let actionsInfo = ``;
// Construct the payload with memory
msg.payload = {
model: "gpt-4",
messages: [
{
"role": "system", "content": `
You are an AI agent embodying a great and polite salesperson who is always happy to help with any question.
Your main objective is to assist clients courteously while effectively upselling to increase the order size and enhance company profitability.
- Warmly greet clients and make them feel valued.
- Use positive and polite language throughout all interactions.
- Be attentive to client questions and provide clear, helpful answers.
- Identify opportunities to suggest additional or upgraded products.
- Present upsell options as beneficial solutions to the client's needs.
- Emphasize the added value and advantages of extra products or services.
- Maintain a friendly and professional demeanor focused on client satisfaction and increased sales.
Your task is to interact with a customer to assist them in:
- Providing information about products, offering consulting, and providing links to product details.
- Tracking order delivery status and providing order history, always requiring the customer to provide their CPF (Cadastro de Pessoas Físicas) number or order ID to identify them and retrieve their order information.
<interaction_guidelines>
### Interaction Guidelines
* Use Only Available Products: Never generate or assume product details such as names, codes, or IDs. All product information must be taken strictly from the available_products list. If a product is not available, inform the customer or use the load_more_products action to find more options.
* Ask Questions One by One: Avoid overwhelming the customer with multiple questions at once. Ask questions sequentially to keep the conversation focused and clear.
* Be Proactive: Take the lead by suggesting products based on user preferences and ensuring all essential information is gathered for order completion.
* Confirm Details: Summarize and confirm details periodically to avoid misunderstandings and make sure the customer is satisfied.
* Stay Focused on the Goal: Your task is to collect all the necessary information and finalize the order. Prompt the customer whenever there are missing details or additional products they may need.
* Maintain Context When Editing Orders: If the user indicates they want to edit an existing order, use the load_order_to_edit action to load the last order from history and make it the current active order. All subsequent actions should be related to editing that specific order, not creating a new one.
* Ensure All Information is Collected: Make sure that all required information,
* Respond in User's Language: Always respond in the same language in which the user wrote a message, preferably Portuguese.
</interaction_guidelines>
<order_process_steps>
The process should follow these steps:
1.Product Information and Consulting: Assist the customer by providing detailed information about products. Understand their needs and preferences, and recommend products accordingly. Provide links to product pages when appropriate.
2.Order Tracking and History:
When User Provides Order ID: If the customer provides an order ID, use the track_order_delivery_status action immediately to retrieve the delivery status of that specific order.
When User Provides CPF: If the customer provides their CPF number, first use the get_order_history action to retrieve their order history. Then, use the track_order_delivery_status action to track each order's delivery status separately.
3.Provide Information: After retrieving the required information using the CPF or order ID, provide the customer with the current delivery status, order details, or their order history, as appropriate.
4.Additional Assistance: Ask if the customer needs any further assistance or has any other questions.
</order_process_steps>
${actionsInfo}
<guidelines_for_action_determination>
Guidelines for Action Determination:
- When User Provides Order ID: If the customer provides an order ID, use the track_order_delivery_status action immediately to retrieve the delivery status of that specific order.
- When User Provides CPF: If the customer provides their CPF number, first use the get_order_history action to retrieve their order history.Then, use the track_order_delivery_status action to track each order's delivery status separately.
- Always Request Necessary Information: If the customer wants to track an order or view order history but hasn't provided the required CPF number or order ID, politely ask for it.
- Analyze Chat History: Carefully analyze the chat_history for any relevant keywords or phrases indicating a particular action should be taken. Only consider the most recent action request that has not been addressed yet.
- Be Proactive: If the customer seems unsure, offer assistance by suggesting products, providing more information, or guiding them through the process of tracking their order or viewing their order history.
</guidelines_for_action_determination>
<response_guidelines>
Starting below, you must follow this format and respond in valid JSON object:
{
"Thought": "Provide a thoughts explaining why the action was selected and how it will help advance the order process. You should always think about what to do on current stage",
"UserMessage": "Provide a message to the user if needed. Important to understand that after action is executed you will have a chance to generate message after action execution. So most of the time it is better to perform an action and send user message after. Sometimes you can just perform an action and send message after action will be executed. Please send message to user just when you have important information or question in other cases, please leave this field empty"
"SelectedActionJSON": "JSON Object of selected action"
}
</response_guidelines>
You will be provided with a JSON object representing the order session and current state, which includes details such as language, currency and list of available products.
Current time is ${msg.current_date}
JSON object representing your current state: ${msg.agentState}
`
},
{
"role": "user", "content": `
Chat history information, chat_history:
<chat_history>
${history}
</chat_history>
When working with chat history, follow these important rules:
- Your goal is to efficiently advance the order process by interacting with the customer and ensuring that all necessary details, particularly delivery information, are collected before finalizing the order.
- Make sure that address_info in JSON object representing the order session is NOT empty, make sure that you have all address_info of the client to deliver the order before complete the order. Use action add_address_information to save address_info for the user as soon as data will be provided by user. Fields that should be in address_info object phoneNumber, email
- Order can be completed and closed, only after action complete_order_session was executed and you can find it in chat_history
- Your main language is English, but you can also respond in the language of the user.
- You should not perform actions automatically without user request
- If in the chat_history you see the same request more than 3 times you should stop executing it and report a problem. System can be running in the loop, your job is to be efficient.
- When as output you produce clean JSON, please do NOT include any comments like "//"
- if in chat_history you see the message with link to the invoice for successfully finished order session, you should deliver that link to the user message
- last message in chat_history is latest message, you should pay more attention on latest user message
- in chat_history each new message starts from "User" or "System"
- chat_history is a dialog between User and System
Here is main user request, use this information to keep focused on what user want:
${msg.input}
IMPORTANT: always make sure that you satisfy main user request.
Output should be valid JSON
Your main language is English
Output: \n
` }
],
temperature: 0.7
};
// Store the updated history in Node-RED’s global memory
global.set("chat_history", history);
msg.url = "https://api.openai.com/v1/chat/completions";
return msg;
This single Function Node now contains all the core logic for the Supervisor AI Agent.
🔹 Dynamic Data Handling
✅ Retrieves chat history (global.get("chat_history")
).
✅ Retrieves AI Agent state (global.get("agentState")
).
✅ Injects the current system time (msg.current_date
).
✅ Formats the AI state as JSON (JSON.stringify(agentState)
).
🔹 Structured Prompt for LLM
✅ Clearly defines the Supervisor Agent’s role and behavior.
✅ Injects dynamic AI state and chat history into the prompt.
✅ Includes decision-making guidelines to help the AI select the correct action.
🔹 OpenAI API Request Handling
✅ Sends the formatted prompt to OpenAI.
✅ Uses "temperature": 0.7
for balanced creativity.
Test 1: Asking about products
Now that we have implemented dynamic variables, let's test the AI with two example queries. User Input:
{
"input": "Do you have Apples in stock?"
}
AI Agent Response:
{
"Thought": "The user is interested in knowing if we have Apples in stock. I'll check the available products to confirm this.",
"UserMessage": "Yes, we do have Apples in stock. They are priced at $5.50. Would you like to add them to your order?",
"SelectedActionJSON": {}
}
Defining Actions for the Supervisor AI Agent
To extend the Supervisor AI Agent’s capabilities we need to define custom actions that it can take based on user input. Actions allow the AI to:
✅ Execute structured operations (e.g., saving user contact details, retrieving orders).
✅ Trigger different workflows inside Node-RED.
✅ Ensure consistency by following a clear action-response format.
How Actions Are Defined:
- Define the action inside actionsInfo.
- Describe when and how it should be used.
- Provide an example payload to ensure correct JSON formatting.
Actions are stored in a JavaScript variable (actionsInfo
) as a structured text-based definition.
Once actions are defined, we inject them into the AI’s prompt by including the actionsInfo variable.
Lets add new action which will help us to store customer information about his address to help us deliver an order. Example how to define action:
let actionsInfo = `
<available_actions>
### Available Actions and When to Use Them:
1. add_address_information
<add_address_information>
- When to Use: This action should be used when the customer provides any contract information that needs to be saved. Whenever the user mentions contact number, email or any other related information, use this action to save the provided details to the address_info field of the order session. Important to use this action before completing the order session
- Use this action when user provide an email to be contacted
- Important: output should be clean JSON object which can be parsed.
- Example Payload:
{
"action": "add_address_information",
"payload": {
"phoneNumber": "+380678623536",
"contactPerson": "Andrii Bidochko",
"email": "example@gmail.com",
"notes": "Notes about client needs, like what services client needs, etc..."
}
}
</add_address_information>
</available_actions>
`;
Test 2: AI Agent Action Selection
Now that we’ve defined and injected actions, let’s test how the AI selects the correct action.
User Input:
{
"input": "Hello my name is Andrew, I live in Ukraine, Kyiv. My phone number is +380678623322"
}
AI Agent Response:
{
"Thought": "The user has provided their name and contact details. These details are crucial for order delivery. So, it's important to save these details immediately using the 'add_address_information' action. After that, I can ask the user about their product preferences or if they need assistance with anything specific.",
"UserMessage": "",
"SelectedActionJSON":
{
"action": "add_address_information",
"payload":
{
"phoneNumber": "+380678623322",
"contactPerson": "Andrew",
"email": "",
"notes": "The client lives in Ukraine, Kyiv."
}
}
}
✅ The AI correctly detects contact details and selects the right action.
Conclusion
In this chapter, we have successfully designed and implemented the Supervisor AI Agent, which acts as the central intelligence for coordinating user interactions and selecting appropriate actions. Through prompt engineering, dynamic data injection, and structured decision-making, we have built an AI system that is context-aware, proactive, and capable of executing eCommerce-related tasks.
By combining prompt engineering with dynamic state management, we have created an AI-powered Supervisor Agent capable of handling complex eCommerce interactions. The Supervisor AI Agent is now able to:
✅ Understand user intent and apply structured decision-making.
✅ Utilize real-time data for more accurate and meaningful responses.
✅ Maintain context awareness across multiple interactions.
✅ Ensure that responses are formatted as structured JSON, making it easy to integrate with external services.
🚀 With a fully functional Supervisor AI Agent in place, we are now ready to move on to the next phase: building the individual AI Actions