# `Jido.Composer.Node`
[🔗](https://github.com/lostbean/jido_composer/blob/main/lib/jido/composer/node.ex#L1)

Uniform context-in/context-out interface for workflow participants.

Every participant in a composition — actions, agents, nested workflows —
implements this behaviour. Nodes form an endomorphism monoid over context
maps, composed via Kleisli arrows.

## Return Types

- `{:ok, context}` — success with implicit outcome `:ok`
- `{:ok, context, outcome}` — success with explicit outcome for FSM transitions
- `{:error, reason}` — failure with implicit outcome `:error`

## Directive Generation

The `to_directive/3` callback allows strategies to dispatch nodes polymorphically
without pattern-matching on concrete struct types. Each node knows how to produce
the appropriate directive(s) for execution given a flat context and keyword opts.

Opts carry strategy-specific metadata (e.g. `:result_action`, `:tag`, `:meta`)
so the node remains strategy-agnostic.

The `to_tool_spec/1` callback lets nodes describe themselves as LLM tool definitions
for orchestrator contexts. Nodes that cannot act as tools return `nil`.

# `context`

```elixir
@type context() :: map()
```

# `directive_result`

```elixir
@type directive_result() :: {:ok, [struct()]} | {:ok, [struct()], keyword()}
```

# `outcome`

```elixir
@type outcome() :: atom()
```

# `result`

```elixir
@type result() :: {:ok, context()} | {:ok, context(), outcome()} | {:error, term()}
```

# `description`

```elixir
@callback description(node :: struct()) :: String.t()
```

# `input_type`
*optional* 

```elixir
@callback input_type(node :: struct()) :: :map | :text | :object | :any
```

# `name`

```elixir
@callback name(node :: struct()) :: String.t()
```

# `output_type`
*optional* 

```elixir
@callback output_type(node :: struct()) :: :map | :text | :object | :any
```

# `run`

```elixir
@callback run(node :: struct(), context :: context(), opts :: keyword()) :: result()
```

# `schema`
*optional* 

```elixir
@callback schema(node :: struct()) :: keyword() | nil
```

# `to_directive`
*optional* 

```elixir
@callback to_directive(node :: struct(), flat_context :: map(), opts :: keyword()) ::
  directive_result()
```

# `to_tool_spec`
*optional* 

```elixir
@callback to_tool_spec(node :: struct()) :: map() | nil
```

# `agent_module?`

```elixir
@spec agent_module?(module()) :: boolean()
```

Returns `true` if `module` is a compiled `Jido.Agent` module.

# `ai_agent_module?`

```elixir
@spec ai_agent_module?(module()) :: boolean()
```

Returns `true` if `module` is a Jido.AI agent (exports `ask_sync/3`).

Jido.AI agents require a running AgentServer process and communicate
via `ask_sync(pid, query, opts)` rather than struct-based `run_sync/2`.

# `dispatch_name`

```elixir
@spec dispatch_name(struct()) :: String.t()
```

Extracts the name from a Node struct.

Validates that the struct's module implements the Node behaviour before
calling `name/1`. Raises `ArgumentError` if it does not.

Used by `AgentTool`, `Configure`, and `Strategy` to handle custom Node
structs without duplicating the dispatch + validation logic.

# `execute_child_sync`

```elixir
@spec execute_child_sync(module(), map()) :: {:ok, term()} | {:error, term()}
```

Runs a child agent module synchronously.

Supports three agent types:
- Composer Workflow agents (`run_sync/2`)
- Composer Orchestrator agents (`query_sync/3`)
- Jido.AI agents (`ask_sync/3` via a temporary AgentServer process)

# `node?`

```elixir
@spec node?(module()) :: boolean()
```

Returns `true` if `module` declares the `Jido.Composer.Node` behaviour.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
