SkillKit.Agent.StreamAccumulator (SkillKit v0.1.0)

Copy Markdown View Source

Shared helpers for consuming an LLM event stream into an %AssistantMessage{}.

Used by SkillKit.Agent.Server for the main agent loop and by SkillKit.Agent.SkillActivation for the in-process skill sub-loop.

The accumulator is a plain map holding partial text, the running list of tool calls, and accumulated usage. new/0 builds an empty one and finalize/1 turns it into an %AssistantMessage{}.

Event-specific updates (text concatenation, tool-call collection, usage merging) are applied by the caller inside its own Enum.reduce/3, so each consumer can emit its own side effects (event notification, telemetry, agent tagging) without coupling to this module.

Summary

Functions

Finalizes the accumulator into an %AssistantMessage{}.

Types

t()

@type t() :: %{
  text: String.t(),
  tool_calls: [SkillKit.Types.ToolCall.t()],
  usage: %{input_tokens: non_neg_integer(), output_tokens: non_neg_integer()}
}

Functions

finalize(acc)

@spec finalize(t()) :: SkillKit.Types.AssistantMessage.t()

Finalizes the accumulator into an %AssistantMessage{}.

new()

@spec new() :: t()