← Back to Pull requests

feat(agent-os): add OCSF schema converter and sink for CloudEvents tr… #4323

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 15, 2026 08:43 UTC
Author

Related Issue

No linked issue — see Problem & Solution below.

Problem & Solution

Problem:
Agent Governance Toolkit standardizes on CloudEvents v1.0 for audit, policy, and trace event delivery (e.g. GovernanceEvent.to_cloudevent(), StdoutGovernanceSink, OTLPGovernanceSink). However, enterprise security data lakes, XDRs, and modern SIEMs (such as Amazon Security Lake, Splunk, Datadog, and IBM QRadar) standardize on the Open Cybersecurity Schema Framework (OCSF). Ingesting raw CloudEvents into these platforms currently requires external, custom ETL pipelines that often drop trace correlation identifiers (traceid, spanid, parentspanid) or lose unmapped governance context.

Solution:
This PR introduces native OCSF v1.3.0 schema conversion and a streaming sink to agent-os:

1. agent_os.ocsf — new module containing:
- cloudevent_to_ocsf: Converts any CloudEvents v1.0 governance or trace envelope into an OCSF v1.3.0 record.
- Dynamic classification into standard OCSF classes:
- Class 2001 (Security Finding): Policy violations, blocked tool calls, prompt injection detections, and MCP tool poisoning (category_uid: 2).
- Class 6003 (API Activity): Policy checks, tool invocations, and resource accesses (category_uid: 6).
- Class 3002 (Authorize Session): Agent identity verification, rejections, and trust handshakes (category_uid: 3).
- Full trace correlation preservation: extracts traceid, spanid, parentspanid, and sessionid into OCSF metadata.correlation_uid and observability objects.
- 100% data fidelity: custom and non-standard payload attributes are retained under unmapped.
- OCSFGovernanceSink: A streaming sink implementing GovernanceEventSinkBase that outputs newline-delimited JSON (NDJSON), ready for direct forwarding to SIEM collectors or AWS Security Lake.

2. GovernanceEvent.to_ocsf() — direct serialization convenience method added on the immutable GovernanceEvent envelope alongside the existing to_cloudevent() and to_dict().

Impact on Your Work

Enables streaming agent governance, policy checks, and trace audit logs directly into OCSF-compliant SIEMs and security data lakes without writing proprietary format converters. Security teams can now correlate agent behavior with enterprise identity and threat logs using standard OCSF queries, with zero data loss and full trace context preserved.

Timeline

None

Alternatives Considered

1. Handling conversion downstream via Logstash / FluentBit plugins — Rejected because downstream log shippers lack semantic domain knowledge of AGT's policy decisions, reasons, and kind enums, leading to lossy conversions.
2. Replacing CloudEvents entirely with OCSF — Rejected because CloudEvents is the established CNCF transport standard across AGT's event bus and broker integrations (Azure Event Grid, EventBridge). Translating CloudEvents to OCSF preserves dual compatibility.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

  • New feature (non-breaking change that adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

  • Documentation update

  • Maintenance (dependency updates, CI/CD, refactoring)

  • Security fix
  • Package(s) Affected

    Core & runtime:

  • agent-governance-toolkit-core

  • agent-primitives

  • agent-os

  • agent-mesh

  • agent-runtime

  • agent-sre

  • agent-compliance
  • Governance & security:

  • agent-mcp-governance

  • agent-rag-governance

  • agent-sandbox

  • agent-discovery

  • agt-policies

  • policy-engine
  • Platform & tooling:

  • agent-hypervisor

  • agent-lightning

  • agent-marketplace

  • agent-governance-toolkit-cli

  • agent-governance-toolkit-integrations

  • agent-governance-toolkit-protocols

  • agentmesh-integrations (framework integrations)
  • CLI plugins:

  • agent-governance CLI plugins (copilot-cli / claude-code / opencode / antigravity-cli)
  • Shared / other:

  • schemas

  • action (GitHub Action)

  • examples

  • docs / root
  • Testing

    Unit Testing

    Added agent-governance-python/agent-os/tests/test_ocsf.py with 8 comprehensive unit tests:

    | Test | What it covers |
    |---|---|
    | test_security_finding_policy_violation | Class 2001 mapping, blocked disposition, failure status, trace IDs |
    | test_api_activity_policy_check_allowed | Class 6003 mapping, API operation, request resource, allowed disposition |
    | test_authorize_session_identity_verified | Class 3002 mapping and session ID binding |
    | test_agentmesh_cloudevent_compatibility | AgentMesh CloudEvent compatibility, custom hashes in unmapped |
    | test_direct_governance_event_to_ocsf | Direct conversion from GovernanceEvent instance |
    | test_governance_event_method_to_ocsf | GovernanceEvent.to_ocsf() convenience method |
    | test_emit_writes_ndjson_to_stream | Multi-line NDJSON output from OCSFGovernanceSink |
    | test_processor_fan_out_with_ocsf_sink | Async batch delivery via GovernanceEventProcessor |

    Manual Testing

    Ran full test suite locally under Python 3.14 on Windows:

    python -m pytest agent-governance-python/agent-os/tests/test_event_sink.py \
                     agent-governance-python/agent-os/tests/test_ocsf.py -v
    

    Result: 42 passed (34 existing regression tests + 8 new OCSF tests), 0 failures.

    Checklist

  • I have linked a related issue above, or completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"

  • My code follows the project style guidelines (ruff check)

  • I have added tests that prove my fix/feature works

  • All new and existing tests pass (pytest)

  • I have updated documentation as needed (updated CHANGELOG.md under [Unreleased])

  • I have signed the Microsoft CLA
  • Attribution & Prior Art

  • This contribution does not contain code copied or derived from other projects without attribution

  • Any external projects that inspired this design are credited in code comments or documentation

  • If this PR implements functionality similar to an existing open-source project, I have listed it below
  • Prior art / related projects:

  • Open Cybersecurity Schema Framework (OCSF) v1.3.0 — Linux Foundation / OCSF consortium: https://schema.ocsf.io/

  • CNCF CloudEvents v1.0 specification: https://cloudevents.io/
  • AI Assistance

  • I can explain every meaningful change in this PR: what it does, why, and what tradeoffs were considered

  • I have run tests and verification appropriate for this change

  • No part of this PR was autonomously submitted by an AI agent without my review

  • I have not used AI to generate review comments on others' PRs
  • AI tools used: Antigravity (Gemini) was used for scaffolding the OCSF class mappings and unit test cases; all logic, types, and test results were reviewed and verified locally before committing.

    IP, Patents, and Licensing

  • This contribution does not implement patent-pending or patent-encumbered techniques

  • This contribution does not require an NDA or licensing agreement to understand or use

  • Any AI tools used have terms compatible with the MIT License
  • ---

    Usage Example

    from agent_os.event_sink import GovernanceEvent, GovernanceEventKind
    from agent_os.ocsf import OCSFGovernanceSink, cloudevent_to_ocsf
    from agent_os import GovernanceEventProcessor
    
    # 1. Direct serialization on GovernanceEvent (.to_ocsf)
    event = GovernanceEvent(
        agent_id="agent-01",
        action="database:query",
        decision="allow",
        trace_id="tr-102938",
        kind=GovernanceEventKind.POLICY_CHECK,
    )
    ocsf_record = event.to_ocsf()
    
    # 2. Convert an existing CloudEvents 1.0 envelope
    ce = event.to_cloudevent(source="/agent-os/prod")
    ocsf_record = cloudevent_to_ocsf(ce)
    
    # 3. Real-time streaming NDJSON to SIEM via OCSFGovernanceSink
    processor = GovernanceEventProcessor()
    processor.add_sink(OCSFGovernanceSink(source="/agent-os/prod"))
    processor.on_event(event)
    processor.shutdown()
    

    OCSF Class Mapping Reference

    | GovernanceEventKind | OCSF Class | Class UID |
    |---|---|---|
    | POLICY_VIOLATION, TOOL_CALL_BLOCKED, PROMPT_INJECTION_DETECTED, MCP_TOOL_POISONING, CONTENT_VIOLATION, ANOMALY_DETECTED | Security Finding | 2001 |
    | IDENTITY_VERIFIED, IDENTITY_REJECTED, ESCALATION_REQUESTED | Authorize Session | 3002 |
    | POLICY_CHECK, RESOURCE_ACCESS, CHECKPOINT_CREATED | API Activity | 6003 |

    Future Work

    Follow-up PRs can bring OCSF schema conversion parity to the standalone .NET (agent-governance-dotnet) and Rust (agent-governance-rust) SDKs.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: MohammadHaroonAbuomar Review duration: 494m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4323"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%