Skip to main content
AI Solutions
Production
Best Practices

Building AI agents for production: what we've learned

Lessons from shipping AI agent systems that handle real workflows in production environments.

Sphere Techlabs TeamEngineering(updated )3 min read

We have built AI systems that run in production for three clients: an onboarding workflow for a B2B SaaS platform, a claims document pipeline for an insurer that handles thousands of documents a month, and a document assistant for a finance team that handles hundreds a day. This is what that work taught us about the gap between a demo and an AI system people rely on.

Production AI is different from demos

AI demos on social media look effortless. But production AI agents need to handle edge cases, maintain consistent performance, integrate with existing systems, and fail gracefully when things go wrong.

In our projects the larger share of the work has been outside the model. It is the infrastructure, error handling, monitoring and integration that make a system reliable enough for real users.

Key technical challenges

Here are the challenges that matter most in production:

  • Latency management: Users won't wait 30 seconds for LLM responses. We use streaming, caching and parallel processing so that responses arrive fast enough for people to keep using the tool.
  • Error handling: LLMs fail in unpredictable ways. We build validation, retry logic, and fallback mechanisms so one bad response doesn't break the entire workflow.
  • Cost control: Running the largest model on every request adds up fast. We use smaller models where possible, implement smart caching, and batch operations to control costs.
  • Prompt stability: Prompts that work today might fail tomorrow as models update. We version prompts, test extensively, and monitor output quality continuously.
  • Context management: Long context windows have not removed the problem. Sending everything is slow and costly, so we select what is relevant and keep state across turns.

Architecture patterns that work

After building several systems, we've converged on some patterns that work well:

Fixed workflows with one narrow step per task, and an agent only where the path cannot be known in advance. Each step can be tested alone.

Human-in-the-loop workflows for high-stakes decisions. In our insurance document project, 95% of documents are processed without manual data entry, and low-confidence extractions go to a person with the context needed to review them.

Extensive logging and observability. We log prompts, responses, decision points and errors, within what the client's data rules allow. This data is invaluable for debugging, improving prompts, and measuring system performance over time.

Testing AI systems

Traditional testing approaches don't work well for AI systems because outputs are non-deterministic. We use several strategies:

Golden dataset testing with example inputs and expected outputs (allowing for semantic similarity rather than exact matches).

Property-based testing that verifies outputs meet structural requirements even if content varies.

A/B testing in production with careful rollout and metrics monitoring.

Continuous evaluation where we sample production outputs and grade them (sometimes with another LLM, sometimes with human reviewers).

When AI fits, and when it does not

Not every problem needs AI. We've found AI agents work best when:

The task requires understanding unstructured data (documents, emails, free-text)

Perfect accuracy isn't required (or humans aren't perfect either)

The cost of mistakes is low or there's human oversight

Traditional rule-based systems would be too complex or brittle

For deterministic tasks, structured data processing, or cases where mistakes are unacceptable, traditional software is usually better.

Workflow or agent?

In a workflow, your code fixes the order of steps and the model handles one narrow step at a time. In an agent, the model decides which tools to call and in what order. Anthropic's own guidance is to start with the simplest option that works, because agents trade latency and cost for flexibility.

The short version

Building production AI systems is mostly ordinary engineering. It requires thinking about reliability, cost, monitoring, and integration, all the same concerns as traditional software systems. The model is the smaller part of the work, and it's the infrastructure around it that determines whether your system actually ships and stays running.

Sources

  1. Anthropic: Building effective agents

Working on something like this?

Tell us what you are building or fixing. An engineer will reply with how we would approach it.

Start a conversation

A reply within 24 hours. Or email service@spheretech.dev