Skip to main content
Glama

Dream Audit Log

graph_audit

Records a detailed audit log of dream process events, enabling reconstruction of entity-resolution decisions for later graph unmerge operations.

Instructions

Append a structured event to the dream process audit log (logs/dream-audit.jsonl). Call this during the dream process to record run_start, run_end, transcript_start, transcript_end, entity_created, entity_resolved, edge_created, edge_modified, merge_flagged, contradiction_found, ingest_start, ingest_end, decay_applied, format_warning, or error events. entity_resolved is the audit trail for entity-resolution decisions during dream — every time the dream picks between matching an existing entity, creating a new one, or flagging an ambiguous candidate, log it here so a later graph_unmerge can reconstruct why a merge happened.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
eventYesEvent type
dataYesEvent payload — fields vary by event type. Always include relevant names/IDs.

Implementation Reference

  • Handler function for the graph_audit tool. Calls appendAuditEvent to write the structured event to logs/dream-audit.jsonl.
    }, async ({ event, data }) => {
      const auditEvent = {
        event,
        timestamp: new Date().toISOString(),
        ...data,
      } as DreamAuditEvent;
      appendAuditEvent(auditEvent);
      return toolResult({ logged: true, event, timestamp: auditEvent.timestamp });
    });
  • Zod input schema for graph_audit: requires an event enum and a data record.
    inputSchema: {
      event: z
        .enum([
          "run_start", "run_end",
          "transcript_start", "transcript_end", "transcript_skipped",
          "entity_created", "entity_resolved", "edge_created", "edge_modified",
          "merge_flagged", "contradiction_found",
          "ingest_start", "ingest_end",
          "decay_applied", "format_warning", "error",
        ])
        .describe("Event type"),
      data: z
        .record(z.string(), z.unknown())
        .describe("Event payload — fields vary by event type. Always include relevant names/IDs."),
    },
  • Registration of graph_audit tool with the MCP server, including title and description.
    server.registerTool("graph_audit", {
      title: "Dream Audit Log",
      description:
        "Append a structured event to the dream process audit log (logs/dream-audit.jsonl). " +
        "Call this during the dream process to record run_start, run_end, transcript_start, " +
        "transcript_end, entity_created, entity_resolved, edge_created, edge_modified, merge_flagged, " +
        "contradiction_found, ingest_start, ingest_end, decay_applied, format_warning, or error events. " +
        "entity_resolved is the audit trail for entity-resolution decisions during dream — every time the " +
        "dream picks between matching an existing entity, creating a new one, or flagging an ambiguous " +
        "candidate, log it here so a later graph_unmerge can reconstruct why a merge happened.",
      inputSchema: {
        event: z
          .enum([
            "run_start", "run_end",
            "transcript_start", "transcript_end", "transcript_skipped",
            "entity_created", "entity_resolved", "edge_created", "edge_modified",
            "merge_flagged", "contradiction_found",
            "ingest_start", "ingest_end",
            "decay_applied", "format_warning", "error",
          ])
          .describe("Event type"),
        data: z
          .record(z.string(), z.unknown())
          .describe("Event payload — fields vary by event type. Always include relevant names/IDs."),
      },
    }, async ({ event, data }) => {
      const auditEvent = {
        event,
        timestamp: new Date().toISOString(),
        ...data,
      } as DreamAuditEvent;
      appendAuditEvent(auditEvent);
      return toolResult({ logged: true, event, timestamp: auditEvent.timestamp });
    });
  • Helper function that appends a structured audit event to logs/dream-audit.jsonl.
    export function appendAuditEvent(event: DreamAuditEvent): void {
      try {
        mkdirSync(join(GRAPH_MEMORY_HOME, "logs"), { recursive: true });
        appendFileSync(AUDIT_LOG, JSON.stringify(event) + "\n");
      } catch { /* never throw from audit */ }
    }
    
    /** Convenience wrapper — stamps timestamp automatically. */
    export function auditEvent<T extends DreamAuditEvent["event"]>(
      eventType: T,
      data: Omit<Extract<DreamAuditEvent, { event: T }>, "event" | "timestamp">,
    ): void {
      appendAuditEvent({
        event: eventType,
        timestamp: new Date().toISOString(),
        ...data,
      } as unknown as DreamAuditEvent);
    }
  • TypeScript discriminated union type defining all possible audit event shapes.
    export type DreamAuditEvent =
      | (BaseEvent & {
          event: "run_start";
          source: string;
          transcripts_pending: number;
          ingest_pending: number;
        })
      | (BaseEvent & {
          event: "run_end";
          source: string;
          duration_ms: number;
          transcripts_processed: number;
          ingest_processed: number;
          entities_created: number;
          edges_created: number;
          errors: number;
        })
      | (BaseEvent & {
          event: "transcript_start";
          session_id: string;
          file_path: string;
          line_count: number;
        })
      | (BaseEvent & {
          event: "transcript_end";
          session_id: string;
          entities_extracted: number;
          edges_created: number;
        })
      | (BaseEvent & {
          event: "transcript_skipped";
          session_id: string;
          file_path: string;
          reason: string;
        })
      | (BaseEvent & {
          event: "entity_created";
          name: string;
          entity_type: string;
          confidence: number;
          source_session: string;
        })
      | (BaseEvent & {
          event: "edge_created";
          from_name: string;
          to_name: string;
          relation: string;
          weight: number;
          source_session: string;
        })
      | (BaseEvent & {
          event: "edge_modified";
          from_name: string;
          to_name: string;
          relation: string;
          old_weight: number;
          new_weight: number;
        })
      | (BaseEvent & {
          event: "entity_resolved";
          /** Raw name as encountered in the transcript/document. */
          candidate_name: string;
          /** Action taken — see prompts/dream-nightly.md §4e for definitions. */
          action:
            | "matched_existing"   // candidate matched an existing entity by name/alias/embedding
            | "created_new"        // no match strong enough; created a fresh entity
            | "skipped_ambiguous"  // multiple candidates above threshold, none clearly best — left unresolved
            | "alias_attached";    // candidate kept distinct but linked via ALIAS_OF to canonical
          /** Resolved entity id when action != "skipped_ambiguous". */
          chosen_id?: string;
          /** Why this action was chosen — "exact name match", "embedding sim 0.91 to <id>",
           *  "name token Jaccard 0.8 with <id>", "no candidate above threshold", etc. */
          reason: string;
          /** Cosine similarity score when the decision was driven by embeddings. */
          similarity_score?: number;
          /** Source session for cross-referencing against the changelog. */
          source_session?: string;
        })
      | (BaseEvent & {
          event: "merge_flagged";
          entity_a: string;
          entity_b: string;
          reason: string;
        })
      | (BaseEvent & {
          event: "contradiction_found";
          entity_a: string;
          entity_b: string;
          relation: string;
          description: string;
        })
      | (BaseEvent & {
          event: "ingest_start";
          file_path: string;
        })
      | (BaseEvent & {
          event: "ingest_end";
          file_path: string;
          entities_extracted: number;
          edges_created: number;
        })
      | (BaseEvent & {
          event: "decay_applied";
          nodes_affected: number;
          edges_affected: number;
        })
      | (BaseEvent & {
          event: "format_warning";
          file_path: string;
          format_version: string;
          warnings: string[];
        })
      | (BaseEvent & {
          event: "error";
          context: string;
          message: string;
        });
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It discloses that events are appended to a specific file and details the entity_resolved event's role. However, it does not mention potential side effects like file growth or latency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with two sentences, front-loading the core action. It could be slightly more structured, but it efficiently conveys key information without unnecessary detail.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite lacking annotations and output schema, the description adequately covers event types and their purpose, including the link to graph_unmerge. It could elaborate on edge cases or error handling, but it is sufficient for core usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description adds significant meaning by listing all event types and instructing to always include 'relevant names/IDs', which goes beyond the schema's generic 'fields vary by event type'.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (append), resource (dream audit log), and context (during the dream process). It lists specific event types, making the tool's purpose unambiguous and distinguishing it from sibling tools like graph_merge and graph_unmerge.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to call the tool ('during the dream process') and explains the purpose of entity_resolved events for later use with graph_unmerge. However, it does not explicitly state when not to use the tool or compare with alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/stevepridemore/graph-memory'

If you have feedback or need assistance with the MCP directory API, please join our Discord server