Jido.Composer.Orchestrator.AgentTool (Jido Composer v0.6.0)

Copy Markdown View Source

Converts Nodes into ReqLLM Tool structs for LLM function calling.

Bridges the gap between Node metadata and ReqLLM.Tool structs. Three operations handle the full round-trip: Node → tool description, tool call → context, and execution result → tool result message.

Summary

Functions

Converts tool call arguments to a context map for node execution.

Converts a Node or action module into a ReqLLM.Tool struct.

Builds a normalized tool result from node execution output.

Functions

to_context(call, valid_keys \\ nil)

@spec to_context(map(), MapSet.t(atom()) | nil) :: map()

Converts tool call arguments to a context map for node execution.

Atomizes string keys so that the resulting map matches the keyword-style keys nodes expect. When valid_keys is provided, only keys in the set are accepted; otherwise falls back to String.to_existing_atom/1.

to_tool(node)

Converts a Node or action module into a ReqLLM.Tool struct.

Returns %ReqLLM.Tool{} with name, description, parameter_schema (JSON Schema map), and a no-op callback (the orchestrator executes tools externally).

Node structs delegate to their to_tool_spec/1 callback. Raw action modules are handled directly for the termination tool use case.

to_tool_result(call_id, node_name, arg)

@spec to_tool_result(
  String.t(),
  String.t(),
  {:ok, map() | Jido.Composer.NodeIO.t()} | {:error, term()}
) ::
  map()

Builds a normalized tool result from node execution output.

Returns %{id, name, result} for feeding back into the LLM conversation.