Skip to content
This repository was archived by the owner on Mar 21, 2026. It is now read-only.

feat: Audit Logging Integration - #50

Merged
limaronaldo merged 1 commit into
mainfrom
feat/audit-integration
Dec 7, 2025
Merged

feat: Audit Logging Integration#50
limaronaldo merged 1 commit into
mainfrom
feat/audit-integration

Conversation

@limaronaldo

Copy link
Copy Markdown
Owner

Summary

Integrates the existing audit crate into the production code path, enabling comprehensive audit logging for LLM operations, tool execution, and HTTP requests.

Changes

Providers Crate (audit feature)

  • AuditedBackend wrapper for any LLMBackend
    • Logs LlmRequest events before inference
    • Logs LlmResponse events with token usage after inference
    • Logs Error events on failures
    • Supports context propagation (trace_id, session_id, agent_id)

Agents Crate (audit feature)

  • AuditedExecutor wrapper for ToolExecutor
    • Logs ToolCall events with parameters and results
    • Logs ApprovalDecision events for denied/skipped tools
    • Logs Error events for approval errors
    • Duration tracking for tool executions

Dashboard Crate (audit feature)

  • REST API Endpoints
    • GET /api/audit/events - List events with filtering (event_type, trace_id, session_id, agent_id, pagination)
    • GET /api/audit/stats - Aggregated statistics by event type
  • HTTP Audit Middleware - Logs all HTTP requests with method, path, status, duration
  • Uses MemoryLogger for queryable in-memory storage

Audit Types Enhancement

  • Added AuditEvent::llm_response() convenience constructor

Testing

  • Providers: 2 new tests (request/response logging, error logging)
  • Agents: 3 new tests (tool calls, denials, multiple tools)
  • Dashboard: 4 new tests (state, logging, stats, conversion)
  • All 9 new tests passing

Usage

// Wrap any LLM backend with audit logging
use rust_ai_agents_providers::AuditedBackend;
use rust_ai_agents_audit::MemoryLogger;

let backend = AnthropicProvider::claude_35_sonnet(api_key);
let logger = Arc::new(MemoryLogger::new());
let audited = AuditedBackend::new(backend, logger)
    .with_trace_id("req-123")
    .with_agent_id("research-agent");

// All LLM calls are now logged
let output = audited.infer(&messages, &tools, 0.7).await?;

Feature Flags

All integrations are opt-in via feature flags:

  • rust-ai-agents-providers/audit
  • rust-ai-agents-agents/audit
  • rust-ai-agents-dashboard/audit

## Providers Crate
- Add AuditedBackend wrapper for LLM backends
- Logs LLM request/response events with token usage
- Logs errors on failed inferences
- Optional via 'audit' feature flag
- 2 new tests

## Agents Crate
- Add AuditedExecutor wrapper for ToolExecutor
- Logs tool executions with parameters and results
- Logs approval decisions (approved/denied/skipped)
- Optional via 'audit' feature flag
- 3 new tests

## Dashboard Crate
- Add audit module with REST API endpoints
- GET /api/audit/events - list events with filtering
- GET /api/audit/stats - aggregated statistics
- HTTP request audit middleware
- Optional via 'audit' feature flag
- 4 new tests

## Audit Types
- Add AuditEvent::llm_response() convenience constructor

All audit integrations are behind feature flags for opt-in usage.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@limaronaldo
limaronaldo merged commit 5b9376f into main Dec 7, 2025
2 checks passed
@limaronaldo
limaronaldo deleted the feat/audit-integration branch December 7, 2025 17:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant