Anyone asking how to build an AI agent for business almost always wants something concrete: serve customers on WhatsApp, support the sales team, triage tickets or answer questions about internal documents. The technology is mature enough for that, and the failures we see come from broad scope, poor data and no evaluation. At iTask, we develop custom agents and maintain AgentHub, our own platform for AI agents on WhatsApp, behind verticals such as Klinik, Korretora, ImobiTask and AiSind. This roadmap gathers what we have learned.
Step 1: pick a narrow process
A good agent starts with a process that has a beginning, a middle and an end, and an owner. Examples: schedule an appointment, qualify a real estate lead, answer an order status question, triage a support ticket. Avoid the “agent that does everything”.
Define before writing code:
- Goal: what it means for the agent to have solved the task.
- Inputs: the channel (WhatsApp, web, email) and the data available.
- Allowed actions: what the agent may read and what it may change.
- When to hand off to a human: clear triggers, such as low confidence, a complaint or a value above a limit.
- How to measure: resolution rate, response time, satisfaction and escalations.
Step 2: the architecture
A business agent has five layers.
- Channel: WhatsApp, website chat, email or API. It handles user authentication, message formats and channel limits.
- Orchestrator: the agent loop. It receives the message, builds the context, calls the model, runs the tools the model requests and returns the answer.
- Language model (LLM): reasons and decides. Choose by quality on the task, latency, cost and privacy requirements. Being able to swap models without rewriting the rest is valuable.
- Knowledge (RAG): the document base the agent consults.
- Tools: functions that access your systems.
Around them sit conversation memory, observability, a queue for async work and a panel for the team to operate it.
Step 3: RAG, the company’s knowledge
The model does not know your procedures, prices or policies. RAG (Retrieval-Augmented Generation) solves that: before answering, the system searches your base for relevant passages and puts them in the model’s context.
The pipeline:
- Ingestion: reading PDFs, pages, spreadsheets and systems, with clean text extraction.
- Chunking with size and overlap tuned to the document type, respecting headings and tables.
- Embeddings: each chunk becomes a vector stored in a vector database (pgvector on PostgreSQL, for example, or a dedicated service).
- Search: the question becomes a vector and retrieves the nearest chunks. Hybrid search (vector plus keyword) and reranking improve precision.
- Answer with citation: the model answers from the chunks and names the source.
RAG errors almost never live in the model. They live in outdated documents, badly split ones, or documents that contradict each other. Treat the knowledge base as a product, with an owner and an update routine.
Step 4: tools, where the agent acts
Tools turn a model into an agent. Each one is a function with a name, a description and typed parameters, which the model decides to call: get_order(number), schedule(time, service), open_ticket(summary).
Principles we follow:
- Least privilege: the tool does one thing and has permission only for that.
- Server-side validation: the model suggests the parameters, your code validates them. Never trust model output as safe input.
- Read before write: start with query tools only. Release the ones that change data when evaluation is solid.
- Human confirmation for irreversible or high-value actions.
- Idempotency: the agent may repeat a call. The action must not duplicate its effect.
The MCP standard (Model Context Protocol) standardizes how tools are exposed to agents and helps reuse integrations across applications.
Step 5: instructions and behavior
The system prompt defines the role, the tone, the limits and what to do under uncertainty. Good prompts are short, specific and tested. Include examples of hard conversations and an explicit instruction to say it does not know and hand off to a person when information is missing. Version prompts like code, with review and history.
Step 6: evaluation, the step most teams skip
Without evaluation, every adjustment becomes a bet. Build a test set with dozens to hundreds of real cases: question, context, expected answer and criteria (correct, complete, on tone, no invention, called the right tool).
- Fix failures by layer: if retrieval did not bring the right passage, the problem is RAG. If it did and the model got it wrong, the problem is the prompt or the model.
- Use a judge model to score answers at scale, with human sampling to calibrate.
- Run the suite on every change to prompt, model, knowledge base or tool, as a regression test in CI.
- After launch, review real conversations by sampling and feed the new cases into the test set.
Step 7: observability and operations
Log every conversation with the agent’s steps: retrieved context, tools called, tokens, latency and cost. LLM tracing tools show where time and money go. Alert on cost spikes, escalation rate and tool errors. Have a way to switch off the agent, or one specific tool, without publishing a new version.
Cost: where it comes from
An agent’s cost has four parts:
- Model tokens: input (prompt, retrieved context, history) and output. Large context costs on every call, so send only what is needed.
- Infrastructure: vector database, hosting, queues and storage.
- Channel: on WhatsApp, conversations carry the official provider’s own fee.
- People: maintaining the knowledge base, reviewing conversations and evolving the agent.
Ways to cut cost without losing quality: use a smaller model on simple tasks and a larger one on hard ones, cache the fixed prompt prefix, summarize long history and limit the number of retrieved chunks. Estimate cost per conversation in the pilot, with real traffic, and project the volume.
Risks and controls
Hallucination. The model can invent a convincing answer. Controls: answer only from retrieved context, require citations, allow “I don’t know” and evaluate continuously.
Prompt injection. Malicious text, from the user or from a document, tries to change the agent’s instructions. Controls: treat all external content as data and not as instructions, restrict tools, validate parameters and filter outputs.
Data leakage. The agent can expose one customer’s information to another. Controls: filter search by user permission at the database level, isolate data per customer and never rely on the prompt alone for security.
Unintended actions. Poorly designed write tools cause real damage. Controls: least privilege, confirmation, and limits on value and frequency.
Vendor dependency. Price, limits and model behavior change. Control: an abstraction layer and an evaluation suite, so you can switch models safely.
Data privacy and personal data
Data protection law applies to the agent as to any system. For companies serving US customers, that means checking which state privacy laws, such as the CCPA in California, and which sector rules apply to the data your agent touches. For Brazilian operations, it means LGPD. The practical points are similar:
- Purpose and legal basis defined for each processing activity, and disclosed to the data subject.
- Minimization: send the model only what is needed and mask identifiers when the task allows.
- Providers and cross-border transfer: evaluate where data is processed, whether the provider uses content for training and which contractual clauses apply.
- Retention: define how long to keep conversations and logs, and how to delete them.
- Data subject rights: access, correction and deletion must also be possible over the agent’s data, including the vector base.
- Encryption in transit and at rest. In the systems we build, personal data is treated as sensitive by design.
- Human review for decisions that significantly affect the data subject.
Ask your legal team or data protection officer for input from the design stage, not after the pilot.
How we deliver in weeks
We start with a free assessment that closes the scope, use our own boilerplates (authentication, multi-tenancy, CI/CD, Kubernetes and observability ready) and AI agents that write and review code under the review of a senior engineer. The same team goes from assessment to deploy. A pilot with one narrow process, evaluation and metrics usually fits in weeks, and evolution follows in short cycles.
If your agent will consume events from other systems, queues become part of the design. See our RabbitMQ .NET tutorial for idempotent consumers, retries and dead-lettering.
How we can help
We design and operate AI agents with RAG, tools and evaluation. See our AI agent development service and our LLM and RAG integration expertise. To find out which process in your company deserves an agent, request the free assessment: you leave with scope, a timeline in weeks and the risks mapped.