Connector
Register Python functions as testable endpoints in Rhesis using the SDK connector. This code-first approach automatically creates and manages endpoints, providing an alternative to manual endpoint configuration.
How it works: Decorate functions with @collaborate and they automatically become endpoints
in Rhesis. The SDK connects via WebSocket, registers function metadata, and keeps endpoints in
sync with your code.
Quick Start
1. Initialize the Client
2. Decorate Functions
3. Automatic Registration
When your app starts, functions are automatically registered as endpoints. View them in Projects → Your Project → Endpoints.
Environment
The environment parameter is required and must be one of:
development: Local iteration and testingstaging: Pre-production validationproduction: Live systems
Production: Changes take effect immediately. Test in development/staging first.
Mapping
Auto-Mapping (Recommended)
Use standard field names for automatic detection:
Standard fields:
- Request:
input,session_id,context,metadata,tool_calls - Response:
output,context,metadata,tool_calls,session_id
Manual Mapping
For custom parameter names or complex structures, provide explicit mappings:
Request Mapping (Jinja2 Templates):
- Use Jinja2 template syntax:
{{ variable_name }} - Maps standard Rhesis request fields (
input,session_id,context) to your function parameters - Custom fields from the request are passed through automatically
- Example:
"user_message": "{{ input }}"maps the Rhesisinputfield to your function’suser_messageparameter
Response Mapping (JSONPath or Jinja2):
- JSONPath syntax (starting with
$): Use for direct field extraction- Example:
"output": "$.choices[0].message.content"extracts a nested field - Example:
"session_id": "$.conv_id"extracts a top-level field
- Example:
- Jinja2 templates: Use with
jsonpath()function for conditional logic or complex extraction- Example:
"output": "{{ jsonpath('$.text_response') or jsonpath('$.result.content') }}"tries the first path, falls back to second if empty - Pure JSONPath expressions (starting with
$) work directly without Jinja2
- Example:
For conditional logic or fallback values, use Jinja2 templates with jsonpath():
Examples
Multiple Functions
Custom Fields
Platform Integration
Viewing Endpoints
Registered endpoints appear in the Rhesis dashboard:
- Location: Projects → Your Project → Endpoints
- Connection Type:
SDK - Status:
Active(connected) orInactive(disconnected) - Naming:
{Project Name} ({function_name})
Connection Management
- Reconnection: SDK automatically reconnects with exponential backoff if connection is lost
- Re-registration: Functions are automatically re-registered on reconnect
- Function changes: Adding/modifying functions updates endpoints automatically; removing functions marks endpoints as Inactive
Best Practices
- Use connectors when: Functions are in your codebase, using standard patterns, want code-first definition
- Use manual config when: Testing external APIs, need complex transformations, services outside codebase
- Function naming: Use descriptive names (avoid
function1,handler) - Type hints: Always include type hints for better auto-detection
- Error handling: Return structured error responses:
{"output": None, "status": "error", "error": str(e)}
Troubleshooting
Functions not appearing:
- Verify
RhesisClientinitialized withapi_key,project_id, andenvironment - Check functions use
@collaborate()decorator - Check logs for “Connector initialized” and “Sent registration” messages
Connection issues:
- Verify API key and project ID are correct
- Ensure Rhesis backend is accessible
- Check firewall/network settings for WebSocket connections
Mapping problems:
- Auto-mapping: Use standard field names (
input,session_id,output) - Manual mapping: Verify Jinja2/JSONPath syntax
- Custom fields: Ensure custom request fields are included in API requests
Common errors:
"RhesisClient not initialized": CreateRhesisClientinstance before using@collaborate"@collaborate requires project_id": Provideproject_idor setRHESIS_PROJECT_IDenv var"Functions not appearing as Active": Restart app to trigger re-registration
Next Steps - Learn about Models to use LLMs in your functions - Explore Metrics to evaluate responses - See Platform Endpoints for manual configuration