AI Agent

How the AI agent works

The loop behind every reply, what it means for your setup, and how to trace any answer.

Every reply from the AI agent comes from one loop. A language model reads its instructions, the conversation and the tools it may use, looks things up when it needs to, then replies. Knowing this loop explains almost everything the AI agent does, and tells you which setting to change when a reply surprises you.

What this page answers

Read this page before you configure anything complex. It is written for the people who set up the AI agent, and for the AI agents that do it for them, such as Copilot or an MCP client. It answers questions like these:

  • Does the AI agent know my whole catalog? No. It searches for products and knowledge when it needs them. See Products.
  • Can a rule tell it to follow up in two hours? No. The loop only runs when a message arrives, so follow-ups are a separate feature. See What the AI agent can't do on its own.
  • Why didn't it use my refund action? An action is only available once a workflow that includes it is in play. See Workflows and where tools come from.
  • Why did it reply this way? Every reply is fully traceable. See Debugging.

Trace any reply

When a reply surprises you, ask Copilot or your own AI agent to explain it:

Ask Copilot or your AI agent

A customer chatted with us yesterday from anna@example.com and got the wrong return window. Find that conversation, explain why the AI agent answered that way, and fix the cause.

The agent reads the exact instructions behind the reply, the searches it ran and the actions it called, then changes the setting that caused the problem. In the dashboard, open the conversation, hover over an AI reply and click the bug icon to see the same details.

The core loop

  1. A customer sends a message.
  2. Octocom calls a large language model (LLM) with three things: the system prompt (its instructions), the conversation so far and the tools it may use.
  3. The model may call one or more tools, for example to look up an order, search products or search the knowledge base. Each tool's result is fed back to the model.
  4. It can call more tools based on what it learned, looping until it has what it needs.
  5. It writes a text reply to the customer. That ends the turn.

There is no hidden machinery beyond this loop. The model reasons over its instructions and the conversation, gathers information through tools when needed, and replies.

customer message
      │
      ▼
┌─────────────────────────────────────────┐
│  LLM call                                │
│  • system prompt (instructions)          │
│  • conversation history                  │
│  • available tools                       │ ◄────┐
└─────────────────────────────────────────┘      │
      │                                           │
      ├── wants to call tool(s)? ── run them ─────┘
      │        (loops, up to a limit)
      │
      └── writes text reply ──► sent to customer (turn ends)

Three consequences follow from this shape:

  • The AI agent only runs when a message arrives. Between messages, nothing happens inside it. There is no background process watching the clock or waiting for events.
  • The loop is bounded. The AI agent can chain several tool calls in one reply, up to about ten rounds. It cannot loop forever.
  • The model decides what to do. Within your instructions, it chooses which tools to call and what to say. You shape that behavior through the system prompt. You don't script it line by line.

What's in the system prompt

The system prompt is where you control the AI agent. Octocom builds it fresh for every reply from a fixed sequence of sections. Some come from your settings, and others are filled in from the conversation. System prompt lists every section in order. These are the ones that matter most when you configure the AI agent.

Instructions and writing style

The first sections say who the AI agent is and how it writes. Each starts from a tuned Octocom default that you can override:

  • Task: who the AI agent is and its core job, for example "You are a support agent for Acme".
  • Safety: high-level guardrails, such as staying on topic and not making unauthorized commitments.
  • Instruction following: which source of truth wins, for example workflow instructions over articles.
  • Tool calling: how and when to use tools.
  • Tone, writing style and language: the voice, separate styles for chat and email, and which language to reply in.
  • Output syntax: formatting rules, such as Markdown and no raw HTML.
  • Business description: a short overview of your company. It is empty until you write one.

Tone, writing style and language are on Settings -> Automation -> Writing Style. See Writing style. The other sections are expert settings on Settings -> Automation -> System Prompt. See System prompt. Reset to default brings back Octocom's default for any section.

Bot rules

Bot rules are short, always-on guidelines written into the system prompt on every turn, such as "always mention the newsletter discount to first-time buyers" or "never promise next-day delivery". Each rule is a title plus a block of instructions, and rules can be scoped to specific channels.

Rules are pure instructions. They guide the model, but they don't run code and they don't give the AI agent new capabilities. See Bot rules for when a rule is the right tool and when a workflow is.

Workflows and where tools come from

Workflows are playbooks for specific situations, such as "customer wants to cancel an order". Workflows covers them in depth, but one point is essential to the operating model and easy to miss:

Workflow actions come from workflows. A workflow declares which actions it makes available. Built-in capabilities, such as searching the knowledge base, reading customer attachments and loading workflows, are available independently.

A workflow reaches the AI agent in one of two ways:

  • Embedded workflows are written into the system prompt in full on every turn. Their instructions are always visible and their actions are always available. They must have exactly one variant, no condition provider and no required conditions.
  • Non-embedded workflows are listed in the system prompt by name, with a one-line "when to follow this". When the model decides one applies, it calls the built-in getWorkflowInstructions tool to load it. Only then are that workflow's instructions, and its actions, added to what the AI agent can use.

A non-embedded workflow can have one variant or several. The variant is chosen by conditions evaluated at load time. When the workflow loads, the AI agent gains the actions of the selected variant.

Loading happens once per conversation, not once per turn. A loaded workflow's instructions and actions stay available for the rest of the conversation, so the AI agent doesn't reload it on later messages. The set of available tools tends to grow over a conversation as more workflows are loaded.

In practice: at the start of a conversation, the AI agent can use its built-in tools and the actions of embedded workflows. Actions from other workflows become available when those workflows load. This keeps the prompt small and focused, and it is why a new conversation doesn't have every action in front of the model. Deciding what to load is part of what makes the AI agent agentic: it pulls in what it needs instead of being handed everything up front.

Knowledge base

The knowledge base is the AI agent's reference material: articles you write, website pages Octocom scrapes and documents you upload, all in one searchable pool.

None of it is memorized or written into the prompt. The AI agent gets one tool, searchKnowledgeBase, and a note about how much content exists. When it needs a fact, it searches, reads the returned passages and answers from them, the same way a person searches a help center. The AI agent is only as good as what it can find: if the answer isn't in the knowledge base, searching won't invent it.

This section is automatic. As soon as there is at least one active knowledge base entry, the AI agent gets this section and the searchKnowledgeBase tool. There is nothing to switch on and no workflow is needed. With an empty knowledge base, neither the section nor the tool exists.

See Knowledge base for its sources, how search selects passages and how to write content that gets found.

Products

When you sync a product catalog, product handling follows one of two styles, depending on its size:

  • Small catalog, roughly a hundred in-stock products or fewer: a compact index of every product is written into the system prompt, with its id, name, price, a few flags and a short summary. The AI agent still calls getProductsByIds to get full details before it talks about a specific product.
  • Larger catalog: nothing is listed in the prompt. The AI agent gets searchProducts, which searches by meaning, by keyword or SKU, or by URL, plus getProductsByIds for full details. It searches, then fetches the details.

The AI agent does not "know" your products. This is one of the most common misconceptions. Beyond a small catalog, it has no memorized product list. It only knows the products it has found through a search in the current conversation. If a search doesn't return a product, the AI agent effectively doesn't know it exists.

Like the knowledge base, the product section and the product tools appear automatically once at least one product has synced through product sync. If no products have synced, they don't exist for the AI agent.

Conversation context

The rest of the prompt is filled in automatically for the current conversation, when the information exists: the current date and time in your business time zone, the channel, the customer's email address and phone number, the page they wrote to on Messenger or Instagram, and their browsing history and recently viewed products in Octocom web chat. In email conversations it also lists the customer's recent previous email conversations, which the AI agent can open with a built-in tool when they help. You don't configure these.

To add your own context, such as the customer's latest orders or account status from your systems, use a custom Python prompt section.

Customer attachments

The AI agent can read supported customer attachments without a custom action or workflow. It receives a file ID, filename and content type, then reads the attachment when its contents are relevant. Attachment notices do not expose private download URLs.

AttachmentBuilt-in readerWhat the AI agent receives
ImagesviewImage({fileId, question})A vision model's answer to the specific question
PDFs, including scanned pagesreadFile({fileId})Extracted text with OCR where needed
Word documents (.docx)readFile({fileId})Document text
TXT, Markdown, CSV, TSV, JSON, XML, and YAMLreadFile({fileId})Text content
Forwarded emails (.eml)readFile({fileId})Sender, recipients, date, subject and body text

Both readers check that the attachment belongs to the current conversation and passes the applicable access and safety checks. Image inspection follows the same checked path whether or not the AI agent's main model supports vision. Files and filenames are customer data, not instructions that can override the AI agent's rules.

Document reading accepts files up to 10 MB and PDFs of up to 30 pages. Larger PDFs need to be reduced to the relevant pages. It retains up to 100,000 extracted characters. Each call returns 12,000 characters by default, or up to 20,000 with limit. When a result includes nextOffset, the AI agent continues with readFile({fileId, offset: nextOffset}). Results disclose extraction limits, so the AI agent can tell a complete read from a partial one. A document's embedded images are not inspected separately by the text reader.

To find something in a long document, the AI agent searches it with readFile({fileId, query}), for example for an order or tracking number. Search is case- and accent-insensitive and returns up to 10 snippets with their offsets. The AI agent then reads around a match with readFile({fileId, offset}). If the whole phrase does not appear, it matches any of the phrase's words.

Forwarded emails are read as plain text: the sender, recipients, date, subject and body, including any quoted reply chain. HTML is reduced to its visible text. Scripts, styles and images are dropped, links keep only their visible label with long or marketing URLs shortened, and nothing in the email is loaded or run. Emails forwarded as attachments inside the email are read inline, up to three levels deep. Other attachments inside a forwarded email are listed by name but not read. The AI agent asks the customer to send any that matter as separate files. Outlook .msg files are not supported.

Extracted text is cached for 3 days, so follow-up questions about the same attachment don't repeat the download, OCR or safety check. Access to the attachment is still verified on every read.

Unsupported file types produce a clear error. For example, readFile cannot read an image, so the AI agent uses viewImage instead. If a file cannot be read, the AI agent explains the limitation and asks for a supported format, the relevant text pasted into the conversation, or a clearer image.

These readers belong to the customer-facing AI agent. To read a PDF from your own Python code, use the transcribe_pdf(url) helper.

What the AI agent can't do on its own

The AI agent is a model, a system prompt and tools in a loop, so its limits follow directly. They trip people up often, so here they are plainly.

It has no sense of elapsed time and can't act on its own schedule. A rule or workflow that says "if the customer doesn't reply, follow up in two hours" does nothing in the core loop. The AI agent only runs when a message comes in. It has no timer and no way to wake itself up later, so telling it to "wait" or "check back" has nothing to carry it out.

It can only do what its tools allow. It cannot browse your admin panel or "go look it up" anywhere it has no tool for. If there's no tool for an action, no instruction can make it happen. Its entire ability to do things, as opposed to say things, is the set of tools currently available to it.

It can't reach the open web. It has no general internet access. It knows what's in its prompt and what its tools return.

It doesn't have your catalog or knowledge base memorized. It searches, and its knowledge of your products and articles is limited to what it retrieves in the moment.

It can make mistakes. Like any LLM, it can occasionally get something wrong or state something its sources don't support. This is called a hallucination. Good instructions and knowledge reduce it, but they don't make it impossible.

Instructions are guidance, not code. Rules and workflow steps strongly shape behavior, but they are natural-language directions to a model, not deterministic program logic. Written clearly, they are followed reliably. Treated as exact if-this-then-that code, they surprise you at the edges.

When something must be guaranteed, move it out of the prompt and into code. For anything that must hold every single time, such as strict identity checks, verifying state in another system, or exact time, money or eligibility logic, don't rely on instructions. Use condition providers, code that evaluates external state and decides which workflow variant the AI agent follows. Use Python actions, code the AI agent calls to do the work. The model still runs the conversation, but the parts that must be exact run as code.

Features around the loop

The limits above describe the core loop on its own, so you have an accurate mental model of the engine. Octocom adds features around the loop that extend or safeguard it, so several of those limits don't apply to the product as a whole:

  • Acting later. The loop can't follow up on its own, but follow-ups, event handlers and recurring jobs can make the AI agent reach out or act when time passes or something happens.
  • Catching mistakes. The model can hallucinate, so Octocom checks replies around the loop. Built-in checks catch and correct a class of errors before a reply reaches the customer, such as a reply in the wrong language (see Check the reply language). Bot QA adds your own checks, for example flagging a refund confirmation that no action result supports.

The rule to remember: don't solve a loop-level limitation with a prompt instruction. A rule that says "respond later" can't work, because the loop has no concept of later. Use the feature built for that job instead.

Debugging: the loop is fully observable

Because a reply is this loop and nothing more, nothing is hidden. Octocom records the complete picture of every AI turn, so when a reply surprises you, you can see exactly what the model saw and did.

In the dashboard

Open a conversation, hover over an AI message and click the bug icon ("Debug this message"). The Response debugging information panel shows:

  • System prompt: the exact system prompt sent to the model for that turn, with its token count and build time.
  • Tool calls: every tool the AI agent called, with its arguments, the result, execution timing and any logs from the call.
  • Reasoning: the model's reasoning trace for each LLM call, when the model provides one.
  • Available actions: every tool the AI agent could use on that turn, with each tool's description and parameters.
  • Response metadata: the message content and response time.

If the AI agent "didn't know" about a product, you can check whether it searched at all. If it ignored a workflow, you can check whether that workflow's instructions and tools were present.

Through MCP

With Octocom MCP or Copilot, the same information is available for any AI message:

  • get_response_system_prompt returns the full system prompt that went into the LLM for that message.
  • get_response_tool_calls returns the available actions, the tool calls (with arguments, results and logs) and the reasoning traces.

To find the message, use get_conversation, which lists the conversation's messages with their debug information. An AI agent can then inspect a real turn end to end: read the exact prompt, see which tools were available and trace what was called, to diagnose behavior or verify a configuration change.

You can see the full input. The system prompt plus the conversation messages are the complete input the LLM received. There is no opaque step between what the customer said and what the AI agent replied.

Putting it together

To configure the AI agent well:

  1. Shape how it sounds with the writing style. The system prompt page shows every section it reads.
  2. Set the few standing guardrails with bot rules.
  3. Give it playbooks and capabilities with workflows and actions, remembering that actions arrive with workflows.
  4. Let it find facts and products through the knowledge base and product search, rather than expecting it to "just know".
  5. Use the dedicated features, not prompt instructions, for anything the core loop can't do on its own, such as acting later or guaranteeing correctness.

Almost every "why did it do that?" or "why won't it do that?" comes back to one fact on this page: it's an LLM, looping over a system prompt and a set of tools, one message at a time.

On this page