Skip to content

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.

  • 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
  1. Open the bot builder
  2. From the Blocks panel, select “Add AI Request”
  3. The Block will be added to the workspace
  1. Double-click on the “AI Request” Block in the builder
  2. Set a descriptive title for the Block
  3. Configure AI task/prompt (required)
  4. Choose whether to use conversation history
  5. If using history, set the context count
  6. Optionally test the AI request
  7. Click “Save” to apply settings

A descriptive name for this AI Request Block to help identify it in your flow.

Examples:

  • “Analyze User Question”
  • “Generate Product Recommendation”
  • “Sentiment Analysis”

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

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

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

Task:

Answer the user's question about our product features.
Be concise and friendly. If you don't know the answer,
suggest contacting support.

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.

Task:

Analyze the sentiment of the user's message.
Respond with: "positive", "negative", or "neutral".
Include a brief explanation in one sentence.

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.

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.

Task:

Translate the user's message to English.
Only provide the translation, no explanations.

Task:

Summarize the user's message in one concise sentence,
capturing the main point or request.

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".

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.

Scenario: Answer user questions about products

Configuration:

  • Use History: Enabled (Context: 5)
  • Task:
You are a helpful product expert. Answer the user's question
about our products. Be friendly and concise. If you don't know
the answer, suggest visiting our website or contacting support.

Flow:

  1. Message: “How can I help you today?”
  2. AI Request: Process question
    • SUCCESS: Message: Show AI response
    • ELSE: Message: “I’m having trouble understanding. Could you rephrase?”

Scenario: Route users based on message sentiment

Configuration:

  • Use History: Disabled
  • Task: “Analyze sentiment: positive, negative, or neutral. Output only the sentiment.”

Flow:

  1. Message: “How was your experience?”
  2. 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!”

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 decisions
Respond with: "qualified", "needs_nurturing", or "not_qualified"

Flow:

  1. [Conversation about needs, budget, timeline]
  2. 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”

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: INTEREST
Their experience level: LEVEL
Previous 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:

  1. AI Request: Generate recommendation
    • SUCCESS: Message: Show AI generated recommendation
    • ELSE: Message: “Check out our latest products!”

Scenario: Validate complex user input

Configuration:

  • Use History: Disabled
  • Task:
Check if the user's message contains:
1. A valid business idea
2. Enough detail to understand the concept
Respond with "valid" or "needs_more_detail"

Flow:

  1. Message: “Describe your business idea”
  2. AI Request: Validate input
    • SUCCESS:
      • Response Check: Is “valid”?
        • SUCCESS: Continue to next step
        • ELSE: Message “Please provide more details”

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_TYPE
Account status: ACCOUNT_STATUS
Be empathetic, clear, and solution-oriented.

Note: Use variables like {subscription_type} and {account_status} in your actual prompts.

Flow:

  1. User describes issue
  2. AI Request: Generate support response
    • SUCCESS: Message: Show AI response
    • Follow-up based on issue resolution

Scenario: Detect language and respond appropriately

Configuration:

  • Use History: Disabled
  • Task:
1. Detect the language of the user's message
2. Respond in the same language with a greeting and
ask how you can help them
Keep the response brief and friendly.

Flow:

  1. User sends message in any language
  2. AI Request: Detect and respond
    • SUCCESS: Message: Show AI response in user’s language
    • Continue conversation in detected language

AI responses can be stored for later use:

Flow Example:

  1. 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

For complex processing, chain multiple AI Requests:

Flow Example:

  1. AI Request 1: Extract user intent
    • SUCCESS: Variable Change: Store intent
  2. Condition Check: What is the intent?
    • If “purchase”: AI Request 2: Generate purchase recommendation
    • If “support”: AI Request 3: Generate support response
  • 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
  • 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
  • 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

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 fallback
  • Use the built-in test feature before deploying
  • Test with various user inputs
  • Verify AI responses match expectations
  • Check edge cases and unexpected inputs
  • 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
  • AI services may be unavailable occasionally
  • Always implement error handling with ELSE paths
  • Consider fallback responses for critical flows
  • AI responses may vary even with identical inputs
  • For consistent results, use specific, constrained prompts
  • Test with diverse inputs to understand response patterns
  • AI requests take time to process (usually 1-5 seconds)
  • Consider user experience during waiting
  • Use typing indicators or loading messages if possible
  • Maximum 20 messages in history
  • Very long messages may be truncated
  • Balance context depth with performance needs
  • AI requests typically cost more than simple operations
  • Using history increases token usage and cost
  • Monitor usage in production environments

The AI response is typically available in subsequent blocks. The exact method depends on your implementation - check if automatic variable assignment is supported.

This depends on your bot configuration. The AI Request Block uses the configured AI assistant for your bot.

The Block takes the ELSE path, allowing you to handle the timeout gracefully (show error message, retry, or use fallback).

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.

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"

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.