Add delegation and pre-action authorization attributes for agent spans
Following the thread on pre-action governance telemetry: the handoff span records source and target agents, but not the authority the target is acting under. In multi-hop delegation that is the question auditors ask first: on whose behalf, and was this action within what was delegated?
A small, scheme-neutral set of attributes could cover it without putting credentials or policy text into traces, in line with the references-and-hashes approach discussed above:
- gen_ai.delegation.root.id: the principal at the root of the chain
- gen_ai.delegation.actor.id: the agent acting now
- gen_ai.delegation.depth: number of delegation hops
- gen_ai.delegation.chain.hash: hash of the delegation chain as verified, so an auditor can fetch and re-verify it out of band
- gen_ai.authz.decision: allow or deny, recorded before the tool call executes
- gen_ai.authz.reason: a short machine-readable code for a denial
These map directly onto RFC 8693 token exchange (sub and the nested act claims) and onto signed delegation formats. We maintain one such format, VAID (https://github.com/solara-associates/vaid), and a bridge from verified VAID chains to RFC 8693 JWTs, so we could emit these attributes in practice and report back on what works.
Happy to draft a PR against the attribute registry if this direction fits.
Thanks for writing this up, and for offering to draft a PR. I prototyped one direction and would value maintainer input:
- Opt-in only: an app wraps a run in
with delegation(root_principal="user:42", chain_id="dlg_7f3a", scope_hash=hash_scope([...])):, and agent and handoff spans in OpenAI Agents and LangGraph gettraceloop.delegation.{root_principal,chain_id,scope_hash,depth}. Nothing is recorded otherwise. - References, never credentials: values that look like tokens (JWTs,
Bearer …) are rejected. The scope is stored only as asha256:digest. - Kept in-process: the values live in the OTel Context, not Baggage, so they never go out in request headers.
- Vendor namespace:
traceloop.*until GenAI semconv defines an equivalent (ties into #3460). These fields correspond to the RFC 8693sub/actclaims.
Authz decision/reason attributes could follow later. I'm opening the prototype as a PR so the code is easy to review; happy to adjust the naming or narrow it to a single instrumentation if you prefer a different direction.
Thanks Rutvij, this is a great prototype and I'm happy for you to take the PR forward. I'll review it.
The design choices look right to me: opt-in, references rather than credentials, scope as a digest, and kept in the OTel Context rather than Baggage.
Two suggestions you might consider:
-
Per-hop scope. If each handoff span records its own scope_hash alongside its parent's, a reviewer can see whether authority narrowed at every hop or widened somewhere. That is the property delegation chains most need to prove, and it costs one extra attribute.
-
An optional, opaque credential reference (for example traceloop.delegation.credential_ref), so a trace can point at whatever credential carried the authority (an OAuth token exchange result, a VAID, a SPIFFE SVID) without the library knowing or storing it. That keeps it vendor-neutral while letting a verifier join the trace to the evidence.
Agree that authz decision and reason attributes can follow later. Happy to test the PR against VAID's delegation chains once it's up.
Thanks @asmeyatsky, both suggestions are now in #4701 (2f29fa5):
- Per-hop scope: a nested
delegation()that declares its ownscope_hashalso records the enclosing hop's astraceloop.delegation.parent_scope_hash, so each hop shows the scope it received and the one it came from. It can also be passed explicitly. traceloop.delegation.credential_ref: an optional opaque reference (token exchange id, VAID, SPIFFE ID). It's validated like the other identifiers, so token-shaped values are rejected, and it isn't inherited by nested hops.
Authz decision/reason are already there via record_authorization(). I'd welcome a test against VAID's delegation chains whenever you have time.
Thanks Rutvij, that's exactly the shape I had in mind, and keeping credential_ref out of inheritance is the right call, since each hop should point at its own credential. I'll test #4701 against a real VAID delegation chain (root, then two attenuated hops) over the next week, checking that each hop records its own scope_hash and parent_scope_hash and that the credential_ref resolves to the VAID that carried the authority, and I'll report back on the PR.
As promised, we tested PR #4701 (head commit 4e9c270) against a real VAID chain, minted with the public vaid-mint package rather than fixtures. Thanks @Rutvij97 for turning this around so quickly.
What we ran: a 3-hop VAID chain (root orchestrator, then two attenuated hops, each narrowing scope) driving a 3-agent flow through the openai-agents OpenTelemetryTracingProcessor this PR touches, with one nested delegation() context per hop and spans captured by the in-memory exporter.
What we checked, all passing:
root_principalandactorper hop,depth0, 1 and 2, and a sharedchain_hashparent_scope_hashon each hop equals the hash of the previous hop's scope- a distinct
credential_refper hop (that hop's VAID id), not inherited: each agent span carried only its own reference - no token-like value or raw scope text in any span attribute
- tool spans inherit from the enclosing agent span, as documented
record_authorization()gives the right decision and reason for an allowed and a denied tool call- every
credential_refresolves back to the VAID minted for that hop and verifies offline with the kernel public key, includingverify_chain()against the real ancestor documents
We also reproduced the final commit's trailing-newline fix for digests and reason codes directly, and the PR's own test suites are green. We found no bugs.
On naming: keeping the attributes under traceloop.delegation.* while GenAI semconv has no delegation concept looks like the right interim call, and the module docstring is clear about it. We'd suggest gen_ai.* as the target once the GenAI semconv group adopts one, so this can converge on the standard.
Happy to share the test harness if it's useful. A maintainer review when you have a chance would be much appreciated.