Aireply24 logo

Aireply24

Aireply24 Prompt Engineering Guide

Welcome to the Aireply24 system! As a prompt engineer, your goal is to craft system instructions that make the AI behave exactly as the business requires. To do this efficiently, you must understand how Aireply24 constructs prompts under the hood, what data is automatically injected, and how the AI interacts with the system's tools and output structures.


1. Under the Hood: How the AI Works

Aireply24 uses PydanticAI to manage interactions with LLM providers (e.g., Gemini, OpenRouter, Vertex AI, etc). The AI does not just generate raw text; it generates Structured Outputs (JSON) and calls Tools based on the business's configuration.

A. The System Prompt Assembly

The final System Prompt sent to the LLM is constructed dynamically. It merges your custom instructions with the business's live data using XML tags.

The final prompt looks like this:

<instructions priority="highest">
[Your Custom System Instruction]
</instructions>

<products>
[TOON formatted active products with id, title, description, and image_ids]
</products>

<files>
[TOON formatted knowledge files with id, file_type, and transcription]
</files>

<order_fields>
[JSON array of all order fields e.g., name, phone, address, etc.]
</order_fields>

Note: If the business has disabled "Manage Orders", the <order_fields> tag is omitted.

B. Context Injection

Additionally, individual user messages are augmented with hidden JSON context so the AI is aware of specific platform nuances:

User: "How much is this?"
<context>{"customer_name": "Mohin Uddin", "last_activity": "5 minutes ago", "replied_to": "..."}</context>

C. How the AI "Sees" Attachments

When a user sends an attachment (image, audio, etc.), the system processes it before sending it to the AI:

  1. Transcribed Mode: A secondary lightweight AI transcribes the image/audio, and the AI sees: [User sent a image attachment, id: 123]:\n<Transcription text>
  2. Direct Mode: The actual image is passed to the vision-capable LLM.
  3. RAG (Image Search): If the user sends an image, the system runs a vector search against the business's FileKnowledge. If it finds a match, it whispers to the AI: [User sent image may related to image id: 45 of this product: '99'].

2. The AI's Output Capabilities (What the AI can do)

Because Aireply24 uses structured outputs, the AI can perform actions simply by populating specific fields in its JSON response. The system natively supports:

  1. text: The actual text sent to the user.
  2. quick replies: Clickable suggestion buttons.

    Note: WhatsApp limits this to 3, Messenger to 13.

  3. attachments: An array of File/Image IDs (e.g., [45, 46]). The system automatically fetches these from FileKnowledge and sends them as media.

    Note: on messenger the system filter the image ids and group them into a single message, maximum 10 images per message, if total image ids are more than 10, it will send multiple messages

  4. products: An array of Product IDs (e.g., [101, 102]). The system automatically converts these into rich interactive UI Carousels (Messenger only).

    Note: on messenger the product sending also apply the same logic as image, maximum 10 products per message, and dividing into multiple messages if needed.

  5. email: The AI can trigger an email to the business admin with a subject and body.
  6. follow_up: by this boolean field ai decide that this conversation is not resolved, and if customer goes silent he need to be followed up based on the schedule set in business profiles settings.

Available Tools (Function Calling)

If order placement is enabled, the AI has access to two powerful tools:


3. Built-In Prompts (What you DON'T need to write)

The system already handles several tasks in the background. Do not waste tokens writing instructions for these:


4. Guide to Writing the SystemInstruction

As the prompt engineer, you only write the top-level behavior. Your prompt should define the Persona, Rules of Engagement, and Workflow.

Example of a Efficient Prompt:

"You are an AI sales agent for 'FashionBd'. Be polite, concise, and speak in friendly Bengali.

Core Directives:

  1. Recommending: When users ask for send relevant products as product card.
  2. Images: If a use is interested about a product and want to know details, send them some images of the product and ask them if they want to place an order.
  3. Order Taking: To place an order, you MUST collect the exact fields defined in <order_fields>. Do not call the edit_or_create_order tool until all fields are collected.

What you MUST instruct the AI to do:

  1. Reference IDs accurately: Tell the AI to strictly use the id values provided in the XML blocks. (e.g., "Only output attachment IDs that exist in the <files> or <products> context.")
  2. Define Language & Tone: Expressly state if the AI should speak English, Bengali, or Banglish.
  3. Specify Tool behavior: Tell the AI how to transition to an order (e.g., "Ask for their phone number and address one by one before calling the order tool").

5. Tips for Token Efficiency & Reducing Redundancy

Don't use low level instructions

Rely on quick replies for conversation steering

Instruct the AI to utilize its quick replies output. Prompt Tip: "Sometimes provide some logical quick replies to keep the user engaged, such as 'Order Now' or 'See More Colors'. You should not send when quick replies does not make sense e.g you asked user to share order details"

Keep the Persona Brief

LLMs do not need 5 paragraphs of backstory to act like a customer service agent. Token-saving tip: Use bullet points in key: value formate instead of paragraphs.

Example: