Trigger Agent
Trigger an AI agent chat with templated user queries. Supports variable substitution in the format {variableName}
Trigger Agent
Trigger an AI agent chat with templated user queries. This function allows you to programmatically interact with AI agents using template strings with variable substitution. The function processes template variables, triggers the agent conversation, and returns the agent's response.
Technical Name: TriggerAgentFunc
Properties
- Execution Mode: SYNC
- Type: NATIVE
- Category: System Functions
- Function ID:
8a2e4c9f-1b3d-4f5a-8e9c-2d6f8a1b4e7c
Input Schema
Required Parameters
| Parameter | Type | Description |
|---|---|---|
agentUUID | string (UUID) | UUID of the AI agent to trigger |
userQuery | string | Template string with variables in {variable} format. Example: 'Create order for {userId} with status {status}' |
Optional Parameters
| Parameter | Type | Description |
|---|---|---|
fileUUID | string (UUID) | UUID of the attached file to include in the chat |
variableMappings | object | Map of variable names to their replacement values. Keys should match variable names used in userQuery template |
[Image placeholder: TriggerAgent function configuration panel]
Input Example
Basic Query Without Variables
{
"agentUUID": "a7b9c4d2-3e5f-4a1b-9c8d-7e6f5a4b3c2d",
"userQuery": "Analyze the sales data for Q1 2024"
}Query With Template Variables
{
"agentUUID": "a7b9c4d2-3e5f-4a1b-9c8d-7e6f5a4b3c2d",
"userQuery": "Create order for {userId} with status {status} and amount {amount}",
"variableMappings": {
"userId": "user-123",
"status": "pending",
"amount": "99.99"
}
}Query With File Attachment
{
"agentUUID": "a7b9c4d2-3e5f-4a1b-9c8d-7e6f5a4b3c2d",
"userQuery": "Analyze this document: {documentType}",
"fileUUID": "file-uuid-here",
"variableMappings": {
"documentType": "invoice"
}
}Output Schema
| Field | Type | Description |
|---|---|---|
success | boolean | Whether the agent trigger operation completed successfully |
conversationId | string (UUID) | Generated conversation ID for the chat session |
runId | string (UUID) | Generated run ID for this specific chat execution |
agentId | string (UUID) | ID of the triggered agent |
agentName | string | Name of the triggered agent |
processedQuery | string | The final user query after template variable processing |
agentResponse | string | The agent's string response content (only supports StringAgentOutput agents) |
errorMessage | string | Error message if the operation failed (only present when success is false) |
Output Example
Success Response
{
"success": true,
"conversationId": "c9d1e6f4-5g7b-6c3d-0e1f-9g8c7d6e5f4g",
"runId": "b8c0d5e3-4f6a-5b2c-9d0e-8f7b6c5d4e3f",
"agentId": "a7b9c4d2-3e5f-4a1b-9c8d-7e6f5a4b3c2d",
"agentName": "Sales Analysis Agent",
"processedQuery": "Create order for user-123 with status pending and amount 99.99",
"agentResponse": "Order created successfully. Order ID: ORD-12345"
}Error Response
{
"success": false,
"errorMessage": "Agent not found with ID: invalid-uuid"
}[Image placeholder: TriggerAgent output visualization]
How It Works
The function performs the following steps:
- Parse Input: Validates and parses input parameters
- Process Template: Uses Spring AI PromptTemplate to replace
{variable}placeholders with values fromvariableMappings - Load Agent: Retrieves the AI agent by UUID from the repository
- Generate IDs: Creates a unique run ID for this execution
- Create Chat Request: Builds an AI chat request with the processed query
- Execute Agent: Triggers the agent chat in a separate thread to preserve execution context
- Extract Response: Extracts string content from the agent's response (only supports StringAgentOutput)
- Return Result: Returns success status, agent information, processed query, and response
Template Variable Processing
The function uses Spring AI PromptTemplate for variable substitution:
- Format: Variables are enclosed in curly braces:
{variableName} - Substitution: Values from
variableMappingsreplace the variables - Missing Variables: If a variable in the template has no mapping, it remains as-is
- No Mappings: If
variableMappingsis null or empty, the query is returned as-is
Template Examples
{
"userQuery": "Hello {name}, your order {orderId} is {status}",
"variableMappings": {
"name": "John",
"orderId": "ORD-123",
"status": "shipped"
}
}Result: "Hello John, your order ORD-123 is shipped"
Use Cases
Dynamic Agent Queries
Trigger agents with dynamic data from workflows:
{
"agentUUID": "{{workflow.agentId}}",
"userQuery": "Analyze customer {customerId} transaction history",
"variableMappings": {
"customerId": "{{workflow.customerId}}"
}
}Workflow Automation
Use AI agents in automated workflows:
Start → FetchMData → TriggerAgent → ProcessResponse → End[Image placeholder: Workflow example]
Document Analysis
Send documents to agents for analysis:
{
"agentUUID": "document-analysis-agent-uuid",
"userQuery": "Analyze this {documentType} and extract key information",
"fileUUID": "{{uploadedFileId}}",
"variableMappings": {
"documentType": "invoice"
}
}Notes
- Agent Type: Only supports agents with
StringAgentOutputresponse type - Template Processing: Uses Spring AI PromptTemplate for variable substitution
- Thread Isolation: Executes agent chat in a separate thread to preserve workflow execution context
- File Attachments: Optional file can be attached to the chat request
- Error Handling: Returns error message in
errorMessagefield if operation fails - Agent Validation: Validates that the agent exists before processing
- Variable Mappings: All values in
variableMappingsare treated as strings
Limitations
- Output Type: Only supports
StringAgentOutputagents. Other output types will throw an exception - Synchronous Execution: The function waits for the agent response before returning
- Template Variables: Variables must match exactly (case-sensitive) between template and mappings
Related Functions
- Call External API - Call external APIs and services
- Run JavaScript Code - Execute custom JavaScript logic
- Calculate Expression - Perform calculations and formulas