Skip to main content
Version: 1.16.0-dev

Connect an agent framework to DVARA

An agent makes model calls, MCP tool calls and A2A calls to other agents. DVARA, the AI gateway, governs each one. To stop a looping agent, hold a tool call for a human, or kill a session, DVARA has to know which calls belong to one agent run. Two headers tell it. There is no DVARA SDK to install: the OpenAI, Anthropic, MCP and A2A SDKs, LangChain4j, Spring AI and LangGraph all work with these headers, pointed at the gateway.

Set the two headers once​

HeaderSet it toWhat DVARA does with it
X-Session-IdOne ID per agent run, the same on the model client, the MCP client and the A2A clientJoins the calls into one session for loop detection, approvals, session kill, tags and audit. At most 128 letters, digits or ._:-.
traceparentWhat your OpenTelemetry setup sends (no code needed with auto-instrumentation)Gives the run's calls one trace ID in the audit trail, unless you send your own X-Trace-ID.

Set them as default headers on each client, not on each call. For example, with the OpenAI Python SDK:

import uuid
from openai import OpenAI

run_id = f"support-run-{uuid.uuid4()}" # one ID per agent run

client = OpenAI(
base_url="https://<dvara-host>/v1",
api_key="<your-api-key>",
default_headers={"X-Session-Id": run_id},
)

Give your MCP client and your A2A client the same X-Session-Id. See DVARA headers for the full contract and examples in TypeScript and Java.

Check that DVARA accepted the session ID​

DVARA ignores a session ID that fails the check, and does not refuse the call. An ignored ID means the call joined no session, so loop detection and a session kill do not apply to it.

From 1.14.0 the Enterprise gateway says so in the response, on /v1, /mcp and /a2a. A valid ID comes back as X-Session-Id. An invalid one gets X-Dvara-Session-Ignored: invalid. Check for that header once, when your agent starts:

curl --silent --include https://<dvara-host>/v1/chat/completions \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--header 'X-Session-Id: support run 42' \
--data '{"model": "gpt-4o", "messages": [{"role": "user", "content": "ping"}]}' \
| grep -i '^x-dvara-session-ignored'

The space in support run 42 fails the check, so this prints X-Dvara-Session-Ignored: invalid. The response headers are on by default; an operator can turn them off with dvara.mcp-gateway.agentic.session-echo.enabled=false. The Open Source gateway sends neither header.

Get one trace ID across model, tool and agent calls​

On /mcp and /a2a, DVARA takes the trace ID from the traceparent you send. From 1.14.0 the Enterprise gateway does the same on /v1, so a run's model calls, tool calls and agent calls share one trace ID, and the X-Trace-ID response header returns it. Before 1.14.0, and in the Open Source gateway, a /v1 call with no X-Trace-ID gets a random trace ID. An X-Trace-ID you send wins on every plane.

Handle the agent governance errors​

Loop detection, approvals and session kills run on MCP tool calls and A2A hops in a session. A session kill also applies to model calls. These controls are in the Enterprise gateway, not in DVARA Open Source. These are the codes an agent should turn into typed errors in its own code. None of them should be retried as they are.

What happened/v1MCP server path (REST)/mcp (JSON-RPC data.dvara_code)A2A (data code)
A reviewer denied the call—403 mcp_approval_deniedMCP_APPROVAL_DENIEDa2a_approval_denied
No decision before the timeout—408 mcp_approval_timeoutMCP_APPROVAL_TIMEOUTa2a_approval_timeout
The approval service could not hold the call—403 mcp_approval_unavailableMCP_APPROVAL_UNAVAILABLEa2a_approval_unavailable
Loop detection stopped the session—429 mcp_agent_loop_detectedAGENT_LOOP_DETECTEDa2a_loop_detected
The session was killed403 session_killed403 mcp_session_killedSESSION_KILLEDa2a_session_killed

A call held for approval stays open until a reviewer decides or the timeout runs out. There is no 202 to poll. A call is held only when an approval rule in the workspace matches it; there are none by default. MCP loop detection is on by default, and a repetition or a cycle also kills the session unless an operator turned auto-kill off. See Agentic governance. For an A2A error, the code is in error.data.code at A2A 0.3 and in error.data[0].metadata.code at A2A 1.0; see Read a refusal.

Two framework defaults work against this:

  • The OpenAI Agents SDK passes a tool error back to the model with "Please try again" by default. Set failure_error_function=None on the tool so a refusal is raised instead of retried.
  • LangChain4j's MCP client keeps only the error message, not data.dvara_code. A Java agent on it cannot tell the codes apart, so stop the run on any refused tool call.

A kill lasts 24 hours on every plane. Start a new run with a new X-Session-Id. The full list of codes is in Error handling.