Learn & Build Agents

    ↑ ↓ to choose · Enter to open · Esc to close

    Practice isn’t built yet. Want a heads-up?

    The idea is short exercises, a few minutes a day, where you build and fix the parts of an agent instead of only reading about them.

    • One email when practice opens, and that’s it.
    • No spam, and your email goes to no one else.
    • Leave the list whenever you want.

    No login and no cookies. Your email is kept in a database used only by this site.

    04 Trust in productionLesson 5 of 511 minIntermediateIt helps to have seen:The harnessCost and latency

    Gateway: the gate between apps and the model

    Path of the callstraight to the API
    If the model goes downeverything stops
    Limitsnone
    • + two apps calling the model
    "Where is 4805?"customer in the chatAgentthe whole systemReview summaryanother store appstoppedMain modelprovider AdownClose-upthe step in detaildirect callsagentkey in the codesummarythe same key, copiedlong outageboth stopone-hour outage: an examplewhere is 4805?error: overloaded
    LLMcodedataperson

    Step 1 of 9: The model went down, and both apps stopped

    You will learn
    • What a gateway does, and what stays in the agent
    • Switching to a backup model when the main one goes down
    • Why the backup goes through the same test
    • A quota per customer and a spending cap per app
    • When a gateway is not worth it
    In the lab

    Test conversations with the main model down: how many the backup answers, and how many pass the test set

    Coming soon: I will measure this on the example agent and publish the number with the report.

    The whole lesson as textEvery step on one page, to read in one go, search or print.
    1. The model went down, and both apps stopped

      Friday, 8 p.m. The agent calls the model’s API directly, and the API starts returning overload errors. The code’s retry waits and tries again, as in the harness lesson. But the outage lasts an hour.

      Every conversation in that hour gets no answer. The review summary stops too: it calls the same API, with the same access key (the store’s password with the provider), copied into its code.

      Every app talking to the model directly repeats the same problem.

    2. A gate between the apps and the model

      A is a service that every call to the model goes through, from any store app. For the agent, little changes: the loop is the same; the address and key of the call change.

      What applies to every call now lives in one place: the provider’s key, the message limit per customer, the spending cap, the choice of model and the log of each call.

      What applies to every call lives in one place.

    3. A backup model when the main one goes down

      With the gateway, a long outage has a way out. The rule works call by call: retry a few times and, if the error persists, send the same call to the backup. If the main model keeps failing, the gateway stops trying it for a while and goes straight to the backup.

      The backup can be the same model sold by another company, such as Amazon or Google, or another model. The rule is written before the failure.

      Transient error: retry. If it persists: switch models.

    4. The backup nobody tested

      At the first real outage, the backup steps in. It writes well, but in conversation s03 it skips get_policy and promises the refund for order 4806 within 24 hours. Under the policy, a card refund takes up to 10 days.

      The prompt was tuned for the main model and never ran on the other one. The backup goes through the same test set before joining the route, including a switch in the middle of a conversation.

      The backup only joins the route after passing the test.

    5. The customer who chats nonstop

      A bot, a program logged in to a customer’s account, sends a message every three seconds. Each message turns into calls to the model, and the store pays. OWASP calls it unbounded consumption: the attack can bring the service down or go after your wallet.

      The defense is a quota per customer. The chat counts messages as they come in, and the gateway, which sees every call, catches whatever slips by with a call cap per customer.

      Without a quota, the store pays for the bot’s chat.

    6. Each app with its own key and its own cap

      In the middle of the night, a bug makes the review summary summarize the same product over and over. If both apps use the same ID at the gateway, the summary spends everyone’s budget, and the agent stops too.

      Each app gets its own key, valid only at the gateway, with a daily spending cap. The log shows who spent what, and only the broken app stops.

      An app with a bug cannot spend the others’ budget.

    7. Uber: one gate for the whole company

      In 2024, Uber described its GenAI Gateway: a single service in front of models from outside providers and its own models. At the time, about 30 teams used it, with 16 million calls a month.

      According to the post, it brings together what each team would do alone: access control, audit logging, cost per team and removal of personal data before the text leaves the company. My take: it pays off when many apps share the models.

      A gateway pays off when many apps share the models.

    8. The gate can go down too

      Now every call goes through the gateway: if it goes down or gets slow, every app feels it. And if it is a third-party service, it sees all the text that passes through.

      Not every project needs one. With one app and one model, the SDK’s retry, a round limit, a quota per customer and the provider’s spending limit are enough; even the backup fits in the app’s code. A gateway pays off with several apps or providers.

      One app and one model: start without a gateway.

    9. One gate for what is shared

      The gateway takes out of each app what is the same for all: the key, the quotas, the spending cap, the model switch and the log.

      The business rules stay in the agent and the tools. And the backup only helps if it passed the same test as the main model.

      Shared things in the gateway; business rules in the agent.

    Questions in this lesson

    What changes in the agent when the store adds a gateway?
    Little: the address and key of the model call. Many gateways accept the same format as the model’s API. The address and key change and, if there is a quota per customer, so does the customer ID sent along.
    Can the backup join the route without going through the test set?
    No, the same prompt can behave differently on it. In an outage, the backup answers every customer. It must have passed the same test as the main model.
    Who sets the quota per customer?
    The store, in the gateway or in code. The provider’s limit applies to the store’s whole account. It does not know who each customer is.