Skip to content

RFC: optional event sink for calls the guard does not pass #24

Closed

Description

@blitzcrieg1

Follows #20.

Problem

When SafeAgents blocks a call, the harness never runs it, so hook-based recorders and audit tools never see the attempt. The record exists only in calls.jsonl.

Now that the journal format is documented, a tool can tail that file, but that has limits. It has to poll, it reads a file that can hold secrets, and it gets nothing under --no-journal. There is also no supported way to react to a verdict as it happens.

This affects anyone who wants SafeAgents' decisions in a SIEM or an audit trail.

Proposal

Add an optional, repeatable --sink MODULE:FACTORY (or path/to/file.py:FACTORY), with the same convention as --plugin. FACTORY() returns a callable that receives one dict per call:

# my_sink.py
def sink():
    def handle(entry: dict) -> None:
        ...  # send it wherever you need
    return handle
safeagents start URL --sink my_sink:sink

Suggested behaviour:

  • Called for every verdict other than passed, at the point where Guard.allow writes the journal.
  • entry has the fields in docs/journal.md, so there is one format to keep stable. id is null under --no-journal. A session ID would be added here if Documented journal schema or event sink, so blocked calls can reach audit trails #20's second point lands.
  • A sink must never delay a response or change a verdict. It runs off the event loop with a short timeout, and exceptions are logged and ignored.
  • Off by default, with no new dependencies. SafeAgents does no network delivery itself, so it holds no sink URLs or tokens.
  • arguments and task can hold secrets, as the journal notes, so the docs should say a sink receives them and is responsible for what it does with them.

From Python, this could be Config(sinks=[...]).

Alternatives

  • Tail calls.jsonl. Needs no change and works today, with the limits above. An adapter can start here either way.
  • A built-in webhook. Simple to use, but SafeAgents would take on URLs, credentials, retries and a payload contract.
  • Run a command per event. Language-neutral, but it starts a process for each call and passes potentially secret data to it.
  • OTLP or OCSF output. Useful for some users, but it picks one schema for everyone, and could be built as a sink later.

If this direction works for you, I'm happy to send a branch following the process in CONTRIBUTING.md. If you would rather keep the proxy minimal, the journal alone is enough for a first adapter.

Activity

  1. younesbelkada commented on Nov 11, 2026

    @younesbelkada
    Collaborator

    Hi @blitzcrieg1
    Thanks for the RFC - the proposed plan sounds great. Could you share a minimal PR on your fork to demostrate how the integration will look like? Also if you could document some potential usecases (maybe by combining it with Agentmetrics) in docs/ (maybe create a new file sink.md ). Thank you!

  2. blitzcrieg1 commented on Nov 11, 2026

    @blitzcrieg1
    ContributorAuthor

    Thanks for the feedback. The minimal sink prototype is on this fork branch:

    https://github.com/blitzcrieg1/safeagents/tree/feature/optional-event-sinks

    It adds repeatable --sink MODULE:FACTORY loading and Config(sinks=[...]), using the journal-shaped observation for non-passed calls, including with --no-journal. Delivery is off the response loop and bounded per sink. The deadline is explicit about Python's inability to cancel a running callback; callbacks need their own I/O timeouts, and notifications can be dropped.

    docs/sink.md covers the raw-payload privacy boundary, a metadata-only output example and possible Agentmetry/SIEM uses. It does not claim a live Agentmetry adapter or infer tool execution from an allowed proposal. The branch includes guard, CLI, journal and scripted proxy regression cases.

    Please let me know whether this is the right shape before adding any destination-specific adapter.

  3. blitzcrieg1 commented on Nov 12, 2026

    @blitzcrieg1
    ContributorAuthor

    Here is the minimal PR on my fork, as you asked: blitzcrieg1#1

    It is one commit on top of current main. It adds a repeatable --sink MODULE:FACTORY and Config(sinks=[...]), delivers off the response path with a bounded queue per sink, and adds docs/sink.md with use cases, including recording blocked calls in Agentmetry. Delivery is best effort: a full queue, a failing callback or shutdown can drop a notification, and the doc says so.

    Happy to change anything. If it looks right, the branch is ready for you to open upstream.

  4. younesbelkada commented on Nov 15, 2026

    @younesbelkada
    Collaborator

    Thanks @blitzcrieg1 ! Reviewed and tested your changes, all is good !

  5. blitzcrieg1 commented on Nov 15, 2026

    @blitzcrieg1
    ContributorAuthor

    Thanks for reviewing, testing and merging it, and for keeping the boundaries in the doc. I'll close my fork PR. If anyone wants to record denied attempts in Agentmetry through a sink, I'm happy to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions