AI Agent Development — Level 3: Production Agents, Evaluation, Security & Multimodal
Get Started Free
Free preview
Agent service architecture
Lecture notes
A demo agent runs in a notebook; a production agent must serve many users, survive failures, protect data and stay within budget.
Typical architecture
- Client (web, mobile, WhatsApp bot) → API layer (FastAPI, Express, Laravel) with authentication, rate limiting and input validation.
- Agent workers that run the loop and call the LLM API and tools.
- Stores: conversation/session state (PostgreSQL, Redis), vector store for RAG, object storage for files, a checkpoint store for resumable runs.
- Tool services (often MCP servers) with their own permissions.
- Observability: tracing, metrics, logs.
Handling long-running tasks
- HTTP requests time out (often 30–60 s; proxies may cut earlier). Agents that research or process documents can take minutes.
- Put work on a queue (Redis/RQ, Celery, BullMQ, SQS, Laravel queues) and process with background workers; return a job ID immediately.
- Notify completion with webhooks, push notifications or WhatsApp messages, or let clients poll a status endpoint.
- Durable execution engines (Temporal, Inngest, Restate, LangGraph checkpointers, cloud workflow services) persist each step so a crash resumes from the last completed step instead of restarting — and avoid repeating side effects.
- Make tool actions idempotent (use idempotency keys for payments and messages) so retries do not charge twice.
Streaming and user experience
- Stream tokens with server-sent events (SSE) or WebSockets so users see progress immediately.
- Show intermediate steps ("Searching the catalogue…", "Checking seats…") for transparency.
- Allow cancellation and clear error messages; never leave users waiting silently.
Resilience
- Retries with exponential backoff and jitter for rate limits (HTTP 429) and overloads (529/503).
- Timeouts on every model and tool call.
- Fallbacks: alternative model or provider, cached answer, or graceful degradation ("I can't check seats right now; here is the WhatsApp number").
- Circuit breakers stop calling a failing dependency for a while.
Want to go further?
20 h · Enroll to access every lesson and earn the certificate.