AI system design

Choosing an AI framework: requirements, evidence, and operating cost

By Anup RaiReviewed

Choose a framework by listing what the application must do. For example, a support agent that waits for a refund approval needs to save the proposed amount, resume after the approval, and check the amount again before paying. Compare frameworks on that complete flow, including what happens if the worker restarts.

A workflow framework can save where a refund job paused. The payment service checks whether the caller and order qualify for the refund before executing it.

Separate the categories

Category Main job Examples to evaluate Selection question
Model client or gateway Call models and normalize selected interfaces Provider SDKs, an application-owned adapter, a gateway Which differences should be abstracted and which must stay visible?
Agent runtime/orchestration Run tools, state transitions, handoffs, and loops LangGraph, Microsoft Agent Framework, CrewAI, agent SDKs How does execution stop, resume, and recover?
Retrieval/data framework Ingest, index, and retrieve evidence LlamaIndex or targeted retrieval components Does it improve this corpus's quality and lifecycle management?
Program optimization Search instructions, examples, or supported trainable components DSPy Is the evaluation objective good enough to optimize?
Observability/evaluation Inspect execution and measure behavior LangSmith or another suitable tracing/evaluation stack Can we diagnose failures and compare releases?
Coding product or coding-agent SDK Operate on repositories and development tools Claude Code, Cline, Cursor, OpenHands, other coding products Where does code execute and how are changes reviewed?
Hosted service/UI integration Operate a runtime or provide a product interface A managed agent service, ChatKit, plugin integration What does the service own, and what remains ours?

These categories overlap. A framework can provide both retrieval and workflows. Avoid invented “L1/L2/L3” tiers unless you explicitly define them for a specific diagram; they are not standard maturity levels.

Write the requirements first

For a learner-facing interview coach, an initial selection brief could be:

Functional requirements

  1. Retrieve relevant teaching material with source links.
  2. Review a submitted answer against a versioned rubric.
  3. Preserve progress across sessions.
  4. Let the learner inspect and correct generated feedback.
  5. Optionally hand off scheduling requests to an existing booking service.

Non-functional requirements

  1. Enforce learner and course-access boundaries.
  2. Meet separate latency targets for interactive help and longer reviews.
  3. Bound cost per completed review and handle provider limits.
  4. Recover persisted work without duplicating external actions.
  5. Export useful diagnostics and support a tested rollback.
  6. Fit the team's actual language, deployment environment, and maintenance capacity.

State measurable targets for the design. If you assume feedback must arrive within ten seconds, explain when the clock starts and how you would check whether learners can wait that long.

Begin with the smallest sufficient design

Architecture / visual model
flowchart TD A[Define task and constraints] --> B{Can ordinary code solve it?} B -->|Yes| C[Use ordinary code] B -->|No| D[One model call or bounded tool loop] D --> E[Evaluate representative failures] E --> F{Which capability is missing?} F -->|Data quality or retrieval| G[Evaluate retrieval components] F -->|State and recovery| H[Evaluate workflow runtime] F -->|Measured prompt quality| I[Evaluate optimization] F -->|No material gap| J[Keep the baseline] G --> K[Compare total behavior and operating cost] H --> K I --> K K --> L[Select and record an exit plan]
Read diagram source
flowchart TD
    A[Define task and constraints] --> B{Can ordinary code solve it?}
    B -->|Yes| C[Use ordinary code]
    B -->|No| D[One model call or bounded tool loop]
    D --> E[Evaluate representative failures]
    E --> F{Which capability is missing?}
    F -->|Data quality or retrieval| G[Evaluate retrieval components]
    F -->|State and recovery| H[Evaluate workflow runtime]
    F -->|Measured prompt quality| I[Evaluate optimization]
    F -->|No material gap| J[Keep the baseline]
    G --> K[Compare total behavior and operating cost]
    H --> K
    I --> K
    K --> L[Select and record an exit plan]

A thin implementation still needs timeouts, validation, telemetry, and error handling. A framework may reduce repeated work in those areas. Conversely, a framework that exposes ten features does not require using all ten.

Use a capability matrix, then test the claims

The following rows identify starting points for investigation. They are not exclusive assignments or performance rankings. The linked lessons include current primary documentation.

Candidate Capability worth evaluating Proof to request before choosing
LangGraph Explicit state, transitions, checkpoints, and interrupts Crash/resume, state migration, and effect-reconciliation exercise
LlamaIndex Document ingestion, indexing, query engines, and workflows Corpus-specific retrieval tests and revision/deletion handling
DSPy Composable model programs and optimization Held-out improvement under a fixed search and runtime budget
CrewAI Task-oriented crews inside controlled flows Routing, partial failure, termination, and persistence tests
Microsoft Agent Framework Agent/session/workflow integration Target-language support and compatibility with existing services
Claude Agent SDK Embedded coding/tool loop Deployment, permission, sandbox, and recovery behavior
OpenAI Agents SDK Application-run agents, tools, and handoffs Guardrail boundaries, continuation, and storage integration
Google ADK Agents and workflow/deployment integrations The exact feature in the selected language and hosting mode

Check whether a dependency still receives fixes and whether a hosted service will keep serving requests. Microsoft archived AutoGen and stopped maintaining it. OpenAI plans to shut down Agent Builder on November 30, 2026. The first calls for a supported replacement. The second gives you a deadline to export workflows and move execution. AutoGen · OpenAI deprecations · SDK comparison.

Compare three realistic candidates

For the coach, shortlist:

  1. Application code plus model client: a fixed retrieval/review sequence with ordinary service persistence.
  2. A retrieval framework plus application workflow: useful if document processing and query composition dominate development work.
  3. A stateful agent/workflow framework: useful if tasks branch, suspend, resume, or require sophisticated recovery.

Run the same tasks, model configuration where possible, evidence, and release criteria for all candidates. Include ordinary requests, missing evidence, malformed outputs, provider timeouts, cancellation, and access changes.

Dimension Measurement Common misleading substitute
Quality Task success and error severity on held-out cases A polished demo response
Latency End-to-end p50/p95 with concurrency and timeout rates One warm model call
Cost Total spend per completed task, including failed attempts Price per token alone
Recovery Correct outcomes after injected failures A “supports persistence” checkbox
Security Tests at actual data/action boundaries Presence of a guardrail API
Maintainability Time to diagnose, upgrade, and change one real flow GitHub stars or marketing adoption claims
Portability A working alternate provider/runtime path A shared method name

Apply required data boundaries before comparing convenience or cost. For example, if recordings must stay in an approved region, exclude options that send them elsewhere.

After eliminating infeasible choices, a weighted comparison can make preferences explicit. The weights and scores are judgments, not objective properties of libraries. Record the evidence behind them and check whether a small weight change reverses the decision.

Count the full cost

Use an explicit model:

total cost = implementation + maintenance + infrastructure + model/tool usage + observability + migration

For incident and vendor-change costs, record what could happen and use a range when you can estimate it. Mark unknown costs explicitly.

An illustrative first-year comparison:

Cost assumption Thin custom path Framework-assisted path
Initial engineering at an assumed $100/hour 100 hours = $10,000 40 hours = $4,000
Monthly maintenance at that rate 10 hours = $1,000 4 hours = $400
Additional monthly platform expense $0 $300
First-year subtotal for these components $22,000 $12,400

This example favors the framework only under the stated assumptions. It excludes common hosting and model costs. If an abstraction causes expensive retries or makes debugging much harder, the result can reverse. Use a small implementation to measure the work and model calls. Use the provider’s terms to price them.

Also compare costs per successful task. If two systems each spend $100, but one completes 80 tasks and the other 100, those observed costs are $1.25 and $1.00 per success. State whether success means an accepted answer, a confirmed business operation, or something else.

Build, adopt a framework, or buy a service?

Choice Benefit Responsibility retained Exit question
Build a thin layer Direct control and few abstractions Implement and maintain every required capability Is the custom surface small enough to sustain?
Adopt a library/framework Reuse components and execution machinery Deployment, domain correctness, versioning, operations Can application contracts survive a library replacement?
Buy a managed service Reduce selected operational work Data policy, integration correctness, product behavior Can state, traces, and artifacts be exported usefully?
Combine approaches Keep critical boundaries owned while outsourcing others Integration and failure handling between components Are there too many runtimes for the value delivered?

“Managed” does not mean all storage and tools are hosted. “Open source” does not mean every platform feature is free or that any model works well. Inspect the specific component and deployment option.

For example, OpenHands documentation distinguishes its software-agent components, browser client, managed service, and enterprise offerings. A blanket statement that it always requires self-hosting is inaccurate. Likewise, a coding product should be assessed as a particular interface and execution environment, not just a brand name.

Keep a practical exit path

For a multi-provider design, own the contracts that matter:

  1. Domain operations with typed requests, authorization, stable operation IDs, and explicit results.
  2. Evaluation datasets, scoring rules, and acceptance thresholds.
  3. Source content and its revision/permission metadata.
  4. Exportable conversation/workflow state where feasible.
  5. Traces and cost records tied to application task IDs.
  6. A tested fallback and rollback procedure.

A model adapter can normalize request shapes. It cannot make different models equally capable or reproduce provider-specific tools. A fallback may also move data to a different service; enforce the same application requirements before allowing it.

Use MCP or A2A when they solve a real integration boundary. For a single in-process service, an ordinary function may be simpler. Protocol compatibility does not remove differences in authentication, state, capabilities, or runtime behavior.

Keep coding tools distinct from the product runtime

Cline, Cursor, and other coding products can help build or operate on a repository. Some also expose SDKs, command-line interfaces, or remote execution. Decide which surface you are evaluating. The product once documented at Windsurf's entry point now has Devin Desktop documentation; verify current names and lifecycle instead of preserving an old brand comparison indefinitely.

For coding automation, evaluate repository isolation, command/network permissions, secret access, meaningful tests, change review, and reproducible environments. “Works with any LLM” is not a realistic promise of equal capability. The tool chosen to build an application need not be the runtime used to serve that application.

Decision record and interview practice

Close the selection with a compact record:

Field What to write
Decision Selected approach and the problem it solves
Alternatives Real candidates tested, including the baseline
Evidence Quality, recovery, latency, cost, and maintenance results
Accepted costs Specific limitations the team can tolerate
Review trigger A measurable change that warrants reconsideration
Exit path Contracts, data, and state needed to migrate
  1. Why not use the most feature-rich framework? Unused features do not solve a requirement and can add dependencies or complexity.
  2. Does DSPy guarantee 99% reliability? No. Optimization can improve a chosen empirical metric; the whole system must be evaluated under defined conditions.
  3. How do you choose between a retrieval framework and a workflow framework? List the missing operations, such as updating an index or resuming an approval. Test which candidate handles those operations and their failure cases.
  4. What evidence proves portability? Run the same representative tasks on a second configuration and verify that its outputs, permissions, and recovery behavior meet the requirements.
  5. When does managed hosting make sense? When its operational benefits exceed its cost and constraints, with acceptable data handling and an exit plan.
  6. Should every system implement MCP and A2A? No. Adopt a protocol for a concrete interoperability need.
  7. What is the strongest reason to change a working framework? A demonstrated requirement, support issue, or operating cost that the current choice cannot reasonably address.

Final notes

Recall card

Start with the required behavior. Build a small example, exercise its failure paths, and estimate its operating cost. Record what the framework handles, what the application must implement, and which evidence would change the decision.

Continue with coding-agent workflows or managing framework change.

Your notes

Write the decision you would make and the uncertainty you would investigate next. Saved only in this browser.

Explore the diagram