The Trap of the Single Prompt
Most developers start their AI journey by building a 'wrapper'. You take a user input, wrap it in a system prompt, send it to an LLM, and return the result. If the result is wrong, you try to 'prompt engineer' your way out of it by adding more instructions to that single prompt.
This is a dead end. No matter how good your prompt is, LLMs struggle with complex tasks in a single pass. They hallucinate, they skip steps, and they fail to double check their own work.
Agentic workflows are different. Instead of one long prompt, you break the task into a loop of smaller, specialized steps where the LLM can reason, act, and correct itself.
From Linear to Iterative
In a standard chatbot, the flow is: User -> Prompt -> LLM -> Output.
In an agentic workflow, the flow looks more like: User -> Planner -> Executor -> Critic -> Refiner -> Output.
Think of it like a professional software project. You do not just write 1,000 lines of code in one go and push to production. You write a draft, you run tests, you find bugs, and you fix them. That is exactly how you should structure your LLM calls.
Three Patterns That Actually Work
1. The Reflection Pattern
This is the simplest agentic move. You ask the LLM to generate a response, and then you send that response back to the LLM (or a different model) with a prompt like: "Review the response above for technical errors or missing requirements. List the flaws."
Once you have the critique, you send both the original response and the critique back to the model to generate a final version. This almost always produces a higher quality result than a single prompt, especially for coding tasks.
2. Tool-Use Loops (ReAct)
Instead of hoping the LLM knows the answer, give it tools. A tool is just a function the LLM can choose to call.
The pattern works like this:
- The model thinks about what it needs (Thought).
- It decides which tool to call (Action).
- Your code executes that tool and feeds the result back to the model (Observation).
- The model repeats this until it has enough information to answer.
This prevents the model from guessing. If it needs a current stock price or a specific database record, it fetches it rather than hallucinating a plausible-looking number.
3. Multi-Agent Delegation
When a task is too large, a single agent gets confused. The context window gets cluttered with irrelevant details. The solution is to split the roles.
Create a 'Manager' agent that breaks the goal into sub-tasks. Then, assign those tasks to 'Worker' agents. For example, one agent handles API documentation, another handles implementation, and a third handles testing. The Manager collects the outputs and ensures they align.
The Hard Part: State Management
Moving to agentic workflows introduces a new problem: state. You are no longer managing a single request, but a conversation history that includes thoughts, tool outputs, and critiques.
If you do not manage this carefully, your token costs will explode, or the model will lose the original goal. I recommend using a structured state object (like a JSON store) rather than just appending everything to a chat history string. Keep track of:
- The original goal
- The current step in the plan
- The history of tool calls
- The latest critique
Concrete Takeaway
Stop trying to write the 'perfect prompt'. It does not exist.
If your LLM is failing at a task, do not add more adjectives to the prompt. Instead, split the task into two steps: one to generate a draft and one to critique it. Then, feed that critique back in for a second pass.
Moving from a linear pipeline to an iterative loop is the single biggest jump in quality you can make in AI development.
Top comments (0)