Перейти до основного вмісту

The Classic Test Agent Flow

This document provides a detailed breakdown of the "Classic Test Agent" flow. This flow is a simple yet powerful tool designed for developers to run quick, ad-hoc tests on a Knowledge Base Agent directly within the Node-RED editor, without needing the full Opik.

Purpose

The primary purpose of this flow is to perform a simple regression or functionality test. It allows a developer to define a list of test questions, run them through an agent one by one, and see all the final answers in a clean, aggregated list. It's ideal for:

  • Quickly verifying that an agent is responding.
  • Testing changes to an agent's prompt or logic.
  • Spot-checking the agent's answers for a small, curated set of questions.

Prerequisites

Before running this flow, you must ensure that your Node-RED global context is configured with the necessary credentials and settings that the agent subflow requires. This flow will pull the following variables from the global context:

  • openaiKey: Your API key for the language model.
  • chroma_link: The connection path for your ChromaDB instance.
  • DATABASE (optional): An object containing database configuration.
  • AI_SETTINGS (optional): An object containing default AI settings.

For details on how to set these, refer to the "Configuring Global Environment Variables in Node-RED" guide.

How It Works: A Step-by-Step Breakdown

The flow operates in three distinct stages: Load, Process, and Display. You can download this Node-RED flow here. (Right-click and "Save link as..." to download)

Classic Test Agent Flow

Step 1: Load Test Data

This stage prepares the list of questions for the test run.

  • Start Test Run (Inject node): The entire flow is initiated by a manual click on this button. It has no payload; its only job is to start the process.
  • Load Test Questions (function node): This is the heart of the test data. It contains a hard-coded array of strings, where each string is a question you want to ask the agent. It then places this array into msg.payload to be sent to the next stage.

Step 2: Run Agent for Each Question (The Processing Loop)

This stage iterates through the questions and gets an answer for each one.

  • Split Questions: The list of questions is fed into a Split node, which breaks the array into a sequence of individual messages. Each message contains a single question, allowing the flow to process them one at a time.
  • Format Agent Payload: This crucial function node acts as an adapter. It takes the simple question string and transforms it into the complex JSON object that the "Knowledge Base Agent V3" subflow expects as its input. It enriches the question with all the required credentials and configuration pulled from the Node-RED global context.
  • Knowledge Base Agent V3: This is the agent being tested. Each individual question is sent to this subflow, which performs its internal logic (querying ChromaDB, calling the LLM) and produces a final answer.
  • Format for Join: Before finishing, this simple function node cleans up the output. It creates a simple object { "question": "...", "answer": "..." } to make the final aggregated result easy to read.

Step 3: Aggregate & Display Results

This final stage collects the results and presents them to the user.

  • Join Results: This Join node is the counterpart to the Split node. It waits until it has received a message for every single question that was sent. Once the specified count is reached, it combines all the individual result objects into a single, clean array.
  • Final Test Results (Debug node): The final array of question-and-answer pairs is sent to the Node-RED debug sidebar for you to inspect.

Advanced Usage & Customization

This flow is designed to be easily modified. Here are the most common ways to customize it for your needs.

1. Editing the Test Questions

This is the most frequent customization. To change, add, or remove test questions, simply edit the "Load Test Questions" node.

Location: Classic Test Agent -> 1. Load Test Data -> Load Test Questions

Action: Modify the questions array inside the node.

const questions = [
// Add your questions here as strings
"How do I create a Kubernetes cluster?",
"What are your cheapest VPS options?",
"What is the conflict of interest policy for employees?"
];
  • ⚠️ IMPORTANT: After changing the number of questions, you must update the "Join Results" node. Double-click it and set the Count property to match the new number of questions in your array. If you don't, the flow will either finish too early or wait forever.

2. Testing a Different Agent

The flow is modular, allowing you to swap out the agent being tested.

Location: Classic Test Agent -> 2. Run Agent for Each Question

Action:

  • Delete the existing "Knowledge Base Agent V3" subflow node.
  • Drag your own agent's subflow into its place and connect it in the flow.
  • Crucially, you must then edit the "Format Agent Payload" node to match the specific input msg.payload structure that your new agent requires.

3. Changing Global Configuration

This flow does not contain any hard-coded keys or secrets. It relies entirely on the Node-RED global context. To run this flow in a different environment or with different credentials, you only need to adjust the global variables (openaiKey, chroma_link, etc.) in your Node-RED instance. No changes to the flow itself are needed.