Building Efficient AI Agents — Part 2: Technology Stack, Deployment Patterns & Cost
Choosing the stack and deploying it — with real cost figures rather than hand-waving.
This is the second installment of a four-part series:
- Part 1: The Mental Model & Core Architecture
- Part 2: Technology Stack, Deployment Patterns & Cost
- Part 3: Code Reference & Agentic Workflows
- Part 4: Security, Evaluation & Production Operations
Part III: Technology Stack
Section titled “Part III: Technology Stack”3.1 LLM Provider Decision Framework
Section titled “3.1 LLM Provider Decision Framework”| Provider | Tier | Best for | Key capability |
|---|---|---|---|
| OpenAI GPT-4o / GPT-5 | Closed | Complex reasoning, tool calling accuracy | Native tool calling, structured output, vision |
| Anthropic Claude Sonnet | Closed | Long context, instruction following | Extended thinking, computer use, MCP |
| Google Gemini 2.5 | Closed | Multimodal, large context | 1M token window, native Google Search |
| Meta Llama 3.x | Open | Self-hosted, cost optimization | Full weight access, fine-tunable |
| Mistral / Qwen | Open | Lightweight tasks, low latency | Efficient inference, low cost at scale |
Recommended strategy: Start with a closed LLM (OpenAI or Claude) to validate agent design. Use LiteLLM from day one so the provider is a config value, not a code dependency. Introduce open LLMs for auxiliary tasks (classification, extraction, summarization) once the core reasoning loop is stable.
3.2 Vector Store Selection
Section titled “3.2 Vector Store Selection”| Store | Deployment | Best for | Notes |
|---|---|---|---|
| ChromaDB | Local / embedded | Prototyping, single-process | No server setup; persist explicitly or lose data on restart |
| pgvector | Postgres extension | Production, existing Postgres infra | Lowest operational overhead if you already run Postgres |
| Qdrant | Dedicated service | High-throughput, rich filtering | Rust-based, excellent performance |
| Pinecone | Managed cloud | Fully managed, scale-out | No infra to operate; watch pricing at scale |
| Weaviate | Self-hosted / cloud | GraphQL API, hybrid search | Strong multimodal support |
Recommendation: pgvector for most production deployments. It collapses your session store and vector store into one Postgres instance, reduces operational surface area, and handles tens of millions of vectors adequately.
3.3 Framework Comparison
Section titled “3.3 Framework Comparison”Understanding the from-scratch primitives means you can read any framework’s source and immediately know what it is doing underneath:
| Pattern (from scratch) | LangGraph | CrewAI | AutoGen | Semantic Kernel |
|---|---|---|---|---|
| ReAct loop | Graph nodes | Agent tasks | AssistantAgent | Planner |
| ExecutionContext | State object | Crew context | Conversation | Kernel context |
| Tool abstraction | Tools / MCP | Tools | Function map | Plugins |
| Multi-agent | Graph edges | Crew roles | GroupChat | Agent collaboration |
| HITL | Interrupt nodes | Human input | Human proxy | Approval steps |
| Evaluation | LangSmith | Built-in metrics | Eval harness | Telemetry |
Part IV: Deployment Patterns
Section titled “Part IV: Deployment Patterns”4.1 Three-Tier Deployment Model
Section titled “4.1 Three-Tier Deployment Model”flowchart TD classDef dev fill:#e8f5e9,stroke:#2e7d32 classDef prod fill:#e3f2fd,stroke:#1565c0 classDef scale fill:#f3e5f5,stroke:#6a1b9a subgraph T1["Tier 1 — Development / Prototype"] D1["Single process<br/>Python + Jupyter"]:::dev D2["InMemorySessionManager"]:::dev D3["ChromaDB local"]:::dev D4["Direct LLM API calls"]:::dev D5["Search MCP server (npx)"]:::dev end subgraph T2["Tier 2 — Single-Server Production"] P1["FastAPI app server"]:::prod P2["Postgres + pgvector<br/>Session + vector store"]:::prod P3["Redis<br/>Session cache + task queue"]:::prod P4["Celery workers<br/>Async long-running agents"]:::prod P5["Nginx reverse proxy"]:::prod P6["Docker Compose"]:::prod end subgraph T3["Tier 3 — Distributed / Scale"] S1["Kubernetes<br/>Agent worker pods"]:::scale S2["Message queue<br/>RabbitMQ / SQS"]:::scale S3["Managed Postgres<br/>RDS / Cloud SQL"]:::scale S4["Managed vector DB<br/>Qdrant Cloud / Pinecone"]:::scale S5["API Gateway<br/>Auth + rate limiting"]:::scale S6["Observability stack<br/>OTel + Grafana / Datadog"]:::scale end T1 -->|"Validated agent design"| T2 T2 -->|"Multi-tenant / volume growth"| T3Move tiers only when forced: Tier 1 validates the agent design, Tier 2 serves real users on one machine with full observability, Tier 3 exists for multi-tenant scale. Most production agent systems live comfortably — and cheaply — in Tier 2.
4.2 Cloud Infrastructure Pricing Reference
Section titled “4.2 Cloud Infrastructure Pricing Reference”The following prices were sourced from live provider APIs (as of 2026-07-01). These are indicative list prices — not quotes. Verify against each provider’s pricing calculator before any commitment.
VM Compute — ~2 vCPU / 8 GB (per vCPU-hour, us-east, on-demand Linux)
| Provider | Service | $/vCPU-hour | Confidence |
|---|---|---|---|
| AWS | EC2 m5.large | $0.0480 | Live |
| Azure | D2s v5 | $0.0480 | Live |
| GCP | e2-standard-2 | $0.0335 | Live |
| Cloudflare | — | Unmapped | No equivalent VM offering — use Workers for serverless |
GCP is cheapest for VM compute at $0.0335/vCPU-hour on-demand. AWS and Azure are equivalent at $0.0480. Excludes reserved/committed-use discounts, attached storage, egress, and Windows licensing.
{"data":[{"type":"bar","x":["AWS EC2 m5.large","Azure D2s v5","GCP e2-standard-2"],"y":[0.048,0.048,0.0335],"marker":{"color":["#1976D2","#0288D1","#388E3C"]},"name":"$/vCPU-hour"}],"layout":{"title":"VM Compute — $/vCPU-hour (us-east, on-demand)","xaxis":{"title":"Provider / Service"},"yaxis":{"title":"USD per vCPU-hour"}}}Object Storage (per GB-month, Standard tier, us-east)
| Provider | Service | $/GB-month | Notes | Confidence |
|---|---|---|---|---|
| AWS | S3 Standard | $0.0230 | — | Live |
| Azure | Blob Hot LRS | $0.0208 | — | Live |
| GCP | Cloud Storage Standard | $0.0200 | — | Live |
| Cloudflare | R2 Standard | $0.0150 | Zero egress fees | Manual list |
Cloudflare R2 is cheapest at $0.015/GB-month, and critically charges zero egress fees — a significant advantage when agents frequently read stored documents or embeddings. Excludes request/operation charges, replication, and lifecycle transitions.
Serverless Functions (per 1M requests, after free tier)
| Provider | Service | $/1M requests | Confidence |
|---|---|---|---|
| AWS | Lambda | $0.20 | Manual list |
| Azure | Functions Consumption | $0.20 | Manual list |
| Cloudflare | Workers | $0.30 | Manual list |
| GCP | Cloud Run / Functions | $0.40 | Manual list |
AWS Lambda and Azure Functions are cheapest at $0.20/1M requests. All figures are invocation price only — excludes GB-second compute duration and egress; verify current pricing.
4.3 Reference Production Architecture — Monthly Cost Estimate
Section titled “4.3 Reference Production Architecture — Monthly Cost Estimate”A Tier 2 single-server production baseline for a moderately active agent deployment (~5M API gateway requests/month, 100 GB document/embedding storage, two compute nodes running 24/7):
| Component | Provider | Quantity | Unit | $/Unit | Monthly |
|---|---|---|---|---|---|
| Agent worker node | GCP e2-standard-2 | 1,440 vCPU-hrs | vCPU-hour | $0.0335 | $48.25 |
| API / orchestrator node | AWS EC2 m5.large | 1,440 vCPU-hrs | vCPU-hour | $0.0480 | $69.12 |
| Document + embedding store | Cloudflare R2 | 100 GB | GB-month | $0.0150 | $1.50 |
| API Gateway (Lambda) | AWS Lambda | 5M requests | per 1M | $0.20 | $1.00 |
| Infrastructure subtotal | $119.87 |
LLM API costs are not included above — they are the dominant variable cost. At GPT-4o pricing (~$2.50/1M input tokens, ~$10/1M output tokens), a moderately complex agent processing 10,000 tasks/month at ~5,000 tokens/task runs approximately $125–$300/month in LLM calls alone, depending on tool call depth. Use prompt caching aggressively — Anthropic and OpenAI both support it and can cut repeated-prefix costs by up to 90%.
Indicative, not a quote. Cloud list prices only; excludes committed-use/reserved discounts, support tiers, taxes, and egress. Verify against provider calculators before commitment.
← Building Efficient AI Agents — Part 1: The Mental Model & Core Architecture · Building Efficient AI Agents — Part 3: Code Reference & Agentic Workflows →