AgentForge.ExecutionStats (AgentForge v0.2.2)

View Source

Provides functionality for collecting and analyzing execution statistics of flows. Tracks metrics such as execution time, steps taken, and signal patterns.

Summary

Functions

Finalizes the execution stats with the result and calculates elapsed time.

Formats the execution stats into a human-readable report.

Creates a new execution stats struct with initial values.

Records a step in the execution process, updating relevant statistics.

Types

t()

@type t() :: %AgentForge.ExecutionStats{
  complete: boolean(),
  elapsed_ms: integer() | nil,
  handler_calls: %{required(atom()) => non_neg_integer()},
  max_state_size: non_neg_integer(),
  result: any(),
  signal_types: %{required(atom()) => non_neg_integer()},
  start_time: integer(),
  steps: non_neg_integer()
}

Functions

finalize(stats, result)

Finalizes the execution stats with the result and calculates elapsed time.

Parameters

  • stats - Current execution stats struct
  • result - The final result of the flow execution

Examples

iex> stats = AgentForge.ExecutionStats.new()
iex> final = AgentForge.ExecutionStats.finalize(stats, {:ok, "success"})
iex> final.complete and is_integer(final.elapsed_ms) and final.result == {:ok, "success"}
true

format_report(stats)

Formats the execution stats into a human-readable report.

Examples

iex> stats = AgentForge.ExecutionStats.new()
iex> stats = AgentForge.ExecutionStats.finalize(stats, {:ok, "success"})
iex> report = AgentForge.ExecutionStats.format_report(stats)
iex> String.contains?(report, "Total Steps: 0") and String.contains?(report, "Result: {:ok, \"success\"}")
true

new()

Creates a new execution stats struct with initial values.

Examples

iex> stats = AgentForge.ExecutionStats.new()
iex> is_integer(stats.start_time) and stats.steps == 0
true

record_step(stats, handler_info, signal, state)

Records a step in the execution process, updating relevant statistics.

Parameters

  • stats - Current execution stats struct
  • handler_info - Information about the handler being executed
  • signal - The signal being processed
  • state - Current state of the flow

Examples

iex> stats = AgentForge.ExecutionStats.new()
iex> signal = %{type: :test, data: "data"}
iex> updated = AgentForge.ExecutionStats.record_step(stats, :test_handler, signal, %{})
iex> updated.steps == 1 and updated.signal_types == %{test: 1}
true