Agent Auth Gateway v1.0

Guides / 7 min read

Secrets Your AI Agent Should Never See

Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team

An agent's context is not a private place. It is logged, summarised, sent to providers, quoted back at users and, under a competent injection, read aloud. Anything placed inside it should be treated as eventually public.

The short answer

Keep real secrets out of the agent's context entirely: no API keys, passwords, tokens or private keys in prompts, tool results, documents it reads or its own outputs. Instead, give the agent a reference — a credential id — and let the gateway or a broker exchange that reference for the real secret at call time, outside the model's view. Audit the places secrets leak into context by accident: verbose tool errors, config echoes, debug logs pasted into chats. The rule is simple to state and worth enforcing mechanically: if the model can read it, it is not a secret anymore.

Check your own setup as you read: run the free Spend Guard self-check or test a policy in the playground — five minutes, no signup, and the gaps it names map to the controls below.

Worked example: the API key in the agent's own summary

A fictional SaaS firm, Copperline Systems, discovered its deployment agent had been including a fragment of a cloud access key in its run summaries. The key had been present in an environment dump a tool returned during debugging — the agent, summarising 'relevant context', faithfully carried the interesting-looking string forward into three weekly reports distributed to a 40-person channel. The key was low-privilege and was rotated within the hour once noticed, but the postmortem's finding was structural: the secret had entered the one place guaranteed to broadcast it.

Copperline moved to brokered credentials. Tools now receive secrets from the gateway at execution time; the agent holds only credential ids like 'deploy-key-prod', and tool outputs are filtered for high-entropy strings before they re-enter context. A scanner runs over agent transcripts and summaries weekly, hunting key-shaped patterns. In six months it has flagged two real finds — both third-party tokens inside customer-supplied logs the agent was asked to summarise — each quarantined and the customer notified, which the firm now counts as a feature it can describe to enterprise buyers.

Context is a broadcast medium

Design as if everything the agent reads will eventually be repeated to someone it should not reach — because across logs, summaries, provider retention, screenshots and extraction attempts, that is the honest planning assumption. This reframes secret-handling from 'be careful what you paste' to architecture: secrets must travel a path that never intersects the model's context. The gateway and tool layer can hold and use secrets; the reasoning layer can know that a credential exists and what it is for, and nothing more.

Brokered credentials: references in, secrets out

The working pattern is a broker: the agent's policy names credential ids per tool; when a call is authorised, the execution layer fetches the real secret, attaches it to the outbound call, and strips it from any response before the response re-enters context. The agent can then work with powerful integrations while being literally unable to reveal their keys — you cannot leak what you have never seen. This also simplifies rotation: the secret changes in one vault, and no prompt, config file or transcript anywhere needs to change with it.

Accidental ingestion is the common path

Deliberate pasting is rare; accidents are weekly. Tool errors that echo connection strings, config files read 'for context', a customer's log bundle containing their own tokens, a screenshot transcribed with a visible password — each places a secret into context innocently. Defences are mechanical: output filters that redact key-shaped strings before they reach the model, tool wrappers that return curated fields instead of raw dumps, and a transcript scanner that hunts patterns after the fact and raises a rotation task when it finds one.

What the agent may know about its secrets

An agent can know a credential's name, purpose, scope and expiry — metadata that helps it choose the right tool and explain a refusal. It should never know the value. When an agent reports 'the production deploy credential expired', that is the system working; when it can quote the credential, the architecture has failed in a way no instruction to 'keep this confidential' will fix. Instructions are read by the same context that holds the secret; architecture is what the context cannot do.

The exit interview for a departing integration

Secrets hygiene has a neglected moment: when an integration or vendor is retired. The agent loses the tool, but copies of the credential often survive — in the vault nobody pruned, in old configuration, in transcripts from its working life. Add a step to every decommission: revoke the credential at the provider, delete it from the broker, and search transcripts and summaries for its fragments. The same applies when a team member who held keys departs. It is unglamorous work, and it is precisely the work that determines whether last year's integration becomes next year's incident through a credential everyone forgot existed.

Five actions to get secrets out of agent context

  1. Inventory where secrets can enter context: prompts, tool outputs, documents, error messages and pasted logs.
  2. Move to brokered credentials — the agent holds credential ids, the execution layer fetches and attaches real secrets outside the model's view.
  3. Filter tool outputs for key-shaped and high-entropy strings before they re-enter the agent's context.
  4. Scan transcripts and summaries weekly for secret patterns, and auto-create a rotation task on any find.
  5. Let agents know credential metadata — name, scope, expiry — and never the value.

Source note and related guides

Figures in the worked example are illustrative, drawn from a fictional company created for this guide; the controls, failure patterns and procedures described are the gateway's documented behaviour — see the Agent Auth Gateway documentation and the policy patterns in allowlists vs denylists, spend caps and the agent kill switch. Reviewed by the Ingenious AI team, 2026-11-14.

Sources

  • RFC 6749, The OAuth 2.0 Authorization Framework, the IETF standard behind scoped, expiring access tokens: rfc-editor.org, 2012
  • Model Context Protocol specification — Authorization, the MCP standard for OAuth-based authorization of MCP servers: modelcontextprotocol.io, 2025
  • NIST AI Risk Management Framework (AI RMF 1.0), the voluntary framework for managing AI risk across design, development and use: nist.gov, 2023

Frequently asked questions

Why can't I just tell the agent to keep a secret confidential?

Because the instruction lives in the same context as the secret, and context gets logged, summarised and, under injection, extracted. Copperline's agent published a key fragment in routine summaries simply by being helpful. Architecture, not instruction, keeps secrets.

What is a brokered credential?

The agent holds a reference — a credential id — and the gateway or execution layer exchanges it for the real secret at call time, outside the model's view, stripping it from responses. The agent can use powerful integrations without ever seeing their keys.

How do secrets usually leak into agent context?

By accident: tool errors echoing connection strings, config files read for context, customer logs containing their own tokens. Mechanical defences — output redaction and transcript scanning — catch what care misses.

What should an agent know about its credentials?

Name, purpose, scope and expiry — enough to choose tools and explain refusals. Never the value. An agent reporting that a credential expired is healthy; an agent able to quote it is an architectural failure.

What do I do when a scanner finds a secret in a transcript?

Rotate the credential, quarantine the transcript from wider distribution, and find the entry path so it can be filtered. If the secret belongs to a customer, notify them — Copperline turned exactly that into a trust-building feature.

Governing agents in production?

Spend caps, approval queues, policy simulation, burn forecasting, and step-up lockdowns — all built into the gateway. Free tier to start. Or test policies in the playground with no signup.

Share this: X Facebook LinkedIn WhatsApp
← Egress Controls for AI Agents: Where You… All guides Session Limits for Long-Running and Alwa… →