MingaAgent.ToolCall (Minga v0.1.0)

Copy Markdown View Source

A single tool call in the agent conversation.

Tracks the tool's identity (id, name, args), its execution lifecycle (status, result, error state, timing), and display state (collapsed).

Mutation methods live here so consumers don't scatter %{tc | ...} updates across 11 files. Each method encodes a domain transition: complete/2 records the result and collapses the output, error/2 marks a failure, abort/1 handles user cancellation mid-execution.

Summary

Types

Tool call execution status.

t()

A tool call.

Functions

Aborts a running tool call. Only transitions :running calls.

Marks the tool call as successfully completed, recording the result and duration.

Marks the tool call as failed, recording the error result and duration.

Returns true if the tool call has finished (complete or error).

Creates a new running tool call with a monotonic start timestamp.

Sets the collapsed state to a specific value.

Toggles the collapsed display state.

Updates the partial result during streaming, auto-expanding the display.

Types

status()

@type status() :: :running | :complete | :error

Tool call execution status.

t()

@type t() :: %MingaAgent.ToolCall{
  args: map(),
  collapsed: boolean(),
  duration_ms: non_neg_integer() | nil,
  id: String.t(),
  is_error: boolean(),
  name: String.t(),
  result: String.t(),
  started_at: integer() | nil,
  status: status()
}

A tool call.

Functions

abort(tc)

@spec abort(t()) :: t()

Aborts a running tool call. Only transitions :running calls.

complete(tc, result)

@spec complete(t(), String.t()) :: t()

Marks the tool call as successfully completed, recording the result and duration.

error(tc, result)

@spec error(t(), String.t()) :: t()

Marks the tool call as failed, recording the error result and duration.

finished?(tool_call)

@spec finished?(t()) :: boolean()

Returns true if the tool call has finished (complete or error).

new(id, name, args \\ %{})

@spec new(String.t(), String.t(), map()) :: t()

Creates a new running tool call with a monotonic start timestamp.

set_collapsed(tc, collapsed)

@spec set_collapsed(t(), boolean()) :: t()

Sets the collapsed state to a specific value.

toggle_collapsed(tc)

@spec toggle_collapsed(t()) :: t()

Toggles the collapsed display state.

update_partial(tc, partial_result)

@spec update_partial(t(), String.t()) :: t()

Updates the partial result during streaming, auto-expanding the display.