Class: AgentRuntime::AuditLog

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_runtime/audit_log.rb

Overview

Optional audit logging for agent decisions and results.

This class provides a simple audit logging mechanism that records agent inputs, decisions, and results as JSON to stdout.

Subclass this to implement custom logging (e.g., to a file or database).

Examples:

Basic usage

audit_log = AuditLog.new
audit_log.record(input: "Search", decision: decision, result: { result: "..." })

Custom audit log implementation

class DatabaseAuditLog < AuditLog
  def record(input:, decision:, result:)
    super  # Still log to stdout
    AuditRecord.create(input: input, decision: decision, result: result)
  end
end

Instance Method Summary collapse

Instance Method Details

#record(input:, decision:, result:) ⇒ void

This method returns an undefined value.

Record an audit log entry.

Outputs a JSON object to stdout containing:

  • time: ISO8601 timestamp

  • input: The input that triggered the decision

  • decision: The decision made (converted to hash if possible)

  • result: The execution result

Examples:

audit_log.record(
  input: "What is the weather?",
  decision: Decision.new(action: "search", params: { query: "weather" }),
  result: { result: "Sunny, 72°F" }
)
# Outputs: {"time":"2024-01-01T12:00:00Z","input":"What is the weather?",...}

Parameters:

  • input (String, Object)

    The input that triggered the decision

  • decision (Decision, Hash, nil)

    The decision made (converted to hash if responds to #to_h)

  • result (Hash, Object)

    The execution result



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/agent_runtime/audit_log.rb', line 45

def record(input:, decision:, result:)
  decision_hash = if decision.nil?
                    nil
                  elsif decision.respond_to?(:to_h)
                    decision.to_h
                  else
                    decision
                  end

  puts({
    time: Time.now.utc.iso8601,
    input: input,
    decision: decision_hash,
    result: result
  }.to_json)
end