DEV Community

TypeScript AI Agents: Framework vs. Raw API Calls

In 2026, the question isn't whether your team will build AI agents. According to McKinsey's State of AI 2024 report, 72% of organizations now use AI in at least one business function, up from 50% in previous years.

The question is how you wire them together without creating a maintenance nightmare six months later. For TypeScript teams specifically, two paths have emerged: reach for a dedicated agent orchestration framework, or build directly against the raw LLM API. Both work. Neither is obviously correct. The choice depends on what you're optimizing for.

I've built both. We shipped our first Autonomous SDR using a flat 3-agent architecture where research, scoring, and writing all reported to a single orchestrator. It worked on 5 leads. At 50, the scorer sat idle waiting on research that had nothing to do with scoring. Splitting into discrete agents with explicit handoff contracts between them cut processing time and made each component independently testable.

That experience shaped how we think about agent architecture now: implicit data passing between components doesn't hold up when volume increases. Every pipeline we build today uses explicit inter-agent schemas for exactly that reason.

Approach A: Dedicated Agent Frameworks

A dedicated TypeScript agent framework, whether purpose-built for a specific reasoning API or a general orchestration tool, gives you scaffolding for the patterns that every agent build eventually needs: tool registration, context window management, retry logic, and structured handoffs between components.

The concrete benefit is speed on the first build. Tool definitions, prompt templates, and memory management come pre-wired. A developer who has never shipped an agent can have a working prototype in a day rather than a week. For startup CTOs evaluating whether agent-based automation is worth the investment, that time compression matters.

The tradeoff is real, though. Frameworks abstract the parts you most need to understand when something breaks in production. When a reasoning model returns a malformed tool call at 2am, you want to know exactly which layer failed. A thick abstraction layer between your code and the API makes that diagnosis harder. We've seen teams spend more time debugging framework internals than they saved during initial development. If your team doesn't have someone who can read the framework source, you're accepting a dependency you can't fully control.

Frameworks also tend to optimize for their own patterns. A tool built specifically for one LLM's API will handle that API's quirks well, but if you need to route certain tasks to a cheaper classification model and others to a more capable reasoning engine, you may find yourself fighting the framework's assumptions rather than working with them. See our notes on reducing token waste in multi-model pipelines for how this plays out in practice.

Approach B: Raw API Calls with Custom Orchestration

Building directly against the LLM API means writing your own tool dispatch loop, your own context management, and your own retry handling. That sounds like more work, and it is, initially. What you get in return is complete visibility into every decision the system makes.

Here's what a minimal TypeScript tool dispatch loop actually looks like against a reasoning API:

async function runAgentLoop(
  messages: Message[],
  tools: Tool[],
  maxIterations = 10
): Promise<string> {
  for (let i = 0; i < maxIterations; i++) {
    const response = await llmClient.messages.create({
      model: "your-model-id",
      max_tokens: 1024,
      tools,
      messages,
    });
    if (response.stop_reason === "end_turn") {
      return extractText(response.content);
    }
    if (response.stop_reason === "tool_use") {
      const toolUse = response.content.find(b => b.type === "tool_use");
      const toolResult = await dispatchTool(toolUse.name, toolUse.input);
      messages = [
        ...messages,
        { role: "assistant", content: response.content },
        {
          role: "user",
          content: [{
            type: "tool_result",
            tool_use_id: toolUse.id,
            content: JSON.stringify(toolResult),
          }],
        },
      ];
    }
  }
  throw new Error("Max iterations reached without resolution");
}

This is the actual pattern. No abstraction layer. You can read every line, add logging at any point, and swap the model identifier without touching anything else. When the reasoning engine returns an unexpected stop_reason, you handle it explicitly rather than hoping the framework catches it.

The cost is that you write this boilerplate yourself, and you write it correctly. Context window overflow, token counting, and graceful degradation when a tool call fails are all your responsibility. Teams without someone who has shipped agents before will hit these edge cases and spend time solving problems that frameworks have already solved. This is not a path for teams that want to move fast without understanding the underlying mechanics.

Security is also your problem. When you control the orchestration layer, you control what permissions each agent component receives. We've written about why agents should never hold admin credentials. With raw API orchestration, you can enforce least-privilege at the tool dispatch layer. With some frameworks, credential scope is set at initialization and applies to everything the agent does.

When to Use Which

Use a framework when your team is new to agent development, your use case fits the framework's assumptions closely, and you need a working prototype fast. The scaffolding is genuinely useful when you don't yet know which edge cases you'll hit.

Build against the raw API when you need precise control over context management, when you're routing tasks across multiple models with different cost profiles, or when the system will run at volume where debugging opacity becomes a real operational cost.

The Autonomous SDR architecture I described earlier, once we split it into discrete components with typed handoff contracts, became something we could test each piece of independently. That's only possible when you own the orchestration logic.

One pattern worth considering regardless of which path you take: define your inter-agent data schemas before you write any agent logic. The schema is the contract. If the research component returns a freeform string and the scoring component expects structured fields, you've built a fragile dependency that will break when the reasoning model's output format shifts slightly. Typed interfaces in TypeScript make this enforceable at compile time, which is one of the genuine advantages TypeScript teams have over Python shops building the same systems.

Neither approach is wrong. Both will get you to a working agent. The difference shows up at 50 leads, not 5, and at 3am when something breaks, not during the demo. If you're evaluating automation infrastructure more broadly, our full blueprint catalog shows how these patterns apply to production orchestration pipelines across different domains.

What We'd Do Differently

Define typed handoff schemas on day one, not after the first production incident. We built the first version of our SDR pipeline with implicit string passing between components. Refactoring to typed contracts after the fact cost more time than writing them upfront would have. TypeScript's type system is your best tool for making agent contracts explicit, and it costs nothing to use it from the start.

Add a hard iteration cap with observable logging before you ship anything. The raw API loop above includes a maxIterations guard, but logging what happened at each iteration is equally important. Without it, a runaway agent loop is nearly impossible to diagnose after the fact. We'd instrument every tool dispatch with a structured log entry including the tool name, input hash, and iteration count, so post-mortem analysis is possible without reproducing the failure.

Evaluate framework lock-in against your 12-month model roadmap. If you expect to swap or add reasoning models as the market shifts, a framework tightly coupled to one API will create migration friction you haven't budgeted for. The raw API approach costs more upfront but leaves that decision open. Given how quickly the LLM landscape is moving in 2026, that optionality has real value.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.