Class: Ask::Agent::Extensions::AuditLog

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/agent/extensions/audit_log.rb

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout, path: nil) ⇒ AuditLog

Returns a new instance of AuditLog.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ask/agent/extensions/audit_log.rb', line 7

def initialize(output: $stdout, path: nil)
  @entries = []
  @mutex = Mutex.new

  if path
    @io = File.open(path, "a")
    @io.sync = true
  else
    @io = output
  end
end

Instance Method Details

#after_tool_call(tool_call, result, _context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ask/agent/extensions/audit_log.rb', line 19

def after_tool_call(tool_call, result, _context)
  entry = {
    timestamp: Time.now.utc.iso8601(3),
    tool_name: tool_call.name,
    arguments: tool_call.arguments,
    result: result,
    duration: result[:duration_ms]
  }

  @mutex.synchronize do
    @entries << entry
    @io.puts entry.to_json
  end

  nil
end

#entriesObject



36
37
38
# File 'lib/ask/agent/extensions/audit_log.rb', line 36

def entries
  @mutex.synchronize { @entries.dup }
end