Your agent wires a payment SDK, an email service, and an AI API straight into feature code, wherever each one is needed. It works, until the vendor changes its prices, you want to switch providers, or the SDK ships a breaking change. Now that one change is scattered across twenty files. This chapter gets each outside service behind one door you control.
5.6.1A vendor threaded everywhere is a rewrite waiting
When feature code calls a vendor's SDK directly, the vendor is glued into your whole app. Every screen that charges a card imports the payment library, every place that emails a user imports the mail library. This is vendor lock-in: the outside service is now welded into dozens of files.
The day the vendor raises its price, breaks its SDK, or loses your trust, the swap means editing everywhere it appears. Vendor entanglement is one of the most common rewrite triggers in AI-built apps. Note this is a service you consume, distinct from the API you expose.
5.6.2Put each service behind one adapter
Give each outside service one adapter you own, the thin-wrapper shape named in the patterns chapter. Your feature code calls your function (charge(...)), and only the adapter file ever imports the vendor. That one file is the whole surface the rest of your app sees.
5.6.3Now you can swap without a rewrite
To move from one provider to another, or to absorb a breaking SDK change, you rewrite the inside of that one adapter. The charge function keeps the same name and the same shape, so every file that calls it stays untouched.
The rest of your app never notices the vendor changed. That is exactly the "extend without rewrites" this part is built around: a swap that could have touched twenty files now touches one.
5.6.4Keep the door thin and in your words
An adapter is only useful if it stays narrow. Expose the handful of operations your app actually needs, named in your own terms (charge, refund, sendEmail), not the vendor's entire API surface.
Do not let the vendor's own types leak back out through the door. If charge returns the vendor's raw response object, every caller is quietly coupled to that vendor again, and you are back where you started. Return a small shape you define, the same narrow-interface idea from the coupling chapter.
This prompt has your agent pull every vendor behind its own door:
Do this now: paste the prompt so your agent finds every direct vendor call and moves each behind one adapter you own, then confirm exactly one file imports each SDK.