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.

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:

The register command request callback method in the Agent SDK reference

The register_command_request_callback() method in the Agent SDK Reference.

For example:

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.

Example

For an example of command callbacks, see GitHub: handle_commands.py.

๐Ÿ‘‹

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 [email protected].