Jido.Composer.ToolConcurrency (Jido Composer v0.6.0)

Copy Markdown View Source

Typed sub-state for tracking tool call concurrency in the Orchestrator.

Replaces flat pending_tool_calls, completed_tool_results, queued_tool_calls, and max_tool_concurrency fields in Orchestrator Strategy.

Summary

Functions

Adds a call ID to pending (e.g., when an approved call is dispatched).

Returns true when no tool calls are pending or queued.

Returns true if at max concurrency capacity.

Records dispatched call IDs and queued calls, resetting completed results.

Drains queued calls into available concurrency slots.

Adds a call to the queue (e.g., when approved but at capacity).

Returns true when there are pending tool calls.

Creates a new ToolConcurrency state.

Records a completed tool result and removes its call_id from pending.

Splits calls into those to dispatch immediately and those to queue, respecting the concurrency limit.

Types

t()

@type t() :: %Jido.Composer.ToolConcurrency{
  completed: [map()],
  max_concurrency: non_neg_integer() | nil,
  max_queue_depth: non_neg_integer() | nil,
  pending: [String.t()],
  queued: [map()]
}

Functions

add_pending(state, call_id)

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

Adds a call ID to pending (e.g., when an approved call is dispatched).

all_clear?(tool_concurrency)

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

Returns true when no tool calls are pending or queued.

at_capacity?(tool_concurrency)

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

Returns true if at max concurrency capacity.

dispatch(state, dispatched_ids, queued_calls)

@spec dispatch(t(), [String.t()], [map()]) :: t()

Records dispatched call IDs and queued calls, resetting completed results.

drain_queue(state)

@spec drain_queue(t()) :: {t(), [map()]}

Drains queued calls into available concurrency slots.

Returns {updated_state, to_dispatch} where to_dispatch is a list of call maps ready to be dispatched.

enqueue(state, call)

@spec enqueue(t(), map()) :: {:ok, t()} | {:error, :queue_full}

Adds a call to the queue (e.g., when approved but at capacity).

Returns {:ok, state} on success, or {:error, :queue_full} if the queue has reached max_queue_depth.

has_pending?(tool_concurrency)

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

Returns true when there are pending tool calls.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new ToolConcurrency state.

record_result(state, call_id, result)

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

Records a completed tool result and removes its call_id from pending.

split_for_dispatch(tool_concurrency, calls)

@spec split_for_dispatch(t(), [map()]) :: {[map()], [map()]}

Splits calls into those to dispatch immediately and those to queue, respecting the concurrency limit.

Returns {to_dispatch, to_queue}.