> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.
> For full documentation content, see https://docs.nvidia.com/nemo/guardrails/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.actions.action_dispatcher

Module for the calling proper action endpoints based on events received at action server endpoint

## Module Contents

### Classes

| Name                                                                             | Description |
| -------------------------------------------------------------------------------- | ----------- |
| [`ActionDispatcher`](#nemoguardrails-actions-action_dispatcher-ActionDispatcher) | -           |

### Functions

| Name                                                                         | Description                                                          |
| ---------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [`is_action_file`](#nemoguardrails-actions-action_dispatcher-is_action_file) | Heuristics for determining if a Python file can have actions or not. |

### Data

[`log`](#nemoguardrails-actions-action_dispatcher-log)

### API

```python
class nemoguardrails.actions.action_dispatcher.ActionDispatcher(
    load_all_actions: bool = True,
    config_path: typing.Optional[str] = None,
    import_paths: typing.Optional[typing.List[str]] = None
)
```

Gets the dictionary of registered actions.
Returns:
dict: A dictionary where keys are action names and values are callable action functions.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher._find_actions(
    directory
) -> typing.Dict
```

Loop through all the subdirectories and check for the class with @action
decorator and add in action\_classes dict.

**Parameters:**

The directory to search for actions.

**Returns:** `Dict`

Dictionary of found actions.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher._load_actions_from_module(
    filepath: str
)
```

staticmethod

Loads the actions from the specified python module.

**Parameters:**

The path of the Python module.

**Returns:**

Dictionary of loaded actions.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher._normalize_action_name(
    name: str
) -> str
```

Normalize the action name to the required format.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher.execute_action(
    action_name: str,
    params: typing.Dict[str, typing.Any]
) -> typing.Tuple[typing.Union[typing.Optional[str], typing.Dict[str, typing.Any]], str]
```

async

Execute a registered action.

**Parameters:**

The name of the action to execute.

Parameters for the action.

**Returns:** `Tuple[Union[Optional[str], Dict[str, Any]], str]`

Tuple\[Union\[str, Dict\[str, Any]], str]: A tuple containing the result and status.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher.get_action(
    name: str
) -> typing.Optional[typing.Callable]
```

Get the registered action by name.

**Parameters:**

The name of the action.

**Returns:** `Optional[Callable]`

The registered action.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher.get_registered_actions() -> typing.List[str]
```

Get the list of available actions.

**Returns:** `List[str]`

List\[str]: List of available actions.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher.has_registered(
    name: str
) -> bool
```

Check if an action is registered.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher.load_actions_from_path(
    path: pathlib.Path
)
```

Loads all actions from the specified path.

This method loads all actions from the `actions.py` file if it exists and
all actions inside the `actions` folder if it exists.

**Parameters:**

A string representing the path from which to load actions.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher.register_action(
    action: typing.Callable,
    name: typing.Optional[str] = None,
    override: bool = True
)
```

Registers an action with the given name.

**Parameters:**

The action function.

The name of the action. Defaults to None.

If an action already exists, whether it should be overridden or not.

```python
nemoguardrails.actions.action_dispatcher.ActionDispatcher.register_actions(
    actions_obj: typing.Any,
    override: bool = True
)
```

Registers all the actions from the given object.

**Parameters:**

The object containing actions.

If an action already exists, whether it should be overridden or not.

```python
nemoguardrails.actions.action_dispatcher.is_action_file(
    filepath
)
```

Heuristics for determining if a Python file can have actions or not.

Currently, it only excludes the \`**init**.py files.

```python
nemoguardrails.actions.action_dispatcher.log = logging.getLogger(__name__)
```