Class: SwarmSDK::TranscriptBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/transcript_builder.rb

Overview

Transforms raw log events into LLM-readable conversation transcripts

TranscriptBuilder converts the structured event log from swarm execution into a human/LLM-readable format suitable for reflection, analysis, or memory creation.

Examples:

Basic usage

transcript = TranscriptBuilder.build(result.logs)
# => "USER: Help me with CORS\n\nAGENT [assistant]: ..."

Filter by agents

transcript = TranscriptBuilder.build(result.logs, agents: [:backend, :database])

Custom options

transcript = TranscriptBuilder.build(
  result.logs,
  include_tool_results: true,
  max_result_length: 1000,
  include_thinking: false
)

Constant Summary collapse

DEFAULT_MAX_RESULT_LENGTH =

Default maximum length for tool result content

500
DEFAULT_MAX_ARGS_LENGTH =

Default maximum length for tool arguments

200

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logs, agents: nil, include_tool_results: true, include_thinking: false, max_result_length: DEFAULT_MAX_RESULT_LENGTH, max_args_length: DEFAULT_MAX_ARGS_LENGTH) ⇒ TranscriptBuilder

Initialize a new TranscriptBuilder



62
63
64
65
66
67
68
69
70
# File 'lib/swarm_sdk/transcript_builder.rb', line 62

def initialize(logs, agents: nil, include_tool_results: true, include_thinking: false,
  max_result_length: DEFAULT_MAX_RESULT_LENGTH, max_args_length: DEFAULT_MAX_ARGS_LENGTH)
  @logs = logs || []
  @agents = normalize_agents(agents)
  @include_tool_results = include_tool_results
  @include_thinking = include_thinking
  @max_result_length = max_result_length
  @max_args_length = max_args_length
end

Class Method Details

.build(logs, agents: nil, include_tool_results: true, include_thinking: false, max_result_length: DEFAULT_MAX_RESULT_LENGTH, max_args_length: DEFAULT_MAX_ARGS_LENGTH) ⇒ String

Build a transcript from log events



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/swarm_sdk/transcript_builder.rb', line 41

def build(logs, agents: nil, include_tool_results: true, include_thinking: false,
  max_result_length: DEFAULT_MAX_RESULT_LENGTH, max_args_length: DEFAULT_MAX_ARGS_LENGTH)
  new(
    logs,
    agents: agents,
    include_tool_results: include_tool_results,
    include_thinking: include_thinking,
    max_result_length: max_result_length,
    max_args_length: max_args_length,
  ).build
end

Instance Method Details

#buildString

Build the transcript



75
76
77
78
79
# File 'lib/swarm_sdk/transcript_builder.rb', line 75

def build
  @logs
    .filter_map { |event| format_event(event) }
    .join("\n\n")
end