A Guide to Building AI Agents

A practical guide to building agents: suitable use cases, design, orchestration, and guardrails.

  • What is an agent?
  • Agent characteristics:
  • When should you build an agent?
  • Ideal use cases for agents:

Main text

  1. A practical guide to building agents

  2. Large language models (LLMs) are becoming increasingly capable of performing complex, multi-step tasks.

  3. Progress in reasoning, multimodality, and tool use has opened up a new category of LLM systems - agents.

  4. This guide is for product and engineering teams building their first agents. It gathers practical recommendations and best practices: how to identify suitable use cases, design the agent's logic and orchestration, and how to keep it safe and predictable.

  5. After reading, you will have the foundational knowledge needed for a confident start.

What is an agent?

  1. Conventional software helps automate tasks, but agents perform these tasks independently on the user's behalf.

  2. An agent is a system that independently executes workflows with a high degree of autonomy. Example workflows: resolving a customer's issue, booking a restaurant, committing to a repository, generating a report. Important: if an LLM does not control process execution but only handles individual steps (for example, a chatbot or classifier), it is not an agent.

  3. It uses an LLM to make decisions and control the process.

  4. Recognizes task completion, can correct its actions or hand control back to a human on error. 2.

  5. It has access to tools (APIs, UI) and selects the right ones depending on the current task state, acting within guardrails.

When should you build an agent?

Building agents means rethinking how systems make decisions and handle complexity. Unlike classic automation, agents are useful where rule-based systems fall short. Example: a traditional system detects fraud by patterns, while an agent analyzes context, picks up atypical signals and acts like an "experienced investigator". Ideal use cases for agents: 1. Complex decisions: handling ambiguity (e.g., refunds in customer support).

2. Complex rules: systems with cumbersome rule sets (e.g., vendor verification). 3. Unstructured data: understanding text, dialogue, and documents (e.g., insurance claims).

We'll curate materials for your task

Agent design fundamentals

  1. Core components of an agent: 1. Model - an LLM that makes decisions. 2. Tools - APIs, functions, UI actions. 3. Instructions - description of behavior and constraints. Example (Python): python CopyEdit Model selection Different models fit different tasks: you don't always need the "smartest" one. Approach: - Build a prototype on the strongest model. - Then try replacing tasks with less expensive models. Principles:
  2. Run eval tests.
  3. Use the best models for critical logic. 3.

Optimize cost and latency by downgrading the model where possible. OpenAI model selection guide Defining tools. Tools are the APIs and functions an agent can call. If no API exists, use UI interactions the way a human would. Tool types:

TypePurposeExamples
DataContext retrievalSearch across database, PDF, and the internet
ActionsState changeEmail, CRM update
OrchestrationCalling other agents as toolswriter agent, researcher agent

Example: python CopyEdit Setting up instructions. Clear instructions are the key to success. The more specific they are, the fewer errors occur. Best practices: - Reuse existing procedures and guidelines. - Break tasks into step-by-step actions. - Define clear actions and outcomes. - Account for exceptions and edge cases (e.g., if the user did not provide data). Example of generating instructions: text CopyEdit "You are an expert at writing instructions for an LLM agent.

Turn the following knowledge base document into step-by-step instructions as a list. Make sure everything is clear and unambiguous." Orchestration. Orchestration is the structure for how a task is executed by an agent or a group of agents. Options: 1. Single agent - runs the entire process. 2. Multiple agents - split responsibilities and call each other. Single agent Manages all tools and logic.

Runs in a loop until the task is complete. python CopyEdit Agents.run(agent, [UserMessage("What's the capital of the USA?")]) You can use templates: python CopyEdit "You are a call center agent talking to {{user_first_name}}.

Their complaints are about {{user_complaint_categories}}..." When to split into multiple agents: - Complex logic (many conditions). - Tool overload. - Separation by task (search, generation, verification, etc.) Multiple agents Patterns: 1. Manager - a central agent calls subordinate agents. 2. Decentralization - agents hand off control to each other. Manager pattern python CopyEdit Decentralized pattern python CopyEdit

Guardrails

Guardrails are measures that ensure safety, privacy and correctness. Types of guardrails: - Relevance classifier - rejects off-topic requests. - Safety filter - protects against prompt injection. - PII filter - checks for personal data leaks. - Moderation - filters toxic content. - Tool risk assessment - for high-risk actions, require human confirmation. - Filters and blocklists - regular expressions, length limits. - Response validation - checks alignment with brand and tone of voice.

Example of a customer churn guardrail: python CopyEdit

Sometimes an agent can't cope - a human is needed.

This matters most early on, to collect errors and improve. When to intervene: -

High-risk action (for example, a refund).

Conclusion

  1. Agents are a new stage of automation where systems: - Reason, -

  2. They perform complex tasks with high autonomy. Tips: 1.

  3. Start with a single agent and expand gradually. 2.

  4. Ensure safety with guardrails. 3.

  5. Use models, tools, and instructions wisely. 4.

  6. Focus on iteration and improvement.

Additional resources:

Discuss the article: A Practical Guide to Building…

Send via: