Skip to main content
📖 You are viewing: Conceptual Guide - Learn how agents work and build your first agentSee also: API Specification · Quickstart Tutorial
What You’ll Learn
  • What an agent is and why it’s more powerful than calling an LLM directly
  • How the agent reasoning loop works under the hood
  • How to build your first agent from scratch
  • How to configure agents for different use cases
  • Common pitfalls and how to avoid them

What is an Agent?

An agent is more than just an LLM. Think of the difference like this: Real-world analogy: An LLM is like a brilliant consultant who can only give advice. An agent is that same consultant, but now they have a phone, a computer, and access to your company’s systems—they can actually do the work.

Why Use Agents?

The LLM can only tell you it doesn’t know.

How Agents Work: The Reasoning Loop

When you send a message to an agent, it doesn’t just generate a response. It enters a reasoning loop:
Key Insight: The loop can repeat! If the LLM decides it needs more information after step 5, it goes back to step 3 and executes another tool. This enables complex multi-step reasoning.

Agent States

During processing, agents transition through different states: You can check the current state in your tools if you need conditional behavior:

Building Your First Agent

Let’s build an agent step by step, starting simple and adding features progressively.

Step 1: The Minimal Agent

Every agent needs three things:
  1. A system prompt - Tells the LLM who it is
  2. A console - Handles output display
  3. Tools - What the agent can do
What happens when you run this:
  1. Agent receives “Hello! What can you help me with?”
  2. LLM sees: System prompt + User message
  3. LLM generates a conversational response
  4. Agent returns the response
Without tools, this agent is essentially just an LLM wrapper. The power of agents comes from giving them tools to use.

Step 2: Adding Your First Tool

Let’s give the agent the ability to tell time:
What happens now:
  1. User asks “What time is it?”
  2. LLM sees the get_current_time tool and its description
  3. LLM decides: “This matches ‘What time is it?’ - I should use this tool”
  4. Agent executes get_current_time(), gets {"time": "2:30 PM", ...}
  5. LLM receives the result and generates a natural response
The docstring is crucial! The LLM reads the docstring to decide when to use a tool. “Use this tool when…” patterns are especially effective.

Step 3: Adding External Capabilities

Now let’s build something more practical—an agent that can fetch weather data:
Key patterns demonstrated:
  1. Instance variables (self.api_key) - Store configuration in __init__
  2. Tool parameters with defaults (country_code="US") - LLM learns optional params
  3. Error handling - Return error info, don’t raise exceptions
  4. Timeout handling - External APIs can be slow
  5. Rich system prompt - Guides LLM behavior beyond just tool selection

Configuration Deep Dive

Agents accept many configuration parameters. Here’s what each one does:

Choosing Your LLM Backend

Uses AMD-optimized Lemonade Server running on your machine:
Pros:
  • Free (no API costs)
  • Data stays on your machine (privacy)
  • Fast inference on AMD hardware (NPU/iGPU acceleration)
Cons:
  • Requires Lemonade Server running
  • Smaller models than cloud options
  • Local compute resources needed
Best for: Development, privacy-sensitive applications, offline use.
Uses Anthropic’s Claude models:
Pros:
  • Excellent reasoning and code understanding
  • Large context window
  • Most capable for complex tasks
Cons:
  • API costs (pay per token)
  • Requires internet connection
  • Data sent to Anthropic
Best for: Complex reasoning, production applications, code analysis.
Uses OpenAI’s GPT models:
Pros:
  • Wide tool support
  • Familiar API
  • Good general performance
Cons:
  • API costs
  • Requires internet connection
Best for: Integration with existing OpenAI workflows.

Tuning Agent Behavior


Common Pitfalls and Solutions

Symptom: Agent gives generic responses instead of using your tools.Cause: Tool docstrings don’t clearly explain when to use them.
Symptom: Agent keeps calling tools repeatedly without making progress.Cause: Usually means max_steps is too high, or tools return ambiguous results.Solutions:
Symptom: Agent stops working when a tool encounters an error.Cause: Raising exceptions in tools instead of returning error information.
Symptom: Agent becomes slow or starts giving inconsistent responses.Cause: Conversation history or tool results exceeding context limits.Solutions:

Practice Challenge

Build a File Explorer Agent

Create an agent that can:
  1. List files in a directory
  2. Read file contents
  3. Search for text in files
Requirements:
  • Handle errors gracefully (missing files, permission denied)
  • Limit file content to prevent context overflow
  • Clear tool docstrings that guide the LLM
  • Use os.listdir() for listing files
  • Use os.path.isfile() to check if path is a file
  • Catch FileNotFoundError and PermissionError
  • Return structured dicts with status fields
Why this solution works:
  1. Security: Validates paths stay within allowed directory
  2. Error handling: Returns informative error dicts instead of raising
  3. Context limits: Truncates large results to prevent overflow
  4. Clear docstrings: LLM knows exactly when to use each tool
  5. Configurable: allowed_path restricts scope for safety

Deep Dive: Under the Hood

When you call agent.process_query(user_input), here’s the detailed flow:
Key insight: The conversation history grows with each tool call, giving the LLM more context for its next decision.
The @tool decorator does several things:
The function name, type hints, and docstring are what the LLM sees, which is why they matter so much. See the Tools guide for the authoritative walkthrough of the registry entry.

Key Takeaways

Agents = LLM + Tools + Memory

Agents can plan, act, observe, and reason—not just generate text.

Three Required Methods

Every agent needs: _get_system_prompt(), _create_console(), _register_tools()

Docstrings Teach the LLM

The LLM only sees your docstring—make it clear when to use each tool.

Return Errors, Don't Raise

Tools should return error info as data so the agent can recover gracefully.

Next Steps

Tool Decorator

Deep dive into creating effective tools

Console Output

Customize how your agent displays output

User Guides

See pre-built agents for chat, code, Jira, Blender