Skip to content
mentoor

Topic 3 of 5 · 5 min read

Framework lock-in and model portability

Goal: Find the coupling points in an agent codebase that would block a model or framework switch and propose a seam for each.

Lock-in is every place your code knows the name of a provider or a framework, and the way to limit it is to put a thin seam of your own at each of those places. You do not need to be portable everywhere. You need to know where switching would hurt and keep that surface small.

Check yourself · 1 of 3

Which design keeps a tool most portable between frameworks?

Choose one answer

Where the coupling hides

  • Message formats. Providers differ in how they represent system prompts, tool calls and tool results. Code that builds those objects by hand ties you to one shape.
  • Tool definitions. A tool written as a framework decorator, with the framework's types in its signature, cannot be reused elsewhere.
  • Model names and parameters. A string like a model id scattered through the code, or a feature only one provider offers.
  • Hidden prompts. The framework adds its own instructions. Your results depend on text you did not write and cannot see unless you log it.
  • State and storage. Sessions saved in the framework's own format are hard to move.
  • Version churn. Agent libraries change their APIs often. Pinning protects you today but delays the cost.

How to put a seam in

  1. Keep tools as plain functions. Write lookup_order(order_id) -> dict with no framework imports. Add a thin adapter per framework that wraps it.
  2. One model gateway. A single module with one function such as complete(messages, tools) that is the only place that imports a provider SDK.
  3. Your own message type. Store history in a simple structure you own, and convert at the gateway.
  4. Config, not code, for model ids. Put the model name in settings.
  5. Log the raw requests. You cannot port behaviour you cannot see.
  6. Test with a fake model. If your business logic runs against a scripted fake, it is not welded to a provider.

Before and after

# Weak: provider and framework types in the business logic
from some_framework import tool, ProviderMessage

@tool
def refund(ctx, order_id: str) -> ProviderMessage:
    ...
# Better: a plain function plus a thin adapter
def refund(order_id: str) -> dict:
    ...  # business logic, no framework imports

# adapters/framework_a.py wraps refund for one framework
# adapters/framework_b.py wraps it for another

What goes wrong

  • Over-abstracting on day one. A generic layer designed for every provider can be more code than the feature, and it leaks anyway because models differ.
  • Assuming a switch is a config change. A different model needs prompt and tool-description changes and a re-run of your evaluations.
  • Forgetting provider-only features. Built-in search or code tools are not portable. Decide on purpose to depend on them.
  • Never testing a second model. An untested seam is a guess.

Examples

Finding the welded parts

from provider_sdk import Client

client = Client()

def run(task):
    resp = client.messages.create(
        model="big-model-2026-01",
        system=SYSTEM,
        messages=[{"role": "user", "content": task}],
        tools=TOOLS,
    )
    ...

Three couplings: the provider import, the hard-coded model id, and the message and tool shapes in messages and TOOLS. The seam is a complete(messages, tools) function in one module, with the model id read from settings.

A seam that pays off

A team keeps its tools as plain functions and its model calls in one gateway. When a cheaper model launches, they swap the gateway, run their 60-case evaluation set, and find two tool descriptions that need rewording. The switch takes a day. A team with decorators and provider types spread across 40 files would have rewritten most of the agent.

Key points

  • Coupling hides in message formats, tool definitions, model names, hidden prompts, saved state and framework versions.
  • Keep tools as plain functions with no framework imports, and wrap them in thin adapters.
  • Route all model calls through one gateway module so only one file imports a provider SDK.
  • Switching models is never only a config change: re-run your evaluations and adjust prompts.
  • Add seams where switching would hurt, not an abstraction layer for every possible provider.

Common mistakes

  • Building a huge generic abstraction layer before a second provider is needed.
  • Importing the provider SDK in many files instead of one gateway.
  • Calling a model switch "just a config change" and skipping evaluations.
  • Leaning on a provider-only built-in tool without deciding that on purpose.

Check yourself · 2 of 3

Where should a provider's SDK be imported in a portable agent codebase?

Choose one answer

Check yourself · 3 of 3

A team moves to a cheaper model by changing the model id in config. What should they still do?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic