Building a Hyper-Personalized Food Ordering Agent for E-commerce at Scale

ifood · E-commerce · 2026 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.4 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: E-commerce food-ordering agents

iFood needed an agent that could reduce food-ordering decision paralysis for millions of users by interpreting vague intent, personalizing options, and safely taking commerce actions across the app and WhatsApp.

Constraints:

Architecture

ISO uses a single-agent architecture with state-dependent behavior. A user message enters the agent, the system prompt changes according to the current flow and tool state, and context is loaded from conversation state plus offline user-profile representations. Food-specific tools handle search, cart, coupons, ordering, payment experiments, UI carousels, and follow-up suggestions. Personalization tools expand user intent into semantic and exact queries, rerank results with user context, and return both agent-visible responses and UI elements. Latency is managed with fast paths, async preprocessing, context compaction, prompt compression, English prompts, smaller models where possible, and scenario-based evaluations.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  app-and-whatsapp-channels[App and WhatsApp channels] --> iso-agent[ISO agent]
  app-and-whatsapp-channels --> authentication-flow[Authentication flow]
  authentication-flow --> iso-agent
  iso-agent --> state-dependent-system-prompt[State-dependent system prompt]
  iso-agent --> user-context-builder[User context builder]
  offline-preference-processing[Offline preference processing] --> user-context-builder
  user-context-builder --> personalized-search-and-reranking[Personalized search and reranking]
  state-dependent-system-prompt --> food-tool-workflows[Food tool workflows]
  iso-agent --> food-tool-workflows
  personalized-search-and-reranking --> food-tool-workflows
  food-tool-workflows --> ui-response-layer[UI response layer]
  personalized-search-and-reranking --> ui-response-layer
  ui-response-layer --> app-and-whatsapp-channels
  evaluation-agent[Evaluation agent] --> iso-agent
  evaluation-agent --> state-dependent-system-prompt
  evaluation-agent --> ui-response-layer
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
App and WhatsApp channels User-facing entry points with different interaction styles and authentication requirements. ISO agent, Authentication flow, UI response layer
ISO agent Single agent whose behavior changes by state and flow while coordinating food tools and user context. App and WhatsApp channels, State-dependent system prompt, User context builder, Food tool workflows, UI response layer
State-dependent system prompt Flow-specific prompt instructions that alter behavior depending on tool use and conversation state. ISO agent, Food tool workflows, Evaluation agent
User context builder Combines conversation context, order history, food categories, time of day, location, and offline user-behavior representations. ISO agent, Offline preference processing, Personalized search and reranking
Offline preference processing Asynchronous processing that prepares user preference representations and moves expensive context work off the synchronous path. User context builder, Personalized search and reranking
Personalized search and reranking Expands requests into semantic and exact queries, retrieves food options, and reranks options using user context. User context builder, Food tool workflows, UI response layer
Food tool workflows Food-specific tools and AI workflows for cart management, ordering, coupons, payment experiments, and recommendation flows. ISO agent, Personalized search and reranking, UI response layer
UI response layer Renders tool outputs as app screens, carousels, buttons, follow-up suggestions, and short response paths. App and WhatsApp channels, Food tool workflows, Personalized search and reranking
Evaluation agent Runs natural-language scenarios against the ISO endpoint and checks responses, UI, and guardrail behavior. State-dependent system prompt, ISO agent, UI response layer
Authentication flow Validates WhatsApp users through app/browser authorization when identity is uncertain. App and WhatsApp channels, ISO agent

Data flow

The agent receives a user message from the app or WhatsApp, loads user and conversation context, selects behavior through a state-dependent system prompt, and calls food-related tools. For recommendations, offline user behavior is converted into preference representations, combined with current context, expanded into search queries, searched semantically and exactly, reranked, then returned as both UI cards and agent context. Evaluations replay natural-language scenarios against the endpoint and UI to test regressions, guardrails, and prompt changes.

4 supporting quotes
“we have a single agent with a twist. We added some um complexity here to be able to um process uh froze in a more independent way.”transcript, stated
“what we do is getting um a representation of the user preferences that we collect based on their behavior in the app so there is some offline processing”transcript, stated
“what we get is converting the user input into search queries. Um for something simple as pizza, we going to do some semantic and exact type of search.”transcript, stated
“these results uh end up as a tool response but also as um a UI element. So we display them directly in the in the app interface”transcript, stated

Why this architecture

iFood used a single-agent design to keep orchestration simpler while still allowing state-specific behavior. The architecture pushes personalization into self-contained tools, returns UI elements alongside tool outputs to reduce typing, and reserves complex flows for complex intent while using shortcuts and async work to meet hungry-user latency expectations.

4 supporting quotes
“we have a single agent with a twist. We added some um complexity here to be able to um process uh froze in a more independent way.”transcript, stated
“Some of these tools are um AI workflows. So they're they're intelligent and uh based on the main agent task, they can operate independently”transcript, stated
“one of the things we learned is that in this kind of setup users don't really want to type much uh we need to limit their work as much as possible”transcript, stated
“we tried to make sure that um we could have a flow to handle complex requests but when things were simple we didn't need to do all of that.”transcript, stated

Models used: LLMs for ISO · smaller models for lower-latency flows where possible · LLM judge/evaluation agents

Scale

Alternatives considered (roads not taken)

Run every request through the full complex agentic flow

Rejected because: Simple food searches and promotion queries did not need the full slow path, so iFood split out shortcuts to reduce P95 latency.

“we could have a flow to handle complex requests but when things were simple we didn't need to do all of that. So we created some shortcuts”transcript, stated

Keep all context processing synchronous

Rejected because: Compacting history and selecting user-behavior information could happen asynchronously, removing tokens from the slowest user-visible flow.

“part of it could be um move to asynchronous processes for instance compacting the context of the previous messages or uh picking the best uh information from the user behavior.”transcript, stated

Write system prompts in the local user language

Rejected because: Portuguese and other non-English prompts cost more tokens and latency in the models they used, so the team kept prompts in English.

“Unfortunately, languages that are not English are penalized and this leads to higher latency and also uh quicker context route because you have more tokens. So, we made sure that all our prompts were in English.”transcript, stated

Patch production edge cases by adding more prompt rules

Rejected because: Prompt edge-case accumulation became a code smell; iFood instead added eval cases, improved tool names, and removed prompt bloat.

“whenever there is a bug in production or user complaint or we find some error in evaluations, it's very easy to add an edge case to the system prompt to cover that. But this gives bloated prompts”transcript, stated
“we try to simplify improve tool naming and at the end remove these edge cases and uh all the time running evaluations”transcript, stated

Treat WhatsApp as fully standalone from the app immediately

Rejected because: The team keeps app validation in the loop for identity and security while experimenting with more standalone WhatsApp behavior.

“if you open if you interact with ISO on WhatsApp there's a point where you need to validate on the food app that you are who you are saying”transcript, stated

Expose all MCP-style tools to the agent

Rejected because: Large tool catalogs bloat context and decision space, so ISO focuses on efficient custom tool grouping.

“one of the problems of MCP is GitHub MCP has 93 tools. So if you connect GitHub, you get 93 tools for free which completely bloats your context.”transcript, stated
“put tools that work together. So if a tool is always called after another, there's no point having to separate tools, right? >> Um you can make it available only if the first one is called or maybe have a single workflow for both of them.”transcript, stated

Patterns

tool-use-orchestration (agent_architecture)

ISO coordinates food-specific tools for search, cart, ordering, coupons, UI generation, and payment experiments, with some tools implemented as independent AI workflows.

“we have a collection of tools uh that are related to food like managing the cart, ordering, searching for food.”transcript, stated
“Some of these tools are um AI workflows. So they're they're intelligent and uh based on the main agent task, they can operate independently”transcript, stated

agent-memory (agent_architecture)

The agent uses order history, food categories, time of day, city context, and remembered behavior to make recommendations feel personalized.

“it knows about the weather it knows whether you're in a new city and if you go to a new city it can see say that you know you're in a new city”transcript, stated
“it remembers you so that's when it starts becoming kind of a true buddy.”transcript, stated

hybrid-search (knowledge_retrieval)

Food search combines semantic and exact search before reranking results with user context.

“for something simple as pizza, we going to do some semantic and exact type of search.”transcript, stated
“Then we get results and we use uh this uh user context to rerank and pick the best options for the user.”transcript, stated

query-rewriting (knowledge_retrieval)

Generic requests like 'I'm hungry' are expanded into multiple search queries that represent the user's likely preferences.

“we can have much more complex scenario like um generic um food uh requests like I'm hungry or something like that where we really need to expand uh into different queries”transcript, stated

context-compaction (context_management)

The team compacts previous-message context and moves context preparation off the synchronous request path to reduce latency.

“compacting the context of the previous messages or uh picking the best uh information from the user behavior. All these processes didn't need to be um done synchronously.”transcript, stated

latency-optimization (operations)

ISO reduced P95 latency by splitting simple flows, moving work asynchronously, compressing prompts, using English prompts, and using smaller models where possible.

“We had around 30 seconds P95 and we decreased that uh up to 10 seconds uh by uh looking at what flows uh we could uh simplify.”transcript, stated
“compressing the prompt and al also using smaller models uh when possible.”transcript, stated

eval-driven-development (quality_assurance)

Every prompt edge case is backed by an evaluation scenario, and an evaluation agent exercises the endpoint, UI, and guardrails.

“if there was um a case in production that led to the error that led to that edge case being added to the prompt, we added an an evaluation uh case for that.”transcript, stated
“this by the way is an agent that runs through these scenarios and uh behaves like a user. So it pings our endpoint for the agent and it evaluates the responses and also the UI.”transcript, stated

safety-policy-enforcement (safety)

WhatsApp flows require authentication/authorization through the app when the phone number or user identity is uncertain, and guardrail evasion is tested in evaluations.

“if we have a new user or we don't know the phone number of the user, then they're going to go through a flow where they need to authenticate and validate this phone number.”transcript, stated
“For instance, uh testing guard rails. Uh you can try for different turns to evade guardrails.”transcript, stated

Tradeoffs

Single-agent architecture with state-dependent behavior

Chose One agent with state-specific prompts and specialized tool workflows over A fully separate multi-agent system.

Rationale: The design gives flow-specific behavior and independent tool workflows without multiplying top-level agents.

“we have a single agent with a twist. We added some um complexity here to be able to um process uh froze in a more independent way.”transcript, stated
“depending on what tool gets used, what flow you're in, we get a slightly different behavior. So this is a kind of a multi- aent setup in a single agent.”transcript, stated

Fast paths for simple requests

Chose Shortcut flows for simple food searches, preferences, and promotions over Always running the complete complex agent flow.

Rationale: Hungry users need low latency, and simple requests do not justify the full workflow.

“users are hungry. They don't want to wait.”transcript, stated
“So we created some shortcuts uh that were faster and this could be searching for food like getting preferences uh searching for um promotions available.”transcript, stated

Use English prompts in a Portuguese-market product

Chose English internal prompts over Portuguese prompts matching the user language.

Rationale: English prompts reduced token counts, latency, and context pressure in the models they used.

“we made sure that all our prompts were in English. Um and this saved us a token compared to the Portuguese version.”transcript, stated
“if you want to write the same information in a language that is not English, uh you're going to have to use more tokens”transcript, stated

Connect tools to UI elements

Chose Carousels, buttons, and follow-up suggestions generated from tool outputs over Pure chat-only responses.

Rationale: Users in food ordering do not want long typing loops; UI shortcuts make the route to ordering shorter.

“those tools are also connected to UI carousels they generate buttons uh depending on um on the user request so the the user has a much shorter route to responding to the agent”transcript, stated

Keep WhatsApp connected to app authorization

Chose WhatsApp plus app/browser validation for identity-sensitive moments over A fully independent WhatsApp ordering agent.

Rationale: WhatsApp is essential in Brazil but needs identity checks before higher-risk commerce actions.

“currently if you open if you interact with ISO on WhatsApp there's a point where you need to validate on the food app that you are who you are saying”transcript, stated
“we are also experimenting with WhatsApp being a more standalone”transcript, stated

Gotchas (what bit them)

Prompt edge cases accumulate into bloated prompts.

Root cause: Production bugs, complaints, and eval failures tempt teams to add another system-prompt rule instead of fixing tool semantics or testing the behavior.

Resolution: Create eval cases for each edge case, improve tool and variable names, and remove explicit prompt rules while running regression evaluations.

“whenever there is a bug in production or user complaint or we find some error in evaluations, it's very easy to add an edge case to the system prompt to cover that. But this gives bloated prompts”transcript, stated
“most important is to improve the name of the tools and name of all variables that we use.”transcript, stated

Non-English prompts pay a token and latency tax.

Root cause: The models used by the team tokenize English more efficiently than Portuguese and most other languages.

Resolution: Keep internal prompts in English while still serving Portuguese-speaking users.

“languages that are not English are penalized and this leads to higher latency and also uh quicker context route because you have more tokens. So, we made sure that all our prompts were in English.”transcript, stated
“it can be up to 50% or more tokens.”transcript, stated

Large context windows still degrade quality and cost.

Root cause: Putting more context into the prompt can create needle-in-a-haystack behavior even when the model window technically fits.

Resolution: Select relevant context, summarize history, reduce tool outputs, and avoid indiscriminate tool exposure.

“the more context doesn't mean uh put everything in the context.”transcript, stated
“it's a needle in a haststack problem because if you put so though you can put more in the context and to be honest you know even if you make mistakes it still fits in the context window”transcript, stated

Tool outputs and tool catalogs can blow the context window.

Root cause: Long tool outputs, long conversations, and many tool descriptions consume context and force more model decisions.

Resolution: Summarize conversations, choose only relevant context, group tools that always run together, and avoid exposing huge tool catalogs.

“Tool outputs can easily blow the context. Uh especially when you up data and you let the LLM choose u the data.”transcript, stated
“if there are a lot of tools the LLM needs to have a lot of tool descriptions uh needs to make a lot of decisions as well.”transcript, stated

WhatsApp creates commerce security and identity challenges.

Root cause: WhatsApp is widely used for commerce in Brazil, but messaging channels are exposed to scams and standalone identity uncertainty.

Resolution: Tie WhatsApp to app-based validation and require authentication when the user or phone number is unknown.

“if we have a new user or we don't know the phone number of the user, then they're going to go through a flow where they need to authenticate and validate this phone number.”transcript, stated
“it does have security issues has other problems in terms of you know UI limitations as well”transcript, stated

Evaluation

iFood combines production-trace evals, regular tests, natural-language scenario definitions, and an evaluation agent that simulates users against the endpoint and UI. Scenario evals also test guardrail evasion and support prompt deflation by turning edge cases into regression tests before removing rules.

Metrics: P95 latency reduced from about 30 seconds to about 10 seconds · scenario pass/fail behavior against endpoint responses · UI behavior checks · guardrail evasion attempts over multiple turns · production trace evaluations

3 supporting quotes
“So we had evos uh on production traces of course and like regular tests that we run”transcript, stated
“what we did was defining scenarios with natural language and these scenarios include instructions on what needs to happen, some steps to set up the scenario and also the expected behavior of the agent.”transcript, stated
“this by the way is an agent that runs through these scenarios and uh behaves like a user. So it pings our endpoint for the agent and it evaluates the responses and also the UI.”transcript, stated

Outcomes

iFood operates at national e-commerce scale: 160 million monthly orders, 55 million monthly users, 400,000 delivery drivers, 1,500 cities, 150 proprietary AI models, 14 billion real-time predictions per month, and a 16-petabyte data lake.

4 supporting quotes
“So ISO is live uh to millions of users in Brazil uh uh both on app and WhatsApp.”transcript, stated
“it can apply coupons it can figure out if a customer has uh a loyalty program with i food uh what discounts to apply”transcript, stated
“So our latency was pretty high. We had around 30 seconds P95 and we decreased that uh up to 10 seconds”transcript, stated
“it doesn't wait for the user to reach out it reaches out uh to the user at the right moments”transcript, stated