Use the Actions Server
The Actions Server enables you to run actions invoked from guardrails in a secure, isolated environment separate from the main guardrails server.
Why Use an Actions Server?
Actions are custom Python functions that guardrails can invoke during processing. Running actions in a separate server provides:
- Security isolation: Actions run in a separate process, limiting the impact of potentially unsafe code.
- Resource management: Separate resource allocation for action execution.
- Scalability: Scale the actions server independently from the guardrails server.
Using an actions server is optional but highly recommended for production deployments. If no actions server is configured, actions run in the same process as the guardrails server.
For more details on security considerations, see Security.
Start the Actions Server
Launch the actions server using the CLI:
The default port is 8001.
Example
On startup, the actions server automatically registers:
- All predefined actions from the NeMo Guardrails library.
- All actions defined in Python files in the current folder and sub-folders.
Endpoints
The actions server exposes two endpoints:
View the OpenAPI documentation at:
- Swagger UI:
http://localhost:8001/docs - ReDoc:
http://localhost:8001/redoc
GET /v1/actions/list
List all available actions registered with the server.
Request
Response
Returns an array of action names:
Python Example
POST /v1/actions/run
Execute an action with the specified parameters.
Request Body
Response Body
Example: Wolfram Alpha Query
Response:
Python Example
Configure Guardrails to Use the Actions Server
To configure a guardrails configuration to use a remote actions server, add the actions_server_url to your config.yml:
When configured, the guardrails server sends action execution requests to the actions server instead of running them locally.
Register Custom Actions
The actions server automatically discovers actions in the current directory. Create a Python file with your custom actions:
Start the actions server from the directory containing your actions:
Your custom actions are now available:
Example: Complete Workflow
This example demonstrates running both servers together.
-
Start the Actions Server.
-
Configure a guardrails configuration to use the actions server.
-
Start the guardrails server.
-
Test the servers.
Deployment Considerations
For production deployments:
- Network isolation: Deploy the actions server in a separate network segment.
- Authentication: Add authentication between the guardrails and actions servers.
- Resource limits: Configure appropriate resource limits for action execution.
- Monitoring: Monitor action execution times and failure rates.
- Logging: Enable detailed logging for debugging and auditing.