13 — LlamaIndex Agents and Tools¶
Learn how LlamaIndex extends RAG applications into tool-enabled AI systems by connecting LLMs with tools, APIs, data sources, and workflows, while keeping the focus on enterprise application architecture, controlled execution, and production integration.
📖 Overview¶
A RAG application primarily answers questions using retrieved knowledge.
An agent-enabled application goes one step further:
User Request
↓
Understand Task
↓
Decide What Is Needed
↓
Select Tool
↓
Execute Tool
↓
Inspect Result
↓
Continue / Finish
LlamaIndex provides abstractions that can connect LLMs with:
- Retrieval systems
- APIs
- Python functions
- Databases
- Enterprise services
- Search systems
- Other application capabilities
A simplified architecture is:
User
│
▼
Agent / LLM
│
┌──────────┼──────────┐
▼ ▼ ▼
Retriever Tool API
│ │ │
▼ ▼ ▼
Knowledge Function Enterprise
Store Service
│ │ │
└──────────┼──────────┘
▼
Result
│
▼
Agent / LLM
│
▼
Answer
The important architectural distinction is:
🎯 Learning Objectives¶
After completing this chapter, you will be able to:
- Understand the role of tools in LlamaIndex
- Understand the difference between RAG and tool-enabled agents
- Understand function tools
- Understand query-engine tools
- Understand retrieval tools
- Understand API-backed tools
- Understand tool schemas
- Understand tool selection
- Understand tool execution
- Understand tool results
- Build simple LlamaIndex agents
- Connect agents with RAG systems
- Connect agents with enterprise APIs
- Understand tool safety boundaries
- Design controlled tool execution
- Understand state and execution concerns
- Design production-oriented tool integrations
- Understand common agent-tool failure patterns
1. RAG vs Agent¶
A traditional RAG application usually follows:
An agent-enabled application can dynamically choose what capability it needs:
User Request
↓
Agent
↓
┌────┼───────────────┐
▼ ▼ ▼
RAG API Function
│ │ │
└────┼───────────────┘
▼
Result
↓
Agent
↓
Answer
2. What Is a Tool?¶
A tool is an application capability exposed to an LLM or agent through a controlled interface.
Examples:
get_customer()
search_documents()
calculate_price()
create_ticket()
query_database()
send_notification()
check_inventory()
Conceptually:
3. Tool Architecture¶
flowchart LR
A[Agent / LLM] --> B[Tool Definition]
B --> C[Input Schema]
B --> D[Tool Executor]
D --> E[Enterprise Service]
E --> F[Tool Result]
F --> A
The LLM does not directly execute arbitrary application code.
Instead:
4. Why Tools Matter¶
LLMs are primarily reasoning and language-processing systems.
They may not have direct access to:
Current Database State
Enterprise APIs
Internal Systems
Real-Time Prices
Operational Systems
Calculators
Business Workflows
Tools provide controlled access to these capabilities.
5. Tool Calling vs Function Calling¶
These terms are often used interchangeably, but the architectural idea is:
The important production concern is not the terminology.
It is:
The application should remain responsible for executing tools.
6. Tool Calling Flow¶
sequenceDiagram
participant U as User
participant A as Agent
participant L as LLM
participant T as Tool
participant S as Service
U->>A: User Request
A->>L: Request + Available Tools
L-->>A: Tool Call
A->>T: Validate Input
T->>S: Execute Operation
S-->>T: Result
T-->>A: Tool Result
A->>L: Result + Original Task
L-->>A: Final Response
A-->>U: Response
7. Function Tool¶
A function can be exposed as a tool.
Conceptually:
def get_customer_balance(
customer_id: str
) -> float:
"""
Return the current account balance.
"""
return 1250.50
The function can then be represented as a tool with:
The exact tool-wrapper API should be verified against the LlamaIndex version being used.
8. Tool Schema¶
A good tool definition describes:
Example conceptual schema:
{
"name": "get_customer_balance",
"description": "Retrieve the current customer account balance.",
"parameters": {
"customer_id": {
"type": "string"
}
}
}
9. Why Tool Descriptions Matter¶
Compare:
with:
The second provides more useful information to the model.
Tool descriptions should communicate:
Avoid vague tool descriptions.
10. Tool Input Validation¶
Never assume that model-generated arguments are safe.
Use:
Example:
For production systems, validation should occur before any side effect.
11. Tool Execution Boundary¶
A critical architecture principle:
LLM
│
│ Request
▼
Tool Boundary
│
├── Schema Validation
├── Authorization
├── Policy Checks
├── Rate Limits
└── Audit
│
▼
Enterprise Service
The tool boundary is a security and reliability boundary.
12. Query Engine as a Tool¶
A LlamaIndex query engine can conceptually be exposed as a capability.
For example:
Agent
↓
Knowledge Search Tool
↓
LlamaIndex Query Engine
↓
Retriever
↓
Vector Store
↓
Relevant Context
This allows an agent to decide when enterprise knowledge retrieval is required.
13. RAG Tool Architecture¶
flowchart TD
A[Agent] --> B[Knowledge Tool]
B --> C[LlamaIndex Query Engine]
C --> D[Retriever]
D --> E[(Vector Store)]
E --> F[Relevant Nodes]
F --> G[Response Synthesis]
G --> H[Tool Result]
H --> A
14. Agent + RAG¶
A useful architecture is:
Agent
│
┌───────────┼───────────┐
▼ ▼ ▼
Knowledge Customer Calculator
Tool API Tool
│ │ │
▼ ▼ ▼
LlamaIndex Service Function
│
▼
Vector Store
The agent does not need to know how retrieval is implemented internally.
It only needs a well-defined capability:
15. Tool Selection¶
Suppose the user asks:
The agent may select:
For:
it may select:
For:
it may select:
Conceptually:
16. Tool Selection Architecture¶
flowchart TD
A[User Request] --> B[Agent]
B --> C{Required Capability}
C -->|Knowledge| D[RAG Tool]
C -->|Customer Data| E[Customer API Tool]
C -->|Calculation| F[Calculation Tool]
C -->|Business Action| G[Workflow Tool]
D --> H[Tool Result]
E --> H
F --> H
G --> H
H --> B
B --> I[Final Response]
17. Multiple Tools¶
An enterprise agent may have several tools:
The agent can select an appropriate tool based on the request.
The exact LlamaIndex agent construction API depends on the version and agent architecture used.
18. Tool Result¶
Tool results should be:
Example:
Prefer structured results over returning unnecessary application data.
19. Tool Result → Agent¶
The agent can use the result as new context:
For multi-step tasks:
20. Multi-Step Tool Execution¶
Example:
User:
"Find customer 123's account and tell me whether
their balance is sufficient for the requested payment."
Potential execution:
This is where agents provide value beyond a fixed RAG pipeline.
21. Multi-Step Tool Architecture¶
flowchart LR
A[User Task] --> B[Agent]
B --> C[Customer Tool]
C --> D[Customer Result]
D --> B
B --> E[Account Tool]
E --> F[Account Result]
F --> B
B --> G[Balance Tool]
G --> H[Balance Result]
H --> B
B --> I[Final Response]
22. Agent Loop¶
An agent can conceptually operate as:
This should be bounded.
Production systems should avoid unrestricted execution loops.
23. Bounded Execution¶
Use limits such as:
Conceptually:
If the limit is reached:
24. Agent Loop Architecture¶
flowchart TD
A[Task] --> B[Agent]
B --> C{Complete?}
C -->|Yes| D[Final Response]
C -->|No| E[Select Tool]
E --> F[Validate]
F --> G[Execute]
G --> H[Tool Result]
H --> B
B --> I{Limit Reached?}
I -->|Yes| J[Stop / Escalate]
I -->|No| C
25. Read vs Write Tools¶
Not all tools have the same risk.
Read Tools¶
Write Tools¶
Write tools are significantly more sensitive because they can create external side effects.
26. Tool Risk Classification¶
A useful enterprise classification:
LOW
└── Read-only
MEDIUM
└── Internal workflow
HIGH
└── External side effect
CRITICAL
└── Financial / destructive action
This classification can drive approval and authorization policies.
27. Read-Only Tool Architecture¶
Usually:
may be required, depending on organizational policy.
28. Write Tool Architecture¶
Agent
↓
Write Tool Request
↓
Schema Validation
↓
Authorization
↓
Risk Policy
↓
Human Approval?
├── Yes → Approval → Execute
└── No → Execute
29. Human-in-the-Loop¶
Sensitive operations may require explicit approval.
Example:
Agent:
"Refund customer $5,000?"
↓
Approval Required
↓
Human Approves
↓
Refund Tool
↓
Payment System
Human-in-the-loop and advanced autonomous multi-agent patterns belong to the later Agentic AI module, but the tool boundary should be designed to support controlled approval.
30. Tool Authorization¶
A user may be allowed to:
but not:
Therefore:
should both be evaluated.
31. Authorization Architecture¶
flowchart TD
A[User] --> B[Agent]
B --> C[Requested Tool]
C --> D[Authorization Service]
D --> E{Allowed?}
E -->|Yes| F[Execute Tool]
E -->|No| G[Deny]
F --> H[Tool Result]
H --> B
32. Tenant-Aware Tools¶
Tools should preserve tenant boundaries.
Example:
However, the application should not blindly trust a tenant ID supplied by the model.
Prefer:
33. Trusted Context¶
Bad:
Better:
The application should derive security context from trusted infrastructure.
34. Tool Sandboxing¶
Tool execution can be isolated from the main application.
Conceptually:
This can reduce the impact of unexpected tool behavior.
35. Tool Gateway¶
An enterprise architecture may centralize tool controls:
flowchart TD
A[Agent] --> B[Tool Gateway]
B --> C[Schema Validation]
C --> D[Authorization]
D --> E[Policy Engine]
E --> F[Rate Limiting]
F --> G[Audit Logging]
G --> H[Tool Executor]
H --> I[Enterprise Service]
I --> J[Result]
J --> A
This pattern becomes particularly valuable as the number of tools grows.
36. Tool Timeout¶
Every external tool should have a timeout.
Conceptually:
If the service does not respond:
Do not allow an agent to wait indefinitely.
37. Tool Retries¶
Retries should be selective.
Suitable:
Potentially unsafe:
Blind retries can duplicate side effects.
38. Idempotency¶
Write tools should consider idempotency.
Example:
If the same request is accidentally repeated:
39. Tool Reliability¶
A production tool should expose predictable behavior:
Example:
Structured errors are easier for the agent and application to handle.
40. Tool Error Handling¶
flowchart TD
A[Agent Tool Call] --> B[Validate Input]
B --> C{Valid?}
C -->|No| D[Validation Error]
C -->|Yes| E[Execute]
E --> F{Success?}
F -->|Yes| G[Tool Result]
F -->|No| H[Classify Error]
H --> I[Retryable]
H --> J[Non-Retryable]
I --> K[Retry / Fallback]
J --> L[Return Structured Error]
G --> M[Agent]
K --> M
L --> M
41. Tool Observability¶
Track:
Tool Name
Tool Version
Input Schema
Execution Time
Status
Error Code
Retry Count
User / Tenant
Trace ID
Cost
Avoid logging sensitive tool arguments unnecessarily.
42. Tool Trace¶
Trace ID: abc-123
Agent
├── Tool: search_documents
│ ├── latency: 120ms
│ └── status: success
│
├── Tool: get_customer
│ ├── latency: 80ms
│ └── status: success
│
└── Tool: calculate
├── latency: 5ms
└── status: success
This makes agent behavior diagnosable.
43. Agent Observability¶
An agent trace should show:
This is more useful than logging only:
44. Tool Metrics¶
Useful metrics include:
Tool Calls
Tool Success Rate
Tool Failure Rate
Tool Latency
Timeout Rate
Retry Rate
Authorization Denials
Rate Limit Events
Track these by:
where appropriate.
45. Tool Cost¶
Tools can also have cost.
Examples:
A useful model is:
46. Tool Selection Quality¶
An agent can fail even when every tool works correctly.
Example:
The tool is healthy.
The decision is wrong.
Therefore evaluate:
47. Tool Selection Evaluation¶
Create a test dataset:
Example:
Question:
"What is customer 123's balance?"
Expected Tool:
get_customer_balance
Expected Parameter:
customer_id = 123
48. Agent Tool Evaluation¶
flowchart TB
A[Test Task] --> B[Agent]
B --> C[Selected Tool]
C --> D[Tool Arguments]
D --> E[Tool Execution]
E --> F[Result]
C --> G[Expected Tool]
D --> H[Expected Arguments]
F --> I[Expected Result]
G --> J[Evaluation]
H --> J
I --> J
49. Tool Calling Failure Patterns¶
Failure 1 — Wrong Tool¶
Failure 2 — Invalid Arguments¶
Failure 3 — Unauthorized Tool¶
Failure 4 — Tool Timeout¶
Failure 5 — Repeated Tool Calls¶
Potential causes:
50. Tool Failure Architecture¶
flowchart TD
A[Agent] --> B[Tool Selection]
B --> C{Correct Tool?}
C -->|No| D[Wrong Tool]
C -->|Yes| E[Validate Arguments]
E --> F{Valid?}
F -->|No| G[Validation Error]
F -->|Yes| H[Authorization]
H --> I{Allowed?}
I -->|No| J[Authorization Error]
I -->|Yes| K[Execute]
K --> L{Successful?}
L -->|No| M[Timeout / Dependency Error]
L -->|Yes| N[Tool Result]
N --> O[Agent]
51. Tool Description Failure¶
Poor:
Better:
Best:
Search authorized enterprise documents
for policies, procedures, and internal
knowledge relevant to the supplied query.
Good descriptions improve tool selection.
52. Too Many Tools¶
Giving an agent hundreds of tools can create problems:
Prefer:
rather than:
53. Tool Grouping¶
Instead of exposing:
consider capability domains:
Customer Tools
├── get_customer
├── search_customer
└── update_customer
Knowledge Tools
├── search_policy
└── search_documents
Finance Tools
├── get_balance
└── calculate_payment
The application can expose an appropriate subset.
54. Tool Registry¶
A production system may maintain a tool registry.
Conceptually:
tool_registry = {
"knowledge.search": knowledge_search,
"customer.get": get_customer,
"account.balance": get_balance,
"calculator.calculate": calculate
}
The registry can support:
55. Tool Versioning¶
Tools can evolve.
Versioning helps avoid silently changing behavior underneath an agent.
A production tool registry can track:
56. Tool Contract¶
A tool should behave like an API contract:
Changes to the contract should be treated like API changes.
57. Tool Contract Testing¶
Test:
Valid Input
Invalid Input
Missing Input
Unauthorized Input
Boundary Values
Timeout
Dependency Failure
Expected Output
This prevents agent failures from being caused by unstable tool interfaces.
58. Agent + LlamaIndex RAG¶
A common Enterprise AI pattern:
Agent
│
┌────────────┼─────────────┐
▼ ▼ ▼
Knowledge Customer Calculator
Tool API Tool
│
▼
LlamaIndex
│
▼
Vector Store
The RAG capability becomes one tool among several.
59. Agent + SQL¶
A structured data tool can expose controlled database access.
For production systems, unrestricted arbitrary SQL execution should generally not be exposed directly to an LLM.
Prefer:
60. Agent + Enterprise API¶
The agent should not need to understand:
Those concerns belong behind the tool interface.
61. Agent + Multiple Systems¶
flowchart TB
A[Agent] --> B[Knowledge Tool]
A --> C[Customer Tool]
A --> D[Finance Tool]
A --> E[Ticket Tool]
B --> F[(Vector Store)]
C --> G[Customer API]
D --> H[Finance Service]
E --> I[ITSM Platform]
This turns the agent into an orchestration layer across enterprise capabilities.
62. Tool Gateway vs Direct Integration¶
Direct¶
Enterprise¶
For larger platforms, centralized controls can simplify governance.
63. LlamaIndex Agent Architecture¶
Conceptually:
User
│
▼
Agent
│
┌───────────┼───────────┐
▼ ▼ ▼
Tool 1 Tool 2 Tool 3
│ │ │
▼ ▼ ▼
RAG API Function
│ │ │
└───────────┼───────────┘
▼
Tool Results
│
▼
Agent
│
▼
Final Answer
LlamaIndex provides agent/tool abstractions, while the enterprise application remains responsible for security, authorization, infrastructure, and operational controls.
64. Agent State¶
Agent execution may require state such as:
Conceptually:
State design becomes increasingly important for long-running workflows.
65. Stateless vs Stateful Execution¶
Stateless¶
Stateful¶
Stateful execution requires explicit lifecycle and persistence decisions.
66. Tool State¶
Avoid putting important business state only inside an LLM conversation.
Instead:
while:
The system of record should remain authoritative.
67. Tool Security Principles¶
Follow:
Least Privilege
+
Explicit Authorization
+
Input Validation
+
Output Validation
+
Audit Logging
+
Timeouts
+
Rate Limits
+
Idempotency
68. Least Privilege¶
A tool should receive only the permissions it needs.
Bad:
Better:
Better still:
69. Secrets¶
Never expose secrets to the model.
Bad:
Better:
The credential remains outside model context.
70. Secret Architecture¶
flowchart LR
A[Agent] --> B[Tool]
B --> C[Secret Manager]
C --> D[Credential]
B --> E[Enterprise API]
D --> E
E --> F[Result]
F --> A
The model should receive:
not:
71. Tool Output Sanitization¶
External systems may return:
Tool results should therefore be treated as untrusted input.
72. Indirect Prompt Injection¶
A retrieved document or API result might contain instructions such as:
The agent should treat retrieved content as:
not automatically as:
This is especially important when tools retrieve untrusted external content.
73. Tool Output Trust Boundary¶
flowchart TD
A[External Data] --> B[Tool]
B --> C[Untrusted Result]
C --> D[Validation / Sanitization]
D --> E[Agent Context]
E --> F[LLM]
F --> G[Tool Decision]
74. Agent Tool Execution Policy¶
A production policy might define:
Allowed Tools
+
Allowed Users
+
Allowed Tenants
+
Allowed Operations
+
Rate Limits
+
Approval Requirements
Example:
get_customer
→ Allowed
update_customer
→ Manager Role Required
delete_customer
→ Human Approval Required
75. Tool Governance¶
As an enterprise tool ecosystem grows:
governance becomes important.
Track:
76. Tool Registry Architecture¶
flowchart TB
A[Agent Platform] --> B[Tool Registry]
B --> C[Tool Metadata]
B --> D[Tool Schema]
B --> E[Permissions]
B --> F[Version]
B --> G[Risk Classification]
B --> H[Tool Gateway]
H --> I[Tool Services]
77. Tool Lifecycle¶
DESIGN
↓
DEFINE CONTRACT
↓
IMPLEMENT
↓
TEST
↓
SECURITY REVIEW
↓
REGISTER
↓
DEPLOY
↓
MONITOR
↓
VERSION
↓
RETIRE
78. Tool Testing¶
Tools should be tested independently of the agent.
This helps isolate:
from:
79. Agent Testing¶
Agent tests should verify:
Correct Tool
+
Correct Arguments
+
Correct Execution Order
+
Correct Handling of Results
+
Correct Final Answer
Example:
80. Tool Sequence Evaluation¶
flowchart LR
A[Test Task] --> B[Agent]
B --> C[Observed Tool 1]
C --> D[Observed Tool 2]
D --> E[Observed Tool 3]
F[Expected Tool 1] --> G[Evaluation]
H[Expected Tool 2] --> G
I[Expected Tool 3] --> G
C --> G
D --> G
E --> G
81. Agent Cost Control¶
Agent loops can increase cost.
Example:
Therefore track:
82. Agent Budget¶
A production execution can have:
Conceptually:
The exact enforcement mechanism depends on the application architecture.
83. Tool Rate Limiting¶
A tool may enforce:
while the agent may attempt more.
Therefore:
The agent should receive a structured rate-limit response rather than being allowed to overload the service.
84. Tool Availability¶
A production agent should handle:
The agent should not assume that every registered tool is always available.
85. Graceful Degradation¶
If a tool fails:
Example:
or:
Fallback behavior should be explicitly designed.
86. Do Not Guess Tool Results¶
If:
fails, the agent should not invent:
Instead:
This is a fundamental reliability principle.
87. Tool Result Grounding¶
The final response should remain consistent with the tool result.
For sensitive operations, validate the final response against the authoritative system state where necessary.
88. Agent + RAG + Tools¶
A powerful enterprise pattern is:
flowchart TB
A[User] --> B[Agent]
B --> C[Knowledge Tool]
B --> D[Customer Tool]
B --> E[SQL Tool]
B --> F[Calculation Tool]
C --> G[LlamaIndex RAG]
G --> H[(Vector Store)]
D --> I[Customer Service]
E --> J[(Database)]
F --> K[Function]
C --> B
D --> B
E --> B
F --> B
B --> L[Final Response]
This architecture combines:
under a controlled agent interface.
89. RAG Tool vs Agent¶
RAG alone:
Agent with RAG:
Task
↓
Should I search?
├── Yes → RAG Tool
└── No
↓
Should I call API?
├── Yes → API Tool
└── No
↓
Answer
The agent adds decision-making around capabilities.
90. Tool Selection vs Hard-Coded Workflow¶
Hard-Coded Workflow¶
Tool-Enabled Agent¶
The second approach provides flexibility but introduces additional complexity and risk.
91. When Not to Use an Agent¶
Do not automatically use an agent for every workflow.
If the process is deterministic:
a normal workflow may be:
Agents are useful when the required execution path is not completely known in advance.
92. Agent vs Workflow¶
| Requirement | Deterministic Workflow | Agent |
|---|---|---|
| Fixed steps | Excellent | Possible |
| Predictability | High | Lower |
| Dynamic tool selection | Limited | Strong |
| Variable task path | Limited | Strong |
| Debugging | Easier | Harder |
| Cost control | Easier | More complex |
| Governance | Easier | More complex |
| Autonomous decision-making | Limited | Strong |
The right choice depends on the problem.
93. Production Agent Architecture¶
flowchart TB
A[User] --> B[API Gateway]
B --> C[Authentication]
C --> D[Authorization]
D --> E[Agent Service]
E --> F[Agent Runtime]
F --> G[Tool Gateway]
G --> H[Policy Engine]
H --> I[Authorization]
I --> J[Tool Executor]
J --> K[Enterprise Services]
J --> L[LlamaIndex RAG]
L --> M[(Vector Store)]
J --> N[(Databases)]
F --> O[LLM]
F --> P[State Store]
E --> Q[Observability]
F --> Q
G --> Q
J --> Q
94. Production Design Principles¶
A production LlamaIndex agent should have:
Explicit Tool Contracts
+
Authorization
+
Input Validation
+
Bounded Execution
+
Timeouts
+
Rate Limits
+
Structured Errors
+
Observability
+
Audit
+
Cost Controls
95. Common Anti-Patterns¶
Anti-Pattern 1¶
Avoid.
Use:
Anti-Pattern 2¶
Avoid.
Use:
Anti-Pattern 3¶
Avoid.
Use:
96. Anti-Pattern 4 — Secrets in Context¶
Avoid:
Use:
97. Anti-Pattern 5 — No Execution Limits¶
Avoid:
Use:
98. Anti-Pattern 6 — Business Logic Inside Prompts¶
Avoid putting critical business rules only inside:
Prefer:
Critical business controls should be enforced by deterministic application code.
99. Tool Architecture Checklist¶
Tool Design¶
- [ ] Clear name
- [ ] Clear description
- [ ] Explicit schema
- [ ] Input validation
- [ ] Structured output
- [ ] Structured errors
Security¶
- [ ] Authorization
- [ ] Least privilege
- [ ] Tenant isolation
- [ ] Secret management
- [ ] Output sanitization
- [ ] Audit logging
Reliability¶
- [ ] Timeout
- [ ] Retry policy
- [ ] Idempotency
- [ ] Rate limits
- [ ] Fallback behavior
- [ ] Dependency monitoring
Agent¶
- [ ] Tool selection evaluation
- [ ] Maximum tool calls
- [ ] Execution timeout
- [ ] Token budget
- [ ] Cost controls
- [ ] State management
100. Key Takeaways¶
- Tools provide controlled capabilities to AI agents.
- A tool is an application interface, not arbitrary model execution.
- LlamaIndex can connect agents with retrieval, APIs, functions, and enterprise capabilities.
- RAG can be exposed as a tool.
- Query engines can become knowledge capabilities for agents.
- Tool descriptions and schemas influence tool selection.
- Tool arguments must be validated before execution.
- Authorization must happen at the application/tool boundary.
- Tenant context should come from trusted application infrastructure.
- Write tools require stronger controls than read-only tools.
- Idempotency is important for side-effecting operations.
- Tool failures should produce structured errors.
- Agents should have bounded execution.
- Tool calls should be observable and auditable.
- Tool registries become useful as enterprise tool ecosystems grow.
- Tool contracts should be independently tested.
- Agent evaluation should verify tool selection and arguments.
- Tool results should be treated as potentially untrusted external data.
- Secrets should never be exposed to the model.
- Agents should not guess when authoritative tools fail.
- Not every workflow needs an agent.
- Deterministic workflows are often better for predictable processes.
- Agents are most useful when the execution path must dynamically adapt to the task.
- LlamaIndex should remain behind appropriate application and capability boundaries in enterprise systems.
📝 Quick Revision Notes¶
Tool¶
Tool Calling¶
Agent + RAG¶
Secure Tool Execution¶
Agent
↓
Tool Gateway
↓
Validation
↓
Authorization
↓
Policy
↓
Rate Limit
↓
Audit
↓
Tool
↓
Enterprise Service
Agent Execution¶
with:
Tool Reliability¶
❓ Interview Questions¶
Beginner¶
- What is a tool in an AI agent?
- What is the difference between a tool and an LLM?
- What is tool calling?
- What is function calling?
- What is a tool schema?
- Why are tool descriptions important?
- What is the difference between a retriever and a tool?
- How can RAG be exposed as a tool?
- What is a query-engine tool?
- What is a tool result?
Intermediate¶
- Explain the complete tool-calling lifecycle.
- How does an agent select a tool?
- How would you validate tool arguments?
- How would you handle tool failures?
- Why are write tools more dangerous than read tools?
- What is idempotency and why does it matter for agent tools?
- How would you implement tool timeouts?
- How would you implement tool rate limiting?
- How would you expose enterprise APIs as tools?
- How would you expose RAG as a tool?
- What is a tool registry?
- Why should tools have explicit contracts?
- How would you evaluate tool selection?
- How would you prevent an agent from calling tools indefinitely?
Advanced¶
- Design an enterprise LlamaIndex agent architecture.
- How would you secure agent tool execution?
- How would you enforce tenant isolation for tools?
- How would you prevent secrets from entering model context?
- How would you protect against indirect prompt injection through tool results?
- How would you design a centralized tool gateway?
- How would you classify tool risk?
- Which tools should require human approval?
- How would you design idempotent financial tools?
- How would you monitor tool execution?
- How would you evaluate tool selection accuracy?
- How would you debug an agent selecting the wrong tool?
- How would you handle unavailable tools?
- How would you implement graceful degradation?
- How would you control agent cost?
- How would you design a tool registry for hundreds of enterprise tools?
- How would you decide between an agent and a deterministic workflow?
- How would you design RAG + API + SQL capabilities under one agent?
- How would you isolate framework-specific agent code from business logic?
- How would you design a production tool lifecycle?
- How would you prevent a tool from becoming an unrestricted gateway to an enterprise system?
🛠️ Practical Exercise¶
Build an enterprise support agent using LlamaIndex.
The agent should have:
Architecture:
Support Agent
│
┌────────────────┼────────────────┐
▼ ▼ ▼
Knowledge Customer Calculator
Tool Tool Tool
│ │ │
▼ ▼ ▼
LlamaIndex Customer API Function
│
▼
Vector Store
Step 1 — Build Knowledge Tool¶
Support:
Return:
Step 2 — Build Customer Tool¶
Support:
Return structured data:
Step 3 — Build Balance Tool¶
Support:
Return:
Step 4 — Build Calculator Tool¶
Support:
For production systems, use a safe calculation implementation rather than arbitrary code execution.
Step 5 — Build Agent¶
Example task:
Expected tool sequence:
🧪 Testing Exercise¶
Create test cases for:
Correct Tool¶
Customer Lookup¶
Balance¶
Calculation¶
🔐 Security Exercise¶
Test:
Expected:
Test:
Expected:
🚀 Production Exercise¶
Add:
Architecture:
flowchart TB
A[Agent] --> B[Tool Gateway]
B --> C[Schema Validation]
C --> D[Authorization]
D --> E[Policy Engine]
E --> F[Rate Limiter]
F --> G[Audit]
G --> H[Tool Executor]
H --> I[Enterprise Service]
I --> J[Result]
J --> A
📊 Evaluation Exercise¶
Build a dataset with:
Measure:
Tool Selection Accuracy
Tool Argument Accuracy
Tool Execution Success
Task Completion
Latency
Tool Calls / Task
LLM Calls / Task
Cost / Task
Example:
🏢 Enterprise Architecture Challenge¶
Design an enterprise agent platform with:
500 Tenants
100+ Tools
Multiple LLM Providers
LlamaIndex RAG
Enterprise APIs
SQL Databases
Strict Authorization
Audit Requirements
High Availability
Required:
Tool Registry
+
Tool Gateway
+
Authorization
+
Tenant Isolation
+
Tool Versioning
+
Execution Limits
+
Observability
+
Evaluation
🧠 Architecture Challenge¶
Design:
User
│
▼
API Gateway
│
▼
Authentication
│
▼
Authorization
│
▼
Agent Service
│
▼
Agent Runtime
│
┌─────┴─────┐
▼ ▼
Tool Registry State
│
▼
Tool Gateway
│
┌──────────┼──────────┐
▼ ▼ ▼
Knowledge Customer Finance
│ │ │
▼ ▼ ▼
LlamaIndex API Service
│
▼
Vector Store
The design should address:
📚 References & Further Reading¶
Recommended areas for further study:
- LlamaIndex Agents
- LlamaIndex Tools
- LlamaIndex Function Tools
- LlamaIndex Query Engine Tools
- LlamaIndex Retrieval Tools
- LlamaIndex Workflows
- LlamaIndex Agent Memory and State
- Tool Calling
- Function Calling
- Enterprise API Integration
- Agent Security
- Tool Governance
- Agent Evaluation
- Agent Observability
- Human-in-the-Loop
- Tool Sandboxing
- Agent Runtime Architecture
LlamaIndex APIs evolve rapidly. Before implementing production systems, verify the current agent classes, tool abstractions, workflow APIs, tool interfaces, state management APIs, and model integrations against the official documentation for the version used by your project.
🧭 Chapter Navigation¶
⬅️ Previous: 12. LlamaIndex RAG Pipelines
📚 Part VIII Index: AI Engineering Frameworks & Tooling
➡️ Next: 14. LlamaIndex Workflows
Enterprise AI Engineering Handbook
Building Production-Grade Enterprise AI Systems — One Chapter at a Time.