---
updatedAt: 2025-11-11T01:52:46.000Z
agentTools:
  projectIndex: https://docs.formant.io/llms.txt
---

# Handling commands

This guide will teach you how to create and handle custom commands using the Agent SDK.

# Step 1: Create a custom command

Before you write your command handling script, you'll want to create custom commands in the Formant web application. To do so, see Step 1 of [Create a custom command](https://docs.formant.io/docs/getting-started-create-a-custom-command).

# Step 2: Write a script which registers a command request callback

You can handle commands by using the [`register_command_request_callback()` method of agent client](https://formantio.github.io/python-sdk-docs-website/#formant.sdk.agent.v1.Client.register_command_request_callback):

<Image alt="The register command request callback method in the Agent SDK reference" align="center" src="https://files.readme.io/a9acf4c-Screenshot_2023-12-18_at_1.58.37_PM.png">
  The `register_command_request_callback()` method in the [Agent SDK Reference](https://docs.formant.io/reference/complete-reference).
</Image>

For example:

```python
from formant.sdk.agent.v1 import Client as FormantClient
fclient = FormantClient()

def handle_command_request(request):
  print(request.command)

fclient.register_command_request_callback(
		handle_command_request, command_filter=["sensor_check", "send_on_route"]
)
```

> 🚧
>
> `request.command`, the string you enter in `command_filter`, and the **Command** field you defined in Step 1 must all match.

## Registering multiple callbacks

Multiple commands can be handled by the same callback. You can designate which commands are handled by the callback by adding command names to the `command_filter` list.

> 📘 Single-receiver behavior
>
> If several callbacks are registered to the same agent, such as when multiple applications are running, only one callback will receive any given command request.
>
> This behavior is different from teleoperation command streams. For more information, see [Handling teleop command streams](https://docs.formant.io/reference/integrating-with-formant-teleop#registering-multiple-callbacks).

# Example

For an example of command callbacks, see [GitHub: `handle_commands.py`](https://github.com/FormantIO/formant/blob/master/examples/python/formant_module/agent/handle_commands.py).

<Callout icon="👋" theme="default">
  ### If you notice an issue with this page or need help, please reach out to us! Use the 'Did this page help you?' buttons below, or get in contact with our Customer Success team via the Intercom messenger in the bottom-right corner of this page, or at [support@formant.io](mailto:support@formant.io).
</Callout>