Creating a Simple Reflex AI Agent

According to ChatGPT “A Simple Reflex Agent is the most basic type of AI agent. It makes decisions based purely on the current perception (input) without considering past experiences or future consequences.”

In normal workflow language, a Simple Reflex Agent can be compared to a Basic Decision Tree or a Rule-Based System. You can think of it as a series of if-then prompts, or steps that are followed sequentially.

When Would You Use a Simple Reflex AI Agent?

Before AI was a “thing” many companies built bespoke integrations to carry out simple, repetitive tasks such as:

  • Reading a file from a shared drive and entering the data into a business system
  • Processing incoming emails and direct to the correct user based on set rules
  • Syncing records between business system when certain actions are completed

Some software products also have workflow engines that can perform similar tasks, although they are often restricted to data that resides in the same system. One example of this is an approvals workflow for new hires in a HR system.

How does AI Improve Basic Decision Trees?

Adding AI into the workflow, or decision tree equation gives a lot more flexibility than the hard-and-fast rules required when coding an integration with traditional tools. For instance, the natural language processing provided by a large language model means that the steps can be written in an easy-to-understand manner.

How Do You Build a Simple Reflex AI Agent

You build a Simple Reflex Agent by linking standard Chat Completion prompts together. The first step feeds its response to the next step as an input to be used in the prompt, and the process continues, until all the steps are completed.

You can use a number of tools to perform this task, but in this demo, we’re going to build on the HTTP endpoints we’ve used in previous posts, such as the First Look at Alibaba’s Qwen API – AI Solutions That Listen, Learn, and Deliver.

We’re also building the user interface using the cool, no-code service called Bolt.new.

Add Your API Key

To use the API you’ll need an API key for either DeepSeek or Qwen, which you can enter by toggling the settings cog at the top of the page. Don’t worry, we don’t save the API, we just send it along with the prompt to the Chat Completions API endpoint.

There is also a toggle to hide the prompt request and response, should you wish to have a cleaner UI.

Decide on the Questions You Need to Ask.

The first step is to outline what questions you’ll need to answer to get the final response. In our demo, we’ve used the highly contrived example of working out is a country flag shares the same colour as the Australian flag. Yes, I know what you’re thinking. How on earth did you live without this tool before.

Step 1

Create a prompt that determines the primary colour of the country’s flag. We only want to colour, not a massive explanation, so we include a restriction in the prompt to ensure only a one-word answer is provided.

The user will give you the name of a country: {userInput}. You are to respond with the name of the primary colour of that country’s flag. Respond with one word only.

Step 2

We take the response from Step 1 and ask if that colour is also in the Australian flag.

Is {previousOutput} in the Australian flag? Answer with only true and false.

Adding Conditional Logic

To demonstrate an if-then, we’re going to restrict the response to true or false and perform different actions depending on the response.

You could basically prompt for anything in the True/False branches, so we’re just asking random, follow-up questions.

True

Explain why {userInput} share the same colour as the Australian flag.

False

Explain the importance of the colours in the flag of {userInput}.

In the True/False branch prompts we also refer to the user’s original input – a name of a country.

Try it Out

We’ve deployed the for this demo to Netlify, so you can take a look at it for yourself.