rcsofttech / audit-trail-ai
Optional Symfony AI bridge for AuditTrailBundle that enriches audit logs with compact structured metadata.
Package info
github.com/rcsofttech85/AuditTrailAI
Type:symfony-bundle
pkg:composer/rcsofttech/audit-trail-ai
Requires
- php: ^8.4
- rcsofttech/audit-trail-bundle: ^4.0.0
- symfony/ai-agent: ^0.8
- symfony/ai-bundle: ^0.8
- symfony/ai-platform: ^0.8
- symfony/config: ^7.4|^8.0
- symfony/dependency-injection: ^7.4|^8.0
- symfony/framework-bundle: ^7.4|^8.0
- symfony/service-contracts: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.1
Suggests
- symfony/ai-anthropic-platform: Provides an Anthropic platform bridge for Symfony AI.
- symfony/ai-gemini-platform: Provides a Gemini platform bridge for Symfony AI.
- symfony/ai-open-ai-platform: Provides an OpenAI platform bridge for Symfony AI.
README
rcsofttech/audit-trail-ai is an optional Symfony bundle that adds AI-generated metadata to audit logs created by rcsofttech/audit-trail-bundle.
It is built for small, structured output. The AI layer can add a short summary, severity, anomaly score, anomaly hints, and tags without pushing Symfony AI dependencies into the core audit bundle.
What This Package Does
- Keeps AI support optional.
- Uses structured output instead of long free-text responses.
- Sends a compact audit payload to a Symfony AI agent.
- Returns only normalized metadata that fits a strict schema.
- Relies on the core bundle's
AuditLogAiProcessorInterface.
How It Behaves
- This bundle is designed for the core audit bundle's non-blocking AI hook. If AI enrichment fails, audit logging can still continue.
- Empty payloads are skipped, so the AI agent is not called when there is nothing useful to send.
summaryis trimmed to the configured max length.severityis limited toinfo,low,medium,high, orcritical.anomaly_scoreis clamped to a number between0and1.anomaly_hintsandtagsare deduplicated and limited to the configured max count.
Requirements
- PHP
^8.4 - Symfony
^7.4or^8.0 rcsofttech/audit-trail-bundle ^4.0symfony/ai-bundle ^0.8symfony/ai-agent ^0.8symfony/ai-platform ^0.8
Installation
Install this package, the core audit bundle, and Symfony AI:
composer require rcsofttech/audit-trail-ai rcsofttech/audit-trail-bundle symfony/ai-bundle
Then install one Symfony AI platform package for your provider. Example:
composer require symfony/ai-open-ai-platform
Other suggested providers in composer.json are:
symfony/ai-anthropic-platformsymfony/ai-gemini-platform
Basic Setup
Create a Symfony AI agent for audit enrichment.
# config/packages/ai.yaml ai: platform: openai: api_key: '%env(OPENAI_API_KEY)%' agent: audit_trail: model: 'gpt-4o-mini'
Then configure this bundle:
# config/packages/audit_trail_ai.yaml audit_trail_ai: enabled: true agent_service: 'ai.agent.audit_trail' namespace: 'symfony_ai' additional_instructions: null max_summary_length: 240 max_hint_count: 5 max_tag_count: 5 max_context_items: 20
Configuration Reference
| Key | Default | Meaning |
|---|---|---|
enabled |
true |
Turns the AI processor on or off. |
agent_service |
ai.agent.audit_trail |
Symfony service id of the AI agent to call. |
namespace |
symfony_ai |
Key used under context['ai'] for this processor's output. |
additional_instructions |
null |
Extra prompt instructions appended to the system prompt. |
max_summary_length |
240 |
Maximum summary length after normalization. |
max_hint_count |
5 |
Maximum number of anomaly hints kept. |
max_tag_count |
5 |
Maximum number of tags kept. |
max_context_items |
20 |
Maximum number of custom context items included in the AI payload. |
Expected Agent Service
The configured agent_service must:
- exist in the Symfony container
- implement
Symfony\AI\Agent\AgentInterface
If the service is missing or has the wrong class, container compilation will fail with a clear error message.
Input Sent To AI
The processor builds a compact payload from the audit context and optional entity. It can include:
entity_classactor.usernameactor.user_idactor.impersonatorrequest.request_idrequest.routerequest.methodrequest.ip_addressrequest.user_agentchange.changed_fieldschange.eventcustom_context
Reserved keys such as ai, username, route, and changed_fields are handled separately and not duplicated inside custom_context.
Complex values are normalized before they are sent to the AI model:
- enums become their name or backed value
- dates become ISO 8601 strings
- stringable objects become strings
- objects become a small
classmarker - deep or large data is truncated
Output Shape
The AI response is expected to match a strict JSON schema. After normalization, the stored metadata looks like this:
$auditLog->context['ai']['symfony_ai'] = [ 'summary' => 'Customer email changed from admin flow.', 'severity' => 'medium', 'anomaly_score' => 0.42, 'anomaly_hints' => ['privileged action', 'sensitive field touched'], 'tags' => ['account', 'admin'], ];