Key Benefits
- Testing Flexibility. Replace any Node’s output or function without changing Flow paths or production logic. To change the Node’s behavior, you can just activate mocking and add mock code.
- Cost Savings. Run simulations with lower costs or less time by mocking data to avoid sending HTTP or LLM requests.
- Consistent Testing Interactions. Control interactions for AI Agent testing by mocking LLM responses with deterministic data.
Restrictions
- If you activate mocking for a Node that has child Nodes, for example, the Then and Else Nodes of an If Node, the child Nodes aren’t executed. However, you can use mocking on child Nodes.
How Mocking Works
Mocking provides the Mock Code field to every Node’s settings in the Node editor. This field supports JavaScript code to access the Input, Context, and Profile objects, andapi.say function. The mock code entirely overrides the configured Node’s execution logic at run-time. With the Mock Code field, you can mock:
- The AI Agent output, for example,
api.say("Are there any requirements for the drilling machine?"). - User input and data, and third-party requests, by storing data in:
- the Input object, for example,
input.text = "I would like to buy a drilling machine". - the Context object, for example,
context.selectedProduct = "Drilling machine". - the Profile object, for example,
profile.name = "John Doe".
- the Input object, for example,
How to Use Mocking
To use mocking, you need to activate it at:- the Node level. Enter the mock code to replace the Node’s logic.
- the interface level. You can use the following interfaces to run tests with mock code:
Activate Mocking
At the Node Level
At the Node Level
- Go to Build > Flows, select the Flow you want to test.
- Right-click the Node you want to mock a behavior for and select Enable Mocking. The
icon appears next to the Node to indicate that the Node logic is replaced by the mock code.
- Click the Node. The Node editor opens.
- In the Mocking section, enter the mock code in the Mock Code field, for example,
api.say("Are there any requirements for the drilling machine?"). Save the Node.
At the Interface Level
At the Interface Level
- Interaction Panel
- Simulator
- Endpoints
- In the upper-right corner, click
to open the Interaction Panel.
- Click the Settings tab and toggle on the Enable Mocking setting in the Advanced section.
Deactivate Mocking
If you want to deactivate mocking, you can deactivate at:- the Node level. Switches the individual Node execution logic back to the original Node settings.
- the interface level. Switches the Node execution logic of all Nodes with mock code.
At the Node Level
At the Node Level
- Go to Build > Flows, select the relevant Flow.
- Right-click the Node you want to deactivate mocking for and select Disable Mocking.
At the Interface Level
At the Interface Level
- Interaction Panel
- Simulator
- Endpoints
- In the upper-right corner, click
to open the Interaction Panel.
- Click the Settings tab and toggle off the Enable Mocking setting in the Advanced section.
Examples
The following examples show how to use mock code in different cases.Mock a User Response
Mock a User Response
To test how your AI Agent performs when it receives a predefined response from the user to a Question Node, you can mock the response. Consider you have a Question Node that stores the user’s response in
input.result. Follow these steps:- Right-click the Question Node you want to mock a behavior for and select Enable Mocking.
- Open the Node editor and enter the code to mock the user’s response, for example:
Mock an AI Agent Response
Mock an AI Agent Response
To test a predefined response instead of an LLM-generated response, for example, from an LLM Prompt Node, follow these steps:
- Right-click the LLM Prompt Node you want to mock a behavior for and select Enable Mocking.
- Open the Node editor and enter the code to mock the AI Agent’s response, for example:
Replace Costly Requests
Replace Costly Requests
Your Flow may contain HTTP or LLM requests that may incur costs or take a long time to complete. These requests could cause issues if you test your AI Agent with frequent simulations. To avoid these issues, you can mock a request during the simulations, for example, in an HTTP Request Node. Consider an HTTP Request Node that retrieves information about a movie from the OMDB API database and stores it in the Input object under
input.movie. You can mock the request of the HTTP Request Node with a predefined response. To do so, follow these steps:- Right-click the HTTP Request Node you want to mock a behavior for and select Enable Mocking.
- Open the Node editor and enter the mock output in the Mock Code field, for example: