Feeding an agent hundreds of full tool schemas into every prompt bloats context, slows responses, and weakens tool selection. This guide explains pragmatic architectures—inline every tool, gateway grouping, and on-demand retrieval—plus metadata and permission patterns that make retrieval reliable at enterprise scale.
Language models treat tool parameter schemas as context. When you include comprehensive JSON schemas for hundreds of functions in every request, you immediately consume valuable context tokens that could instead be used for user input, dialogue history, or model reasoning. The effect is measurable: higher token bills, longer prompt construction times, and frequently exhausted context windows for complex tasks. For production agents this isn’t theoretical—teams report slower turn times, poorer tool selection accuracy (the model sifts through noise), and brittle behavior as the tool set grows. Treating schemas as free context is a scaling trap.
Beyond raw token cost, keeping a large list of parameter schemas in every prompt amplifies selection errors. The model sees many similar tool descriptions and overlapping parameter names, which increases false positives and ambiguous function calls. In large catalogs, minor naming differences or inconsistent descriptions cause the model to choose a near-match rather than the intended integration. That leads to runtime debugging, human-in-the-loop corrections, and developer churn. A retrieval-first approach narrows candidate space and preserves signal-to-noise in the model’s decision surface.
Practically, teams building agents face three sensible architecture patterns: (1) Inline everything up front, which is simple but unsustainable at scale; (2) Group tools by gateway or domain and expose compact gateway interfaces; and (3) Use on-demand tool retrieval—keep a lightweight registry of names and short descriptions in context, and fetch parameter schemas only for the selected few. Each approach has trade-offs in latency, complexity, auditability, and security. The rest of this article compares these approaches, and gives prescriptive metadata and permission practices to make on-demand retrieval reliable and auditable.
Finally, as organizations adopt MCP servers, enterprise API catalogs, and per-user integrations, a hybrid architecture often performs best: keep high-frequency tools loaded, route domain-specific groups behind gateways, and defer the long tail. This reduces per-request token load while preserving the ability to call specialised tools reliably. The architecture also simplifies permission enforcement and logging because retrieval points become natural places to check user entitlements and insert audit records before exposing schemas to the model.
Three deployment patterns and their trade-offs
Pattern 1—Inline All Tools: you declare every tool and its full parameter schema in the prompt. Pros: deterministic model view, one fewer network hop, simple implementation. Cons: linear increase in context tokens, higher latency constructing prompts, and a heavier cognitive load for the model leading to selection errors as the candidate set grows. Use only for small tool sets or single-purpose agents.
Pattern 2—Gateway/Grouping: you expose a small set of gateways that encapsulate many backend tools (e.g., payments, CRM, analytics). Pros: reduces visible candidates, centralizes authentication, and can standardize parameter shapes. Cons: gateway design is critical—poorly designed gateways become monoliths, and debugging which sub-tool executed requires richer tracing. Gateways work well for bounded domains where one API can mediate many operations.
Pattern 3—On-demand Retrieval (recommended for large catalogs): keep compact metadata (name, short description, category, permission tags) in prompt context and fetch the full schema only when the model selects a tool. Pros: smallest steady-state token footprint, better selection accuracy, and simpler scaling. Cons: requires a retrieval service (client-side or server-side), an extra round trip (unless integrated server-side), and careful metadata design so the model knows which tools exist without full schemas.
Designing tool metadata for reliable retrieval
Make the prompt-level registry compact but informative. Each deferred tool entry should include: a canonical name (unique, human-readable), a single-line description focused on user intent, a category or domain tag, capability keywords, and a permission scope identifier. Avoid long JSON parameter examples in the description. Instead, include usage hints like "accepts order IDs or invoice numbers". These concise metadata fields give the model enough discriminative signal to choose candidates without the full schema in context.
Standardize categories and capability keywords across teams. Enforce a small controlled vocabulary (e.g., payments, user-management, reporting, remediation) and keep synonyms mapped in the registry. This lets retrieval filtering prioritize high-probability tools and reduces ambiguous matches. Also include a short stability tag (stable, beta, ephemeral) so the agent can bias against less reliable integrations.
Permissions, auditing, and where to enforce them
Treat tool retrieval as a security choke point. When the model requests a schema, validate the caller’s entitlements before returning parameters or enabling a function call. Log retrieval requests with a unique call ID, user identity, timestamp, and the returned schema snapshot. This enables post-hoc audits and reduces the blast radius of a compromised context. For enterprise deployments, integrate retrieval calls with your identity provider so permissions follow the same grants used for UI and API access.
Prefer server-side retrieval for low-latency central policy checks. Client-side retrieval is useful when you need per-user dynamic tool additions (e.g., a user connects a new SaaS integration mid-session), but it adds a round trip and requires careful rate-limiting. In both modes, return a minimal schema: only the fields the model needs to call the function and metadata required for validation.