AnyLearn
All lessons
AIintermediate

Gateway, Tools, and the M by N Problem

An agent is only as useful as the things it can do, and connecting many agents to many tools is a multiplication problem that gets expensive fast. This lesson covers what AgentCore Gateway converts into tools and how, the semantic search that stops tool overload, the two directions of authentication, and the managed sandboxes for code and browsing.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 7

The multiplication nobody budgets for

One agent calling one internal API is an afternoon. The trouble arrives with scale in two dimensions at once.

Every agent that needs a capability needs an integration to it: the call, the auth, the schema, the error handling, the retry policy, and a description the model can use to decide when to call it. Do that per agent and per tool, and the work is the product of the two counts, not the sum. AWS names this directly in its Gateway announcement as the M by N integration problem.

Integrations to build: direct wiring vs a shared gateway
Direct: M x NVia gateway: M + N
integrations02k4k6k8k10k5 agents, 10 tools20 agents, 50 tools50 agents, 200 tools
Source: computed: M x N direct pairings versus M + N connections when every agent and tool connects once to a shared gateway

Key idea: a gateway converts a multiplication into an addition. Each tool is adapted once, each agent connects once, and the integration count grows with the sum rather than the product. At 50 agents and 200 tools that is the difference between 10,000 pieces of glue and 250.

Full lesson text

All 7 steps on one page, for reading, reference, and search.

Show

1. The multiplication nobody budgets for

One agent calling one internal API is an afternoon. The trouble arrives with scale in two dimensions at once.

Every agent that needs a capability needs an integration to it: the call, the auth, the schema, the error handling, the retry policy, and a description the model can use to decide when to call it. Do that per agent and per tool, and the work is the product of the two counts, not the sum. AWS names this directly in its Gateway announcement as the M by N integration problem.

Integrations to build: direct wiring vs a shared gateway
Direct: M x NVia gateway: M + N
integrations02k4k6k8k10k5 agents, 10 tools20 agents, 50 tools50 agents, 200 tools
Source: computed: M x N direct pairings versus M + N connections when every agent and tool connects once to a shared gateway

Key idea: a gateway converts a multiplication into an addition. Each tool is adapted once, each agent connects once, and the integration count grows with the sum rather than the product. At 50 agents and 200 tools that is the difference between 10,000 pieces of glue and 250.

2. What Gateway converts, and from what

AgentCore Gateway's job is to take things you already have and make them look like MCP tools, which is the interface agents already know how to consume.

AWS documents the supported inputs precisely:

  • REST APIs described by an OpenAPI specification, or by a Smithy model.
  • AWS Lambda functions, with a defined schema.
  • Existing MCP servers, connected through rather than rebuilt.

The phrase in the announcement is zero-code MCP tool creation from APIs and Lambda functions. The mechanism underneath is unglamorous and exactly right: your OpenAPI document already declares the operations, their parameters and their types, which is most of what a tool definition needs, so the conversion is a transformation of a description you have already written rather than new code.

In practice: this reframes a stalled question many teams face. "How do we expose our systems to agents?" often becomes "is our OpenAPI spec accurate and are its descriptions written for a reader who is not us?", which is a documentation problem with a known fix, not an integration project.

AWS also lists connectors for common SaaS systems including Salesforce, Zoom, Jira and Slack, so the same endpoint can front internal and third-party capabilities.

3. Tool overload, and the search that fixes it

Solving M by N creates a second problem immediately, and it is a model problem rather than an infrastructure one.

Predict first

Your gateway now exposes 800 tools, and every one is offered to the agent on every turn. What goes wrong, before you even consider cost?

Gateway's answer is to stop offering everything. AWS provides semantic tool selection through a built-in tool named x_amz_bedrock_agentcore_search: the agent describes what it needs in natural language, and search returns the small set of relevant tools rather than the catalogue.

Key idea: this is retrieval applied to tools instead of documents, and it is the same insight as RAG. Do not put the corpus in the context; put a way to find the relevant part of it. Once tool counts pass a few dozen, tool selection stops being a prompt-engineering problem and becomes a retrieval problem.

4. Two directions of authentication

A gateway sits between callers and systems, so it faces an authentication question on each side, and conflating them is a common design error.

Inbound is: may this caller use this gateway and these tools? AWS implements OAuth-based authorization following the MCP specification, working with Amazon Cognito, Okta, Auth0 or custom providers, and supporting both the authorization code flow, three-legged OAuth, and the client credentials flow, two-legged OAuth.

Outbound is: what credential does the gateway present to the target system? AWS documents IAM role-based authorization for Lambda and Smithy targets, and for OpenAPI targets either an API key, in a header or query parameter, or OAuth client credentials, with the credentials managed through AgentCore Identity's resource credential provider.

The distinction that matters for design: three-legged flows carry a specific end user's authorisation, so the downstream system can enforce that user's permissions. Two-legged flows carry the application's identity, so the downstream system sees one service account and cannot distinguish users. Choosing the second for convenience is how an agent quietly becomes a way for any user to reach data they were never entitled to.

flowchart LR
A["Agent or caller"] --> B["Inbound: OAuth 3LO or 2LO via Cognito, Okta, Auth0"]
B --> C["Gateway"]
C --> D["Outbound: IAM role for Lambda and Smithy"]
C --> E["Outbound: API key or OAuth 2LO for OpenAPI"]
D --> F["Target system"]
E --> F
G["AgentCore Identity holds the credentials"] --> C

5. Policy: deterministic limits on a probabilistic caller

Prompting a model not to do something is a request, not a control. Because a model's tool choice is probabilistic, any guarantee about what an agent will never do has to live outside the model.

AgentCore Policy provides that layer. AWS describes it as deterministic control that keeps agents within defined boundaries and business rules, with rules authored in natural language or in Cedar, AWS's open-source policy language, and integrated with Gateway to intercept every tool call before execution. It can constrain which tools an agent may access, what actions it may perform, and under what conditions.

The placement is what makes it meaningful:

  • Enforcement is at the call site, before execution, not in the prompt where the model may ignore it.
  • Rules are declarative and reviewable as artefacts, so a security reviewer reads policy rather than inferring behaviour from prompts.
  • The guarantee holds regardless of how the model was persuaded, which is the only defence that survives prompt injection.

Gotcha: an agent that reads untrusted content, a web page, an email, a support ticket, is an agent that may act on instructions written by whoever produced that content. No prompt hardening closes that hole. What closes it is the boundary the model cannot argue with: a policy that says this agent may never call the refund tool above a threshold, evaluated outside the model, every time.

6. The two sandboxed tools

Beyond your own systems, AgentCore ships two capabilities that are hard to provide safely yourself, and the reason is the same in both cases: they execute something the model produced.

Code Interpreter is an isolated sandbox where the agent writes and runs code, supporting Python, JavaScript and TypeScript. It is the standard fix for a real limitation: a language model doing arithmetic or data manipulation by prediction is unreliable, while a model that writes six lines of code and runs them gets an exact answer. Data analysis, format conversion and calculation move from a generation problem to an execution one.

Browser is a managed cloud browser runtime, letting agents navigate sites, fill forms and extract information, and AWS lists it as working with automation frameworks including Playwright and BrowserUse. It is the escape hatch for systems with no API, which in most enterprises is a long list.

Build yourselfManaged
IsolationYou own the sandbox escape problemProvided per session
ScalingContainer pool, warm starts, cleanupHandled
Cost shapeIdle capacityPer use
ControlTotal, including custom dependenciesBounded by the service

In practice: browser automation is the most brittle capability in any agent stack, because it depends on other people's markup. Prefer an API when one exists, keep browser paths narrow and well-tested, and expect maintenance whenever a target site changes.

7. Designing the tool surface

The platform makes exposure easy, which shifts the difficulty to a question it cannot answer for you: what should this agent be able to do at all?

The design rules that hold up:

  • Expose capabilities, not endpoints. refund_order(order_id, reason) is a tool. A generic POST /transactions that can do fourteen things depending on a body field is a puzzle the model must solve on every call, and a permission you cannot scope.
  • Write descriptions for the model, and test them. The description is the entire basis of the selection decision. When an agent picks the wrong tool, the fix is usually one sentence of description, not a smarter model.
  • Scope narrowly, then widen. Registering everything because Gateway makes it cheap creates both tool overload and a large action surface for a probabilistic caller.
  • Make destructive actions distinct. Read tools and write tools deserve different policies, and irreversible actions deserve confirmation, a spend cap, or a human.
  • Version the contract. Agents depend on tool schemas exactly as clients depend on APIs; changing a parameter's meaning silently breaks behaviour without breaking a call.

Key idea: Gateway solved the plumbing, which promotes the real problem to the front: an agent's capability set is a security perimeter and a product decision at the same time. The next lesson covers what the agent remembers across those calls, who it is acting as, and how you find out what it actually did.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. What is the M by N integration problem a gateway addresses?
    • Model context windows growing with the number of agents
    • Wiring every agent to every tool individually means work proportional to the product of the counts, not the sum
    • The cost of running M models across N regions
    • Rate limits multiplying across concurrent agent sessions
  2. What does AgentCore Gateway convert into MCP-compatible tools?
    • Only AWS-native services such as Lambda and DynamoDB
    • Only tools written specifically against the MCP specification
    • REST APIs described by OpenAPI or Smithy, Lambda functions with schemas, and existing MCP servers
    • Any HTTP endpoint, discovered automatically by crawling
  3. Why does exposing 800 tools to an agent degrade its behaviour?
    • Gateway throttles requests above a tool-count threshold
    • MCP limits the number of tools per session
    • Tool schemas exceed the model's maximum output length
    • Tool overload: the right tool competes with hundreds of similar distractors in context, causing wrong selections and inefficient paths, at token cost every turn
  4. What is the practical difference between inbound 3LO and 2LO for a gateway?
    • 3LO carries a specific end user's authorisation so downstream systems can enforce that user's permissions; 2LO carries only the application's identity
    • 3LO is for internal APIs and 2LO for third-party SaaS
    • 3LO is faster because it skips the token exchange
    • 2LO supports more identity providers than 3LO
  5. Why must limits on agent actions be enforced by policy rather than by prompting?
    • Prompts cannot express conditional rules
    • Policy evaluation is cheaper than adding prompt tokens
    • Tool choice is probabilistic and an agent reading untrusted content may act on injected instructions, so only enforcement outside the model survives
    • Cedar rules run faster than model inference

Related lessons

AI
intermediate

Memory, Identity, and Seeing What the Agent Did

Three services decide whether an agent survives contact with production: what it remembers between sessions, whose authority it acts with when it calls your systems, and whether you can reconstruct what it did after the fact. This lesson covers AgentCore Memory, Identity and Observability, and the delegation problem that makes agent authentication genuinely different.

7 steps·~11 min
AI
intermediate

Running an Agent: Runtime, Harness, and Session Isolation

An agent is a loop that runs for minutes, holds state, executes code it just wrote, and must not leak anything into the next user's session. This lesson covers what AgentCore Runtime provides that a container does not, why session isolation is the load-bearing guarantee, and where the managed Harness sits against bringing your own loop.

7 steps·~11 min
Programming
beginner

Networking and the Bill: Where the Surprises Live

Two things reliably surprise teams new to AWS: the network they must build before anything can talk, and an invoice driven by charges nobody chose deliberately. The two are connected, because moving data is where much of the cost hides. This lesson covers the virtual network primitives, the traffic charges that follow from them, and how to read a bill.

7 steps·~11 min
Programming
beginner

Storage and Data: Three Shapes, and Choosing a Database

Cloud storage looks like a long product list and is really three physical shapes, object, block and file, each with an access pattern it is built for and one it is bad at. This lesson covers those three, the difference between durability and availability that people conflate, what eleven nines actually means at scale, and how to choose a database by access pattern.

7 steps·~11 min