Best practices for AI agents

There's plenty of excitement about AI agents and agentic workflows, and for good reason. But actually building and deploying these systems effectively means going through some messy realities. Like for AI strategy in general, it's about making them work reliably and provide real value.

Understanding AI Agents and Workflows

First, let's nail down what we're talking about. You'll hear "agents" and "workflows" used, and it's important to distinguish them. Agents are systems where Large Language Models (LLMs) dynamically figure out their next steps and decide which tools to use. The ideal is a kind of digital autonomy. Workflows, on the other hand, are more predictable: LLMs and tools follow a predefined, coded path.

Then there are agentic workflows. These are sequences of connected steps, dynamically executed by agents to achieve specific goals. It’s a mix of guided structure and what we hope is intelligent, autonomous execution.

The reality today is that "dynamic execution" can be quite fragile, often relying on complex prompt engineering and control flow logic that looks a lot like sophisticated prompt chains trying to act like true planning.

For an agent to have a shot at being effective, it needs a few core components:

  • Reasoning capabilities: This means mechanisms (prompts + LLMs) for planning and reflecting on actions to improve.
  • Tool integration: Agents often need to interact with external functions or APIs.
  • Memory systems: Both short-term (for the current task, in context) and long-term (to retain learnings, via vector stores and RAG).

When Should You Use AI Agents?

The urge to build something complex and "agentic" is strong, but always start with the simplest solution. Agentic systems, with their potential for multiple LLM calls, can be slower, more expensive than simpler methods, and are more likely to fall off the rails. Increased complexity needs to deliver a comparative return on investment to be justifiable, so only do it when you have evidence it's necessary.

So, when might agents actually be worth it? They can be a good candidate for tasks where the steps cannot be reliably predicted in advance, problems that require adaptive decision-making based on unfolding information, and situations requiring iterative result refinement and a degree of self-correction.

Conversely, there are many scenarios where you should steer clear of agents. For simple, predictable tasks, a basic LLM call might do; don't build an agent to staple a piece of paper. They also might be too slow for time-sensitive applications (eg. interactive use cases) due to larger latency introduced by multiple, sequential LLM calls.

High-stakes decisions requiring absolute reliability are another area to avoid, due to inherent randomness of the LLMs being amplified by multiple agent interaction (this may be mitigating somewhat by putting human oversight into the loop). And, of course, keep an eye on the cost: higher cost of numerous LLM calls may significantly change the economics of your solution.

Common Design Patterns for AI Agents

With everyone jumping to build AI agents, some common approaches (best practices) are emerging. These patterns provide a starting point and you will probably want to mix and adapt them to your use cases.

Workflow Patterns

Workflow patterns are less autonomous, but more predictable, structured, reliable, and can be easier to build.

  • Prompt Chaining: Sequential LLM calls where outputs feed into subsequent inputs. Good for tasks with clearly defined sub-steps, like summarizing a document then extracting key entities.
  • Routing: An initial LLM call classifies the input and directs it to a specialized sub-task or a different, fine-tuned LLM. Useful for things like customer query classification.
  • Parallelization: Breaking a task into independent sub-tasks processed simultaneously, then aggregating results. Think RAG where multiple document chunks are processed at once, or exploring multiple potential problem-solving paths at once.

Agentic Patterns

Agentic patterns are more autonomous, adaptable and can be more capable. On the other hand, they're more complex, fragile, can go off the rails easier, and are harder to build and debug.

  • Planning (Orchestrator + Workers): A central "planner" LLM (the orchestrator) decomposes a task into dynamic sub-tasks for "worker" LLMs or tools, in multi-step reasoning. However, getting this right is tough. The planner might generate plausible-sounding plans that are actually suboptimal or that workers can't execute reliably.
  • Tool Use: The LLM invokes external functions or APIs, interacting with the outside world. Designing clear tool definitions here is crucial but challenging.
  • Reflection (Worker + Evaluator/Optimizer): An LLM (or a separate one) evaluates its own output and tries to refine it. This is useful for iterative improvement of the result. However, the evaluator may also confidently agree with a bad output or get stuck in a loop of minor, unhelpful changes.
  • Multi-Agents: Multiple agents with specific roles collaborate, ideal for highly complex tasks. While conceptually powerful, managing the interactions, communication, and potential for cascading errors between agents is a significant engineering challenge.

Implementation Best Practices

Here are some practical suggestions for implementing agentic systems:

  • Show the plan (if possible): If your agent has a planning step, making that visible to (or even editable by) the user helps with debugging and builds trust.
  • Give models room to "think": Encourage the LLM to think through before answering or invoking the tools.
  • Keep it simple and focused: The simpler and more straightforward the instructions, interactions and expectations, the easier and more reliable the agent will behave. Vague instructions increase the chance for random (and usually unintended) outcomes.
  • Clear tool definitions (with examples): The LLM needs to understand what tools it has and how to use them. Even then, expect it to get creative in ways you didn't anticipate. Avoid overly complex data structures for tool inputs and outputs.
  • Robust guardrails and oversight: Assume your agent will try to do something unexpected, wrong, or even harmful if given the chance. What happens when a tool call fails repeatedly? What if the agent gets stuck in a loop?
  • Design for failure: LLMs will get stuck. Tools will fail. APIs will error. Networks will glitch. Ensure your tools provide clear error feedback, and your agent has some strategy for handling these failures.
  • State Management: Pay attention to reliable agent state management (short and long-term memory) across potentially long-running tasks, tool calls, and failures.
  • Test religiously in sandboxed environments: Especially if tools can modify data or interact with the outside world.
  • Frameworks vs. Direct APIs: Frameworks (LangChain, LlamaIndex, etc.) can accelerate development for standard patterns but can also add abstraction layers that obscure problems or limit flexibility. Starting with direct LLM API calls can help you understand the core mechanics (and limitations) before you commit to a framework.
  • Define clear, measurable metrics: How do you know if your agent is working or improving? Test and measure to find out where your agent is slow, expensive, or unreliable. Track task completion, quality (if you can define it), cost, and latency.
  • Iterate, iterate, iterate: Tweak the prompts and tools to improve agent reliability and performance. This is often a painstaking process of trial, error, and relentless refinement. Plan to spend significant time tuning prompts and handling the LLM's often surprising interpretations of user intentions, or misuses of your tools.

Common Pitfalls to Avoid

If you build agents, you'll likely hit these.

Overengineering: The siren song of complexity. Building a sophisticated multi-agent system when a well-crafted prompt or a simple RAG pipeline would suffice is a common trap. Every layer of agentic behavior adds latency, cost, and fragility.

Inadequate Guardrails: Giving agents, especially those with powerful tools, too much autonomy without ironclad oversight is a recipe for disaster. This is where many promising agent projects go off the rails in practice. Assume the LLM will find a way to surprise you.

Misaligned Expectations: Agents are not magic. Expect a journey of iteration. The first (and often tenth) version will likely be slow, expensive, and make mistakes. The real question is whether you have the resources, patience, and a clear enough ROI to push through the debugging and refinement phase. Underestimating the stohastic, non-deterministic nature of LLMs is a classic blunder.

How to Evaluate Your AI Agents

Knowing if your agent is actually good is a major challenge. You'll want to track things like:

  • Task completion rate and perceived quality: Does it do the job? How well, according to your users or internal standards?
  • Efficiency: Time taken, LLM calls made, tokens consumed (which all translate to cost).
  • Adaptability to novel situations: How does it handle things it hasn't seen before?
  • Self-correction capabilities (if applicable): Does it fix/heal from its mistakes or just propagates/repeats them?

Actually measuring some of these consistently, like "adaptability" or "self-correction," is pretty challenging. You'll often rely on a blend of quantitative data (where possible), extensive human review, A/B testing, and even adversarial testing to get a true picture of performance and reliability.

Risk Assessment

Identify failure modes (brainstorm all the ways it could go wrong), then test them and evaluate consequences. When testing AI agents (and LLM-based systems more broadly), keep in mind these systems are non-deterministic. The AI agent may work correctly 95% of the time, but fail 5% of the time on the same instructions and input (same scenario).

What's the damage if it fails in each of those ways? For critical actions you'll want to put in checks, balances and human review steps. More autonomy often means more potential for things to go spectacularly wrong. Find the right trade-off between autonomy and system safety, that matches your specific risk tolerance.

Further reading

Agentic systems are powerful but difficult to build reliably. The industry is still new, common approaches are still emerging, and at the same time there's a lot of hype. This article is a result of extensive personal experience in building agentic systems, combined with the insight from many other practictioners, such as:

Looking for more insight or wondering how this might apply to your organisation?Reach out for a free 30-minute consultation.Get in touch