A REDCap External Module that exposes RExI escalation ticket operations as callable agent tools for the SecureChatAI orchestration system.
Three tools for creating, listing, and fetching escalation tickets — no UI, no orchestration logic, just a data layer.
User → Cappy (or other UX) → SecureChatAI (Agent Orchestrator) → THIS MODULE → REDCap
- User describes an issue in natural language ("I need help with my intake survey")
- The calling EM (Cappy, MSPA, or any EM) calls
$secureChatAI->callAI()withagent_mode => true - SecureChatAI's LLM decides to create/list/fetch an escalation ticket
- SecureChatAI invokes this module's
handleToolCall()via EM-to-EM direct PHP (no API token needed) - This module executes the operation against the configured escalation project and returns structured JSON
- The LLM uses the result to compose a human-readable response
- Place this module in your REDCap
modules/directory (ormodules-local/for development) - Enable the module system-wide in REDCap's External Module Manager (project-level enablement is not required)
- Set the Escalation Project ID system setting to point to the REDCap project that stores escalation tickets
- In SecureChatAI settings, add this module's prefix to Agent Tool EM Prefixes:
- System-wide:
agent_tool_em_prefixessetting - Or per-project:
project_agent_tool_em_prefixessetting
- System-wide:
That's it. SecureChatAI auto-discovers the tools from this module's tools.json manifest and invokes them via direct PHP calls (EM-to-EM). No API token, no HTTP requests — just one EM calling another's handleToolCall() method in the same process.
SecureChatAI discovers tool EMs by matching their prefix against the Agent Tool EM Prefixes list. The redcap_agent_ prefix is a convention, not a hard requirement — any prefix works as long as it's in SecureChatAI's list.
| Setting | Description |
|---|---|
Escalation Project ID (escalation-project-id) |
The REDCap project that stores escalation tickets. Required. |
These are the current defaults in REDCapAgentRexiTools.php. Update them to match your escalation project data dictionary:
escalation_subjectescalation_summaryescalation_usernameescalation_priorityescalation_statusescalation_created_atescalation_updated_atescalation_resolutionescalation_assigned_toescalation_conversation_summary
Every tool is called through handleToolCall($action, $payload). In production, SecureChatAI handles this via EM-to-EM PHP calls. Tool definitions live in tools.json.
All tools return JSON. On success, you get the result object. On failure:
{"error": true, "message": "What went wrong"}Action: escalation_create
Create a ticket in the escalation project. Auto-generates a numeric record ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
subject |
string | ✅ | Brief subject line for the escalation |
summary |
string | ✅ | Detailed description of the issue |
priority |
string | "low", "normal" (default), or "high" |
|
status |
string | "open" (default), "in_progress", "resolved", "closed" |
|
username |
string | Auto-resolved from session if omitted |
// Request
{"subject": "Need help with intake", "summary": "Survey error on submit", "priority": "high"}
// Response
{
"pid": 99,
"record_id": "42",
"subject": "Need help with intake",
"summary": "Survey error on submit",
"priority": "1",
"status": "1",
"username": "irvins",
"success": true
}Note: Confirmation UX (agent summarizes, user approves) is handled by the agent prompt, not this EM.
Action: escalation_list
List tickets for the current user with optional status filter.
| Parameter | Type | Required | Description |
|---|---|---|---|
status |
string | Filter: "open", "in_progress", "resolved", "all" (default: "open") |
|
username |
string | Auto-resolved from session if omitted |
// Request
{"status": "open"}
// Response
{
"pid": 99,
"username": "irvins",
"status": "1",
"record_count": 2,
"records": { ... }
}Action: escalation_get
Fetch details for a specific ticket by record ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
record_id |
string | ✅ | The escalation ticket record ID |
// Request
{"record_id": "42"}
// Response
{
"pid": 99,
"record_id": "42",
"record": { ... }
}curl -X POST https://your-redcap/api/ \
-d "token=YOUR_SECURECHAT_PROJECT_TOKEN" \
-d "content=externalModule" \
-d "prefix=secure_chat_ai" \
-d "action=callAI" \
-d 'payload={"message":"Create an escalation ticket about a broken survey","agent_mode":true}'Since handleToolCall() is a plain PHP method, you can call it directly from any test harness — no API token needed:
$toolEM = \ExternalModules\ExternalModules::getModuleInstance('redcap_agent_rexi_tools');
$result = $toolEM->handleToolCall('escalation_create', [
'subject' => 'Test ticket',
'summary' => 'Testing escalation creation'
]);- Choice normalization: Priority and status strings are mapped to coded values (
low→3,normal→2,high→1;open→1,in progress→2, etc.) - Record ID auto-numbering: Checks
redcap_record_listfirst (newer REDCap), falls back to querying the data table - Username resolution: Tries
$useridglobal →USERIDconstant →$_SESSION['username']→ explicit payload parameter
secure_chat_ai— Agent orchestration and LLM routingredcap_agent_record_tools— Project and record operationsredcap_agent_tool_template— Starter template for building new tool EMs