AI Agents

What is an AI Agent?

When you want to centrally manage agent routing, control access, and gain observability over agent traffic, use the AI Agent entity to expose upstream agents through AI Gateway. AI Gateway:

  • Acts as a central point of contact for A2A clients
  • Rewrites agent-card URLs so clients route through the gateway (not directly to agents)
  • Enforces access controls via Access Control Lists (ACLs)
  • Emits structured telemetry tied to agent operations.

The AI Agent entity supports two types: a2a for AI Agents that speak the Agent-to-Agent protocol, and http for standard HTTP AI Agents. See the AI Agent types section for protocol-specific behavior and configuration guidance.

Manage AI Agents

AI Agents can be created and managed through:

  • Konnect UI
  • AI Gateway API: /v1/ai-gateways/{aiGatewayId}/agents
  • kongctl

For configuration examples and step-by-step setup instructions, see the following Set up an AI Agent section.

AI Agent types

Choose an AI Agent type based on your upstream and observability needs. The type controls how requests are processed:

Type

Use case

a2a Agents that speak the Agent-to-Agent protocol. AI Gateway applies protocol awareness, detects A2A requests (JSON-RPC and REST bindings), rewrites agent-card URLs to the gateway address, emits structured A2A telemetry, and extracts task metadata for analytics. Use when you want full observability tied to A2A semantics.
http Standard HTTP agent endpoints. Requests pass through transparently as a generic HTTP proxy without A2A-specific processing. Use for upstream agents that don’t implement A2A or when you need simple transparent proxying without protocol-aware behavior.

Use cases for AI Agents

Common use cases for exposing agents through AI Gateway:

Use case

Description

Observability and telemetry Emit structured A2A telemetry and extract task metadata for analytics. Track agent performance, request patterns, and error rates tied to A2A task semantics. Use for production agent deployments where visibility into agent traffic is critical. See Logging and observability for details on telemetry collection and OpenTelemetry integration.
Authentication and access control Require agents to authenticate clients through an AI Auth Strategy, using the openid-connect or key-auth auth strategy, before routing requests. Restrict which AI Consumers or AI Consumer Groups can reach specific agents via ACLs.
Rate limiting Enforce per-agent or per-consumer rate limits to prevent overload and manage agent resource usage. Use AI Rate Limiting Advanced to set token or request quotas per consumer.
Policy enforcement Attach AI Policies to agents for request transformation, PII detection, input validation, and request logging. Layer security and governance controls on agent traffic.
Centralized discovery Provide A2A clients with a single, stable gateway endpoint (via agent-card URL rewriting) instead of having them discover and connect directly to agent instances.
AWS-native upstream agents Authenticate to upstream agents that only accept AWS IAM (SigV4) signed requests, such as an agent hosted on Amazon Bedrock AgentCore Runtime or fronted by an IAM-protected Amazon API Gateway, using config.upstream.auth. See Upstream authentication.

How A2A traffic flows

When an Agent has type a2a, proxied traffic is processed in four phases:

  1. Access. Detects whether the request is an A2A operation (JSON-RPC or REST binding). This starts an OpenTelemetry span, and records the request body for payload logging if that’s enabled.
  2. Header filter. Detects streaming responses (Content-Type: text/event-stream) and records time to first byte. Buffers agent-card responses for URL rewriting.
  3. Body filter. Streams SSE chunks through to the client without buffering. Buffers non-streaming responses to extract task metadata. Rewrites agent-card URLs to the gateway address. Emits analytics at end of response.
  4. Log. Finalizes the OpenTelemetry span with task state, task ID, and any error information.

Non-A2A traffic, and traffic to http Agents, is proxied without these steps.

Routing configuration

Beyond the url field, AI Agents can define HTTP routing rules through config.route. This allows you to match requests by method, path, host, and other HTTP patterns. Use route when you need fine-grained control over which traffic reaches the AI Agent. If only a URL is needed, the url field is simpler.

 
sequenceDiagram
    autonumber
    participant Client as A2A Client
    participant Gateway as AI Gateway
(Agent) participant Agent as Upstream A2A Agent Client->>Gateway: A2A request (JSON-RPC or REST) Note over Gateway: Detect A2A binding and method
Start OTel span (if logging enabled) Gateway->>Agent: Proxied request
(Accept-Encoding removed if logging enabled) alt Streaming response (SSE) Agent-->>Gateway: text/event-stream chunks Note over Gateway: Pass through each chunk
Count SSE events, track TTFB Gateway-->>Client: SSE chunks (unchanged) Note over Gateway: On final chunk:
Extract task state, set analytics else Non-streaming response Agent->>Gateway: JSON response Note over Gateway: Buffer response
Extract task metadata Gateway->>Client: Response (unchanged) end Note over Gateway: Finish OTel span
Emit ai.a2a metrics to log plugins

Core A2A protocol elements

A2A defines the communication elements between agents. The AI Gateway runtime surfaces data tied to these elements in log output and OpenTelemetry spans for a2a Agents.

Element

Description

Purpose

Agent Card A JSON metadata document describing an agent’s identity, capabilities, endpoint, skills, and authentication requirements. Enables clients to discover agents and understand how to interact with them.
Task A stateful unit of work initiated by an agent, with a unique ID and defined lifecycle. Tracks long-running operations and supports multi-turn interactions.
Message A single turn of communication between a client and an agent, containing content and a role (user or agent). Conveys instructions, context, questions, answers, or status updates that are not formal artifacts.
Part The fundamental content container (for example, TextPart, FilePart, DataPart) used within messages and artifacts. Provides flexibility for agents to exchange different content types within messages and artifacts.
Artifact A tangible output generated by an agent during a task (for example, a document, image, or structured data). Carries the concrete output of a task in a structured, retrievable form.

Protocol detection

A2A traffic is auto-detected per request and non-A2A traffic passes through without overhead.

REST binding

Detection anchors to the end of the request path, so any prefix added by the route is ignored. For example, both /v1/message:send and /api/agents/v1/message:send match SendMessage:

HTTP method

Path suffix

A2A operation

Canonical method

POST /v1/message:send SendMessage message/send
POST /v1/message:stream SendStreamingMessage message/stream
GET /.well-known/agent-card.json GetAgentCard agent/getCard
GET /v1/extendedAgentCard GetExtendedAgentCard agent/getExtendedAgentCard
GET /v1/tasks/{id} GetTask tasks/get
GET /v1/tasks ListTasks tasks/list
POST /v1/tasks/{id}:cancel CancelTask tasks/cancel
POST /v1/tasks/{id}:subscribe SubscribeToTask tasks/resubscribe
POST /v1/tasks ListTasks tasks/list

The canonical method name is what appears in OpenTelemetry span attributes and log output.

JSON-RPC binding

Detected by the "jsonrpc" field in the request body, combined with a recognized A2A method name or an A2A-Version request header. Recognized methods include message/send, message/stream, tasks/get, tasks/list, tasks/cancel, tasks/resubscribe, the tasks/pushNotificationConfig/* family, and agent/getExtendedAgentCard.

A request carrying an A2A-Version header is treated as JSON-RPC even if the method isn’t in the recognized list. When an unknown method is accepted this way, the method field in log output is recorded as "unknown" to bound metric cardinality. The OpenTelemetry span’s kong.a2a.operation attribute still receives the actual method name.

Agent-card URL rewriting

When an upstream agent returns an agent card, the runtime rewrites the url field, and any additionalInterfaces[].url fields, to the AI Gateway address. A2A clients then discover the gateway as the canonical endpoint instead of contacting the upstream directly. The rewrite uses X-Forwarded-* headers to construct the correct scheme, host, and port when the gateway is deployed behind a load balancer or reverse proxy.

Logging and observability

For a2a type AI Agents, AI Gateway automatically emits structured A2A telemetry to track agent performance, debug issues, and monitor A2A traffic patterns. This telemetry flows to Konnect analytics, logging plugins, and OpenTelemetry for full visibility into agent operations, with no separate toggle required.

The telemetry data is emitted into the ai.a2a namespace (consumed by Konnect analytics and logging AI Policies) and creates a kong.a2a child span when you’ve configured Kong Gateway tracing. For the canonical metric and attribute list, see A2A metrics.

For a2a type Agents, the runtime removes the Accept-Encoding request header before forwarding to the upstream. This prevents compressed responses that the runtime can’t parse for metadata extraction.

Payload logging additionally captures request and response bodies. Payloads are truncated at the configured payload size limit.

Payload logging may expose sensitive data. Only enable it when you’re prepared to handle request and response bodies in your logging pipeline.

You can view A2A analytics in Konnect Explorer and Dashboards through the Agentic usage analytics view.

Log output fields

When config.logging.log_statistics is enabled, it writes the following fields to the ai.a2a.rpc[] array:

Field

Type

Description

ai.a2a.rpc[].method string A2A operation name
ai.a2a.rpc[].binding string Protocol binding: jsonrpc or rest
ai.a2a.rpc[].latency number End-to-end proxy latency in milliseconds
ai.a2a.rpc[].id string Request ID (JSON-RPC) or task ID (REST)
ai.a2a.rpc[].task_id string Task ID extracted from the response
ai.a2a.rpc[].task_state string Normalized task state (see task states)
ai.a2a.rpc[].context_id string A2A context ID extracted from the response
ai.a2a.rpc[].error string Error type string when the upstream returned an error
ai.a2a.rpc[].response_body_size number Response body size in bytes
ai.a2a.rpc[].streaming boolean true for SSE streaming responses
ai.a2a.rpc[].ttfb_latency number Time to first byte in milliseconds (streaming only)
ai.a2a.rpc[].sse_events_count number Count of SSE data: events received (streaming only)
ai.a2a.rpc[].payload.request string Request body (only when log_payloads is enabled)
ai.a2a.rpc[].payload.response string Response body (only when log_payloads is enabled)

OpenTelemetry span attributes

For a2a type Agents, when Kong Gateway tracing is configured, the runtime creates a kong.a2a child span with the following attributes:

Attribute

Value Type

Description

kong.a2a.operation string A2A operation name
kong.a2a.protocol.version string Value of the A2A-Version request header, or unknown
kong.a2a.task.id string Task ID from the response
kong.a2a.task.state string Normalized task state
kong.a2a.context.id string A2A context ID
kong.a2a.error string Error type string when present
kong.a2a.streaming boolean true for SSE streaming responses
kong.a2a.ttfb_latency int Time to first byte in milliseconds (streaming only)
kong.a2a.sse_events_count int Count of SSE events (streaming only)
rpc.system string jsonrpc (JSON-RPC binding only)
rpc.method string A2A operation name (JSON-RPC binding only)

Access control

To restrict which AI Consumers or teams can reach a specific agent, use ACLs. The access.acls field defines either an allow or a deny list of identities that can access the agent. Each entry references an AI Consumer, AI Consumer Group, or Authenticated Group by name. An Authenticated Group is a dynamic group representing all consumers authenticated via a specific OAuth2 scope or claim. Access is enforced before traffic reaches the upstream agent.

For per-request authentication and identity validation, reference an AI Auth Strategy in the access.auth_strategies array, the same way you would for an AI Model. The AI Agent has its own top-level authentication mechanism: you configure the authentication through AI Auth Strategies. See AI Policy scopes for details.

An AI Agent currently accepts up to one AI Auth Strategy reference. ACLs are evaluated only after the AI Consumer’s identity is resolved through this authentication step.

Upstream authentication

Access control and AI Auth Strategies govern who can reach the AI Agent. Separately, config.upstream.auth controls how AI Gateway authenticates itself to the upstream agent. By default, AI Gateway proxies requests without adding credentials.

Some upstream agents don’t accept bearer tokens or API keys at all, and only accept requests signed with AWS IAM (SigV4), such as an agent hosted on Amazon Bedrock AgentCore Runtime or fronted by an IAM-protected Amazon API Gateway. For these, set config.upstream.auth.type to aws.

AI Gateway signs each proxied request using the credentials you provide:

  • Static IAM user credentials, access_key_id and secret_access_key, optionally paired with a session_token for temporary credentials. Environment auto-detection when you omit access_key_id and secret_access_key, for example, an EC2 instance profile or environment variables.
  • Role assumption through assume_role_arn and role_session_name, layered on top of either credential source. Recommended for production use and cross-account access.

Set region to override the region. Otherwise, AI Gateway infers from the environment, and sts_endpoint_url to use a custom AWS STS endpoint when assuming a role.

secret_access_key and session_token are write-only and referenceable fields. Store them in a vault instead of in plaintext.

config:
  url: https://agent.execute-api.us-east-1.amazonaws.com/prod
  upstream:
    auth:
      type: aws
      region: us-east-1
      assume_role_arn: arn:aws:iam::123456789012:role/agent-access
      role_session_name: kong-ai-gateway

config.upstream is available regardless of the AI Agent’s type; it applies to a2a and http Agents alike.

Attach AI Policies

To enforce security, transformation, or governance controls on agent traffic (for example, request validation, PII detection, request logging), attach AI Policies to the agent. Add policy names or IDs to the AI Agent’s policies field. Multiple AI Policies can attach to one AI Agent; each runs independently in the request lifecycle.

For available policy types and configuration, see the AI Policy entity reference.

Set up an Agent

Before creating an AI Agent with access restrictions, create an AI Consumer Group to reference in access.acls. This example references a group named internal-teams. See Set up an AI Consumer Group to create it, or substitute the name of your own AI Consumer, AI Consumer Group, or Authenticated Group in access.acls.allow.

The following example creates an a2a Agent that proxies traffic to an upstream A2A agent at https://booking-agent.internal.kongair.com, with access restricted to the internal-teams Consumer Group.

This example proxies to a placeholder upstream at https://booking-agent.internal.kongair.com. Substitute the URL of your own running A2A agent in config.url. Because this Agent has type: a2a, requests must use the A2A JSON-RPC envelope (jsonrpc: "2.0", id, method: "message/send", params.message with kind and messageId). A flat {"message": {...}} body without that envelope is rejected by the upstream agent itself (for example, "Invalid Request: jsonrpc must be 2.0"), not by AI Gateway.

Schema

FAQs

An a2a AI Agent applies Agent-to-Agent protocol awareness (JSON-RPC and REST binding detection, agent-card URL rewriting, structured A2A telemetry) to traffic flowing to an upstream agent. An http AI Agent is a generic HTTP route to an upstream agent without A2A-specific processing. Use a2a when the upstream speaks the A2A protocol and you want observability tied to A2A task and message semantics.

No. The runtime behind an AI Agent operates as a transparent proxy. It detects A2A requests, records telemetry, and rewrites agent-card URLs to the gateway address. It does not change routing decisions, merge responses, or hold task state on behalf of clients.

A2A clients use agent-card responses (at /.well-known/agent-card.json) to discover where to send subsequent requests. Rewriting the url field, and any additionalInterfaces[].url fields on the agent card response, to the AI Gateway address means clients route follow-up traffic through the gateway instead of bypassing it. The rewrite honors X-Forwarded-* headers when the gateway sits behind a load balancer.

Server-sent events (Content-Type: text/event-stream) pass through chunk-by-chunk without buffering. The runtime counts SSE events, captures time-to-first-byte, and extracts task state from the final event for analytics. Latency is preserved.

Set the access.acls field on the AI Agent with an allow list or a deny list. Each entry is a string that references an AI Consumer, AI Consumer Group, or Authenticated Group by name.

Reference an AI Auth Strategy by name or id in the AI Agent’s access.auth_strategies array, the same field used on AI Models. An AI Agent currently accepts up to one AI Auth Strategy reference. The AI Agent has its own top-level authentication mechanism, so attaching an authentication AI Policy directly to its policies field isn’t supported.

Configuration that applies to the AI Agent goes through the AI Policy entity. Attach AI Policies to the AI Agent through its policies field.

Configure config.upstream.auth with type: aws. AI Gateway signs each proxied request using static IAM credentials, environment auto-detection, or an assumed role. This is separate from access.auth_strategies, which authenticates inbound clients rather than outbound requests to the upstream agent. See Upstream authentication.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!