rcsofttech/audit-trail-ai 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rcsofttech/audit-trail-ai

最新稳定版本:v1.0.0

Composer 安装命令:

composer require rcsofttech/audit-trail-ai

包简介

Optional Symfony AI bridge for AuditTrailBundle that enriches audit logs with compact structured metadata.

README 文档

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.
  • summary is trimmed to the configured max length.
  • severity is limited to info, low, medium, high, or critical.
  • anomaly_score is clamped to a number between 0 and 1.
  • anomaly_hints and tags are deduplicated and limited to the configured max count.

Requirements

  • PHP ^8.4
  • Symfony ^7.4 or ^8.0
  • rcsofttech/audit-trail-bundle ^4.0
  • symfony/ai-bundle ^0.8
  • symfony/ai-agent ^0.8
  • symfony/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-platform
  • symfony/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_class
  • actor.username
  • actor.user_id
  • actor.impersonator
  • request.request_id
  • request.route
  • request.method
  • request.ip_address
  • request.user_agent
  • change.changed_fields
  • change.event
  • custom_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 class marker
  • 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'],
];

rcsofttech/audit-trail-ai 适用场景与选型建议

rcsofttech/audit-trail-ai 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「Audit」 「ai」 「audit-trail」 「structured-output」 「symfony-ai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rcsofttech/audit-trail-ai 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rcsofttech/audit-trail-ai 我们能提供哪些服务?
定制开发 / 二次开发

基于 rcsofttech/audit-trail-ai 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 46
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-11