Search IOCombats

Search challenges, guides, questions and articles

Your TypeScript team is about to build its first AI agent. How would you choose an agent framework?

Intermediate12 min interview
Skills tested:
Turning product needs into framework requirementsKnowing what the AI SDK, Mastra, LangGraph.js and the OpenAI Agents SDK each focus onRunning a time-boxed spike to compare optionsIsolating a framework behind an internal interfaceConsidering team skills, hosting and vendor lock-in

Advertisement

🧩 Scenario

You lead a team of five React and Next.js engineers. Product wants an assistant in your SaaS dashboard that can look up account data, draft emails and, with user approval, change settings. A teammate wants LangGraph.js, another wants Mastra, and a third says "just use the AI SDK". The interviewer asks how you would make the decision.

Concept Walkthrough

Step 1: Write requirements before looking at libraries

Choosing a framework is like choosing a state manager. You would not pick Redux before knowing whether you need server cache, global UI state or both. For an agent, the questions are:

  • UI streaming: how do tokens, tool calls and approvals reach the React UI?
  • Tool calling and loop control: step limits, stop conditions, dynamic tools.
  • Human approval: can a run pause for the user and resume?
  • Memory and persistence: conversation history, user facts, resuming after a server restart.
  • Workflows: do you need fixed multi-step flows alongside the agent?
  • Observability: traces of each step, tokens and cost.
  • Models: one provider, or the freedom to switch?
  • Team and hosting: TypeScript fluency, serverless limits on run time, who maintains it.

Step 2: Know what each option focuses on

Keep this high level in an interview, and always check current docs because these libraries move fast:

  • Vercel AI SDK: a provider-agnostic toolkit. Strong on streaming and React hooks, with ToolLoopAgent, stop conditions and tool approvals. A good base when the frontend experience matters most.
  • Mastra: a TypeScript framework with agents, workflows and memory (including working memory and semantic recall) as first-class features.
  • LangGraph.js: models an agent as a graph of nodes and edges with persisted state, which suits long-running, resumable runs with human-in-the-loop interrupts.
  • OpenAI Agents SDK (@openai/agents): agents, handoffs between agents, guardrails, and tracing that is on by default in server runtimes like Node.js.

Step 3: Run a time-boxed spike

Build the same small agent (two tools, one approval step, streaming to a page) in your top two options. Measure: lines of code, how the stream reaches React, how approval feels, what a trace looks like, and how easy a failing run is to debug.

Step 4: Protect yourself from churn

Wrap the framework behind your own small interface, the same way you would wrap an analytics SDK. Components call assistant.run(), never the framework directly. If you switch later, you change one module.


Key Code Explained

// assistant/types.ts: the only thing the rest of the app imports
export interface AssistantRunner {
  run(input: { userId: string; prompt: string; signal?: AbortSignal }): Promise<{
    text: string;
    steps: number;
  }>;
}
// assistant/ai-sdk-runner.ts: one implementation behind the interface
import { ToolLoopAgent, tool, isStepCount } from 'ai';
import { z } from 'zod';
import type { AssistantRunner } from './types';
import { getAccount } from '../data/accounts'; // your own function

export function createAiSdkRunner(): AssistantRunner {
  return {
    async run({ userId, prompt, signal }) {
      const agent = new ToolLoopAgent({
        model: 'anthropic/claude-sonnet-5.5', // example id
        instructions: 'Help the user with their account. Be concise.',
        tools: {
          getAccount: tool({
            description: "Get the signed-in user's account summary.",
            inputSchema: z.object({}),
            // userId comes from your session, never from the model
            execute: async () => getAccount(userId),
          }),
        },
        stopWhen: isStepCount(6),
      });

      const result = await agent.generate({ prompt, abortSignal: signal });
      return { text: result.text, steps: result.steps.length };
    },
  };
}

For the spike, write a second file such as mastra-runner.ts or langgraph-runner.ts that implements the same AssistantRunner. Your test page and evals stay identical, so the comparison is fair. The interface is deliberately small: if a framework forces you to expose its own types to components, that is a signal about how much lock-in it brings.


Tradeoffs

OptionFocusGood whenWatch out for
No framework (AI SDK only)Model calls, streaming, tool loopsUI-heavy features, small teamsYou build memory, persistence and tracing yourself
MastraAgents, workflows, memory in TypeScriptYou want batteries included in TSAnother layer to learn and upgrade
LangGraph.jsGraph-based, persisted, resumable runsLong-running flows with interruptsMore concepts, graph modelling overhead
OpenAI Agents SDKAgents, handoffs, guardrails, built-in tracingTeams committed to OpenAICloser ties to one provider

What Interviewers Actually Check

  • Whether you start from requirements, not hype
  • Whether you consider "no framework" as a real option
  • Whether you think about how results stream to the React UI
  • Whether you plan a spike with measurable criteria
  • Whether you protect the codebase from framework churn

Follow-Up Questions

  1. Which requirement would push you from the AI SDK alone to LangGraph.js?
  2. How would long-running agent runs work on a serverless platform with execution time limits?
  3. How would you migrate from one framework to another without breaking the UI?
  4. What would you look for in a framework's release notes before upgrading?
  5. How would you compare tracing across two frameworks during the spike?

Common Candidate Mistakes

  • Naming a favourite framework without asking what the product needs.
  • Comparing frameworks by GitHub stars or blog posts instead of a working spike.
  • Forgetting streaming, approvals or persistence until after the choice is made.
  • Exposing framework types throughout components.
  • Treating the decision as permanent instead of reversible.

Interview Readiness Checklist

Before you leave this question, make sure you can answer:

  • Can you list the requirements that decide a framework choice?
  • Can you describe what the AI SDK, Mastra, LangGraph.js and the OpenAI Agents SDK each focus on?
  • Can you argue for starting with no framework?
  • Can you design a two-day spike with clear criteria?
  • Can you write a small interface that hides the framework?

Summary

Choose an agent framework the way you choose any core library: requirements first. List what you need for streaming, tools, approvals, memory, persistence, tracing and model choice. Many teams can start with the AI SDK and plain TypeScript, then adopt Mastra, LangGraph.js or the OpenAI Agents SDK when their specific strengths are needed. Run a short spike of the same agent in two options, measure what matters to your product, and keep the framework behind your own interface so the decision stays reversible.

Frequently Asked Questions

Do I need an agent framework at all?

Not always. Anthropic's "Building effective agents" post suggests starting with LLM APIs directly, because many patterns take only a few lines of code and frameworks can hide the actual prompts and responses. A framework earns its place when it gives you things you would otherwise build yourself, such as persistence, approvals and tracing.

Is the Vercel AI SDK an agent framework?

It is a TypeScript toolkit for calling models, with an agent class (ToolLoopAgent), loop control, tool approvals, and React hooks for streaming chat UIs. For many product features that is enough. Frameworks like Mastra add higher-level building blocks such as memory and workflows on top.

Does choosing a provider's SDK lock me in?

It can. The OpenAI Agents SDK, for example, is built around OpenAI models and its tracing, although it documents support for other models. Weigh that against your plans, and keep model ids and framework calls behind your own module either way.

Advertisement


Stay Updated

Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.

Namaste Dev
Sponsored

Cohort-style courses to go from tutorials to job-ready.

Explore Courses

Advertisement