KatInterview

Building a Production LLM Agent with Tool Access and State

Machine LearningModel answer
MediumModel answerMachine Learningllm-agentssystem-designproduction-ml

Last updated

Design a production system where an LLM agent uses external APIs to complete multi-step tasks, handling state, failures, security, and evaluation.

You're building a production system where an LLM acts as an autonomous agent, calling external APIs and services to accomplish business tasks. The agent might query databases, retrieve documents, create support tickets, send messages, or trigger workflows.

Your system needs to handle:

  • Employees using the agent for tasks ranging from quick lookups (seconds) to multi-day workflows with human approvals
  • Around 50,000 users with peak load of 200 concurrent tasks
  • Each task involves 8–15 API calls on average
  • Enterprise requirements: audit logs, access control, data residency, cost control

Address these design areas:

  1. Failure modes: What are the primary ways tool-using agents fail in production, and how do you mitigate them?

  2. State management: How do you handle complex state across long-running tasks that may pause for hours, branch into alternatives, or need to resume after interruption?

  3. Evaluation: How do you measure whether the system is working correctly, both during development and in production?

Provide a system architecture and explain your choices around safety, observability, and reliability.

Hints

Hint 1

Think about what happens when the LLM picks the wrong tool, hallucinates parameters, or loops forever—architectural safeguards beat better prompts

Hint 2

Long-running workflows need durable state outside the LLM context; consider event sourcing and checkpoints so tasks survive restarts

Hint 3

Security is critical: the agent should never have more permissions than the user who invoked it, and all tool outputs should be treated as untrusted