Improving AI Agent Decision-Making with Workflow Tags and JSON
Last updated
Last updated
If you are working on AI agents for conversations and running into issues with decision-making, especially as the number of instructions grows, here is a great framework to follow:
The agents forget, mix up, or misorder tasks, and while better prompting (like decision-tree styles) helps a little, it’s not enough for complex workflows with tens or hundreds of instructions. You’re asking how we solve this, and I’m happy to share an approach that’s been working well for us.
Instead of relying solely on prompts, we use a system with workflow tags and structured JSON objects to guide the AI step-by-step. This keeps things organized and prevents confusion, even with lots of instructions. Here’s how it works in a clear, practical way:
1. Create Workflow Tags for Different Tasks
We define specific tags to represent the types of tasks the AI needs to handle. For example:
book_ticket: For booking a flight.
cancel_order: For canceling a customer’s order.
Each tag is like a label that tells the AI what kind of job it’s dealing with.
2. Build a JSON Structure for Each Tag
For every workflow tag, we set up a JSON object in our database that lists the information the AI needs to collect. The keys are the required details, and the values start empty. For example, here’s what the JSON for book_ticket might look like:
This acts like a checklist the AI fills out as it talks to the user.
3. Assign Tags to Users Based on Their Needs
During the conversation, the AI listens to what the user wants and assigns the right workflow tag. For instance:
If the user says, “I want to book a flight,” the AI maps them to the book_ticket tag.
This step is key—it tells the AI which “checklist” to focus on.
4. Fill in the JSON Step-by-Step
Once the tag is assigned, the AI’s job is to gather the missing info by asking questions like:
“What’s your name?”
“Which airport are you flying from?”
“When do you want to leave?”
As the user answers, the AI updates the JSON. For example, after the user says “John” and “JFK,” it might look like:
The AI keeps going until every field is filled.
5. Finish and Move On
When all the values in the JSON are completed, the workflow is done. The AI can then:
Process the task (e.g., book the ticket).
Remove the book_ticket tag from the user.
If the user has another request (like canceling an order), the AI assigns a new tag and starts over.
Why This Works
Keeps Things Organized: Breaking tasks into small, clear steps prevents the AI from getting overwhelmed.
Tracks Progress: The JSON shows what’s done and what’s left, so the AI doesn’t repeat or forget steps.
Scales Well: Even with hundreds of instructions across different workflows, the AI stays focused because it only deals with one tag at a time.
How It Helps Your Case
Since your agents struggle with forgetting or mixing up instructions, this method offloads the complexity from the prompt to a structured system. The AI doesn’t have to “remember” everything—it just follows the JSON checklist and updates it as it goes. We store these workflows in a database, so the agent can always check what’s next.
This has been a game-changer for our agents, and I think it could help you too. Let me know if you’d like more details on setting it up!