AI Request Block
“AI Request” Block
Section titled ““AI Request” Block”What is an “AI Request” Block
Section titled “What is an “AI Request” Block”The “AI Request” Block is an intelligent processing element in Grailgun that leverages artificial intelligence to analyze user messages, generate responses, and make decisions based on context. This Block enables your bot to understand natural language, provide intelligent answers, and create dynamic conversational experiences powered by AI assistants.
Main Functions
Section titled “Main Functions”- Processing user input with AI understanding
- Generating intelligent, context-aware responses
- Analyzing user intent and sentiment
- Creating dynamic dialogue based on conversation history
- Providing natural language understanding capabilities
- Making intelligent decisions based on user context
- Enabling conversational AI experiences
Creation and Configuration
Section titled “Creation and Configuration”How to Add an “AI Request” Block
Section titled “How to Add an “AI Request” Block”- Open the bot builder
- From the Blocks panel, select “Add AI Request”
- The Block will be added to the workspace
Configuring AI Request Parameters
Section titled “Configuring AI Request Parameters”- Double-click on the “AI Request” Block in the builder
- Set a descriptive title for the Block
- Configure AI task/prompt (required)
- Choose whether to use conversation history
- If using history, set the context count
- Optionally test the AI request
- Click “Save” to apply settings
Configuration Fields
Section titled “Configuration Fields”A descriptive name for this AI Request Block to help identify it in your flow.
Examples:
- “Analyze User Question”
- “Generate Product Recommendation”
- “Sentiment Analysis”
Use History
Section titled “Use History”Enable this option to include previous conversation messages in the AI request.
When enabled:
- The AI receives context from past messages
- More accurate and contextually relevant responses
- Better understanding of conversation flow
- Increased AI processing cost (more tokens used)
When disabled:
- Only the current user message is analyzed
- Faster processing
- Lower cost
- Suitable for independent, stateless tasks
Default: Disabled
Context Count (Message History Limit)
Section titled “Context Count (Message History Limit)”When “Use History” is enabled, this setting controls how many previous messages to include.
Range: 0-20 messages Default: 1 message Recommended: 3-10 messages for most conversational contexts
Considerations:
- More context: Better understanding, higher accuracy, more cost
- Less context: Faster, cheaper, but may miss important conversation details
- Include enough messages to capture relevant context without excessive data
Example:
- Context Count = 5 means the AI sees the last 5 user-bot message exchanges
Task (AI Context/Prompt)
Section titled “Task (AI Context/Prompt)”Required field. This is the instruction or prompt that tells the AI what to do with the user’s message.
Prompt Guidelines:
- Be clear and specific about what you want the AI to do
- Include expected output format
- Mention any constraints or requirements
- Use variables with
{variable_name}syntax for dynamic context
Error Handling:
- Empty task field shows validation error
- Red border indicates missing required field
- Must be filled before saving
Prompt Examples
Section titled “Prompt Examples”Simple Question Answering
Section titled “Simple Question Answering”Task:
Answer the user's question about our product features.Be concise and friendly. If you don't know the answer,suggest contacting support.Intent Detection
Section titled “Intent Detection”Task:
Analyze the user's message and determine their intent.Respond with one of: "purchase", "support", "information", "other".Only output the intent category, nothing else.Sentiment Analysis
Section titled “Sentiment Analysis”Task:
Analyze the sentiment of the user's message.Respond with: "positive", "negative", or "neutral".Include a brief explanation in one sentence.Content Generation
Section titled “Content Generation”Task:
Generate a personalized product recommendation based on the user's message.Consider they are interested in INTEREST and their budget is BUDGET.Provide 2-3 specific recommendations with brief descriptions.Note: Use variable syntax like {user_interest} and {user_budget} in your actual prompts.
Data Extraction
Section titled “Data Extraction”Task:
Extract the following information from the user's message:- Full name- Email address- Phone number
Return the data in JSON format. If any field is missing, use null.Language Translation
Section titled “Language Translation”Task:
Translate the user's message to English.Only provide the translation, no explanations.Text Summarization
Section titled “Text Summarization”Task:
Summarize the user's message in one concise sentence,capturing the main point or request.Validation and Classification
Section titled “Validation and Classification”Task:
Check if the user's message contains a valid complaint or issue.If yes, categorize it as: "technical", "billing", "service", "other".If no, respond with "not_a_complaint".Connection Points
Section titled “Connection Points”The AI Request Block has branching outputs:
- IN - Accepts connection from previous Blocks
- SUCCESS - Connected Block executes when AI request succeeds and processes the message
- ELSE - Connected Block executes when AI request fails (error, timeout, or AI unavailable)
This allows you to handle success and failure scenarios differently.
Usage Examples
Section titled “Usage Examples”Intelligent FAQ Bot
Section titled “Intelligent FAQ Bot”Scenario: Answer user questions about products
Configuration:
- Use History: Enabled (Context: 5)
- Task:
You are a helpful product expert. Answer the user's questionabout our products. Be friendly and concise. If you don't knowthe answer, suggest visiting our website or contacting support.Flow:
- Message: “How can I help you today?”
- AI Request: Process question
- SUCCESS: Message: Show AI response
- ELSE: Message: “I’m having trouble understanding. Could you rephrase?”
Sentiment-Based Routing
Section titled “Sentiment-Based Routing”Scenario: Route users based on message sentiment
Configuration:
- Use History: Disabled
- Task: “Analyze sentiment: positive, negative, or neutral. Output only the sentiment.”
Flow:
- Message: “How was your experience?”
- AI Request: Analyze sentiment
- SUCCESS:
- Response Check: Is response “negative”?
- SUCCESS: Message “Sorry to hear that!” → Alert admin
- ELSE: Message “Thank you for your feedback!”
- Response Check: Is response “negative”?
- SUCCESS:
Lead Qualification
Section titled “Lead Qualification”Scenario: Qualify leads based on conversation
Configuration:
- Use History: Enabled (Context: 10)
- Task:
Based on the conversation, determine if this lead is qualified:- Has budget- Has timeline- Has authority to make decisionsRespond with: "qualified", "needs_nurturing", or "not_qualified"Flow:
- [Conversation about needs, budget, timeline]
- AI Request: Qualify lead
- SUCCESS:
- Response Check: Is “qualified”?
- SUCCESS: Alert “Qualified lead!” → Connect to sales
- ELSE: Message “Thank you, we’ll follow up soon”
- Response Check: Is “qualified”?
- SUCCESS:
Dynamic Content Personalization
Section titled “Dynamic Content Personalization”Scenario: Generate personalized message based on user profile
Configuration:
- Use History: Enabled (Context: 3)
- Task:
Generate a personalized message for this user.They are interested in: INTERESTTheir experience level: LEVELPrevious purchase: PURCHASE
Create a friendly message suggesting the next product they might like.Note: Use variable syntax like {user_interest}, {user_level}, and {last_purchase} in your actual prompts.
Flow:
- AI Request: Generate recommendation
- SUCCESS: Message: Show AI generated recommendation
- ELSE: Message: “Check out our latest products!”
Input Validation with AI
Section titled “Input Validation with AI”Scenario: Validate complex user input
Configuration:
- Use History: Disabled
- Task:
Check if the user's message contains:1. A valid business idea2. Enough detail to understand the conceptRespond with "valid" or "needs_more_detail"Flow:
- Message: “Describe your business idea”
- AI Request: Validate input
- SUCCESS:
- Response Check: Is “valid”?
- SUCCESS: Continue to next step
- ELSE: Message “Please provide more details”
- Response Check: Is “valid”?
- SUCCESS:
Context-Aware Customer Support
Section titled “Context-Aware Customer Support”Scenario: Provide support with conversation context
Configuration:
- Use History: Enabled (Context: 8)
- Task:
You are a customer support agent. Help the user with their issue.Reference previous context when relevant.User subscription: SUBSCRIPTION_TYPEAccount status: ACCOUNT_STATUS
Be empathetic, clear, and solution-oriented.Note: Use variables like {subscription_type} and {account_status} in your actual prompts.
Flow:
- User describes issue
- AI Request: Generate support response
- SUCCESS: Message: Show AI response
- Follow-up based on issue resolution
Multi-Language Detection and Response
Section titled “Multi-Language Detection and Response”Scenario: Detect language and respond appropriately
Configuration:
- Use History: Disabled
- Task:
1. Detect the language of the user's message2. Respond in the same language with a greeting and ask how you can help them
Keep the response brief and friendly.Flow:
- User sends message in any language
- AI Request: Detect and respond
- SUCCESS: Message: Show AI response in user’s language
- Continue conversation in detected language
Working with AI Responses
Section titled “Working with AI Responses”Storing AI Responses in Variables
Section titled “Storing AI Responses in Variables”AI responses can be stored for later use:
Flow Example:
- AI Request: Generate content
- SUCCESS:
- Variable Change: Set “ai_answer” = USER_RESPONSE (or AI response if supported)
- Use “
{ai_answer}” in subsequent messages or conditions
- SUCCESS:
Chaining Multiple AI Requests
Section titled “Chaining Multiple AI Requests”For complex processing, chain multiple AI Requests:
Flow Example:
- AI Request 1: Extract user intent
- SUCCESS: Variable Change: Store intent
- Condition Check: What is the intent?
- If “purchase”: AI Request 2: Generate purchase recommendation
- If “support”: AI Request 3: Generate support response
Best Practices
Section titled “Best Practices”Prompt Engineering
Section titled “Prompt Engineering”- Be specific: Clear instructions yield better results
- Set expectations: Define output format explicitly
- Include constraints: Mention limitations or requirements
- Use examples: Show the AI what you expect (when possible)
- Iterate: Test and refine prompts for optimal results
Performance Optimization
Section titled “Performance Optimization”- Minimize history when possible: Reduces cost and latency
- Use appropriate context count: Balance between accuracy and performance
- Cache common requests: Consider storing frequent AI responses as static content
- Implement timeouts: Handle AI delays gracefully with ELSE paths
Cost Management
Section titled “Cost Management”- Disable history for simple tasks: Stateless requests are cheaper
- Limit context count: More messages = more cost
- Use AI selectively: Not every interaction needs AI processing
- Monitor usage: Track AI request frequency and costs
Error Handling
Section titled “Error Handling”Always implement ELSE paths:
AI Request → SUCCESS: Handle AI response → ELSE: → Message: "I'm having trouble processing that right now" → Alert: "AI request failed for user ID" → Alternative action or fallbackTesting
Section titled “Testing”- Use the built-in test feature before deploying
- Test with various user inputs
- Verify AI responses match expectations
- Check edge cases and unexpected inputs
Tips and Recommendations
Section titled “Tips and Recommendations”- Start simple: Begin with basic prompts, add complexity gradually
- Test extensively: AI responses can be unpredictable, test thoroughly
- Provide fallbacks: Always have ELSE path for AI failures
- Use variables: Include context from variables in prompts
- Monitor quality: Review AI responses regularly
- Update prompts: Refine prompts based on user interactions
- Consider alternatives: Not every task requires AI; simple rules may suffice
- Privacy first: Don’t send sensitive data to AI unless necessary
- Set clear titles: Identify AI Request Blocks clearly in complex flows
- Combine with other blocks: Use Response Check or Condition Check to validate AI outputs
Limitations and Considerations
Section titled “Limitations and Considerations”AI Availability
Section titled “AI Availability”- AI services may be unavailable occasionally
- Always implement error handling with ELSE paths
- Consider fallback responses for critical flows
Response Variability
Section titled “Response Variability”- AI responses may vary even with identical inputs
- For consistent results, use specific, constrained prompts
- Test with diverse inputs to understand response patterns
Processing Time
Section titled “Processing Time”- AI requests take time to process (usually 1-5 seconds)
- Consider user experience during waiting
- Use typing indicators or loading messages if possible
Context Limits
Section titled “Context Limits”- Maximum 20 messages in history
- Very long messages may be truncated
- Balance context depth with performance needs
Cost Implications
Section titled “Cost Implications”- AI requests typically cost more than simple operations
- Using history increases token usage and cost
- Monitor usage in production environments
Frequently Asked Questions
Section titled “Frequently Asked Questions”How do I access the AI’s response?
Section titled “How do I access the AI’s response?”The AI response is typically available in subsequent blocks. The exact method depends on your implementation - check if automatic variable assignment is supported.
Can I use multiple AI models?
Section titled “Can I use multiple AI models?”This depends on your bot configuration. The AI Request Block uses the configured AI assistant for your bot.
What happens if the AI request times out?
Section titled “What happens if the AI request times out?”The Block takes the ELSE path, allowing you to handle the timeout gracefully (show error message, retry, or use fallback).
Can I provide training data to the AI?
Section titled “Can I provide training data to the AI?”The AI Request Block uses the configured AI assistant’s base knowledge. Custom training typically requires AI assistant configuration outside the flow builder.
How do I test AI requests during development?
Section titled “How do I test AI requests during development?”Use the “Test Request” button in the AI Request Block form to see how the AI responds to sample inputs before deploying.
Can the AI access my bot’s variables?
Section titled “Can the AI access my bot’s variables?”You can include variable values in your task prompt using {variable_name} syntax. The AI doesn’t automatically know about variables unless you include them in the prompt.
How do I make the AI respond in a specific format?
Section titled “How do I make the AI respond in a specific format?”Include format instructions in your task prompt.
Example:
"Respond in JSON format with intent and confidence fields"Can I use AI Request for image analysis?
Section titled “Can I use AI Request for image analysis?”This depends on your AI assistant configuration. Standard text-based AI assistants process text only. Check if multimodal capabilities are available.
How do I prevent inappropriate AI responses?
Section titled “How do I prevent inappropriate AI responses?”- Write clear, constrained prompts
- Include guidelines in task instructions
- Test thoroughly with edge cases
- Implement Response Check validation after AI Request
- Consider content filtering in prompts
What’s the difference between AI Request and Response Check with AI?
Section titled “What’s the difference between AI Request and Response Check with AI?”- AI Request: Processes user messages with AI for any purpose (analysis, generation, decision-making)
- Response Check with AI: Validates user responses against specific criteria using AI
AI Request is more flexible and general-purpose, while Response Check is specifically for validation logic.