# `BB.Jido.Action.WaitForState`
[🔗](https://github.com/beam-bots/bb_jido/blob/main/lib/bb/jido/action/wait_for_state.ex#L5)

Jido action that waits for a Beam Bots robot to enter a target state.

Subscribes to the `[:state_machine]` PubSub topic and blocks until the
robot reports a transition into `:target`, or returns immediately if the
robot is already in that state.

## Schema

- `:robot` — the robot module (required).
- `:target` — the desired robot state atom (required, e.g. `:idle`,
  `:armed`).
- `:timeout` — millisecond timeout (default `30_000`).

## Returns

- `{:ok, %{robot: ..., state: target}}` when the state is reached.
- `{:error, :timeout}` if the timeout elapses first.

## Warning

This action blocks the calling process while waiting. When invoked
directly from a Jido agent it will block the agent server; prefer
running it from a dedicated process or via a workflow when long waits
are expected.

# `__action_metadata__`

Returns the Action metadata. Alias for to_json/0.

# `category`

Returns the category of the Action.

# `description`

Returns the description of the Action.

# `name`

Returns the name of the Action.

# `on_after_run`

Lifecycle hook called after Action execution.

# `on_after_validate_output`

Lifecycle hook called after output validation.

# `on_after_validate_params`

Lifecycle hook called after parameter validation.

# `on_before_validate_output`

Lifecycle hook called before output validation.

# `on_before_validate_params`

Lifecycle hook called before parameter validation.

# `on_error`

Lifecycle hook called when an error occurs.

# `output_schema`

Returns the output schema of the Action.

# `run`

Executes the Action with the given parameters and context.

The `run/2` function must be implemented in the module using Jido.Action.

# `schema`

Returns the input schema of the Action.

# `tags`

Returns the tags associated with the Action.

# `to_json`

Returns the Action metadata as a JSON-serializable map.

# `to_tool`

Converts the Action to an LLM-compatible tool format.

# `validate_output`

```elixir
@spec validate_output(map()) :: {:ok, map()} | {:error, String.t()}
```

Validates the output result for the Action.

## Examples

    iex> defmodule ExampleAction do
    ...>   use Jido.Action,
    ...>     name: "example_action",
    ...>     output_schema: [
    ...>       result: [type: :string, required: true]
    ...>     ]
    ...> end
    ...> ExampleAction.validate_output(%{result: "test", extra: "ignored"})
    {:ok, %{result: "test", extra: "ignored"}}

    iex> ExampleAction.validate_output(%{extra: "ignored"})
    {:error, "Invalid output for Action: Required key :result not found"}

# `validate_params`

```elixir
@spec validate_params(map()) :: {:ok, map()} | {:error, String.t()}
```

Validates the input parameters for the Action.

## Examples

    iex> defmodule ExampleAction do
    ...>   use Jido.Action,
    ...>     name: "example_action",
    ...>     schema: [
    ...>       input: [type: :string, required: true]
    ...>     ]
    ...> end
    ...> ExampleAction.validate_params(%{input: "test"})
    {:ok, %{input: "test"}}

    iex> ExampleAction.validate_params(%{})
    {:error, "Invalid parameters for Action: Required key :input not found"}

# `vsn`

Returns the version of the Action.

---

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