Repository navigation
feat(aiguard): send evaluations through the Agent when the service has no keys - #21595
florentinl wants to merge 12 commits into
Conversation
…s no keys A service instrumented by Single Step Instrumentation never gets DD_API_KEY and DD_APP_KEY, so AI Guard stayed off. When both keys are missing and the Agent advertises /ai_guard/proxy/ in its /info endpoint list, the client now sends evaluations to that route and the Agent attaches its own credentials. Services that set both keys keep calling the API directly. Adds the two SDK metrics the RFC defines: an ai_guard.transport gauge tagged with the transport in use, and an ai_guard.agent.requests count per evaluation sent to the Agent, tagged with the status code, the error type and the Agent's own error code. Original PR: #21569 Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 59f1205 | Docs | View more details | Give us feedback! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 452e8f64db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Use the internal one-shot thread for Agent discovery and give transport errors and Agent info their expected types. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
BenchmarksBenchmark execution time: 2026-11-09 14:01:54 Comparing candidate commit 59f1205 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 619 metrics, 9 unstable metrics, 1 flaky benchmarks without significant changes.
|
Bound waits for background discovery, start it once per generation, and wake callers when discovery is reset or invalidated. Reset discovery after fork and discard late probe results. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
Cache only confirmed unsupported Agents. Retry unreadable info on the next evaluation and verify forked children do not inherit the parent absence backoff. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
Document credential precedence, evaluation-time discovery errors, and the endpoint override scope. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
There was a problem hiding this comment.
More details
Concurrent evaluations share pending Agent discovery, and transient discovery failures remain retryable. Runtime behavior could not be verified because required dependencies were unavailable.
🤖 Bits Code Review · Commit 9ed8af8
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ed8af8795
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Accept Agent info endpoints with or without a leading slash. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
Use the shared Agent base-path helper for evaluation targets while keeping Unix socket locations separate. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
Let callers opt in to a distinct /info 404 error while preserving the existing info() default. Cache confirmed unsupported Agents and keep transient failures retryable. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
Let the native HTTP client preserve the base path instead of prepending it to the target again. Add real HTTP-server regressions for root and prefixed Agent URLs, including a trailing slash. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
A 404 from a pinned connection base must not invalidate the process-wide route used by factory clients. Cover the failure and a subsequent successful evaluation on the discovered route. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
Treat native thread resource failures as an optional background-probe failure. Install AI Guard listeners and let evaluations discover the Agent synchronously. Co-authored-by: Eliott B <eliott.bouhana@datadoghq.com>
Description
Allow services without both Datadog credentials to send AI Guard evaluations through the local Agent when it advertises the proxy route. Services with both keys continue calling AI Guard directly. Discovery is shared across clients, evaluations wait within the Agent timeout for pending discovery, and transient failures can be retried on the next evaluation. Includes Unix socket support and transport telemetry.
Original PR: #21569 by @eliottness. Eliott Bouhana remains credited as co-author.
Testing
All 561 AI Guard API and Agent-helper tests pass on Python 3.12, including concurrent startup, bounded waits, invalidation, transient recovery, a forked-child regression, advertised endpoint normalization, native HTTP requests through reverse-proxy paths, unsupported /info responses, cross-client isolation, and background-thread resource failures. All local repository checks pass, including typing, security, spelling, and ast-grep. Import analysis found no new cycles or dependency-direction violations.
Discovery performance has not been benchmarked.
Risks
Requires an Agent that supports the AI Guard proxy route. Missing credentials now produce evaluation-time errors instead of preventing client initialization. Evaluations fail if discovery cannot complete within the Agent timeout or no supported route exists.