AI Agents Explained: Reasoning, Tools and Function Calling
A chatbot answers questions. An AI agent completes tasks: it reasons about a goal, decides which tools (APIs, functions, databases, searches) to use, calls them, looks at the results and repeats until done. This is agentic AI – today’s fastest-growing area of GenAI work.
The agent loop
flowchart TD
G["User goal: Where is order ORD-1001 and can I return it?"] --> R{"Reason<br/>What do I need next?"}
R -->|call tool| T["Act: get_order_status(order_id='ORD-1001')"]
T --> O["Observe: {status: 'Out for delivery', eta: '2026-11-19'}"]
O --> R
R -->|search knowledge| K["Act: search returns policy"]
K --> O2[Observe: 30-day return window]
O2 --> R
R -->|enough information| F[Final answer to the user]
This Reason → Act → Observe cycle is the ReAct pattern. The model never executes code itself – it asks your application to run a tool, and your code returns the result.
Tool (function) calling
You describe each tool with a name, description and parameter schema; the model decides when to call it and fills the arguments.
{
"toolSpec": {
"name": "get_order_status",
"description": "Get the delivery status of an order",
"inputSchema": { "json": {
"type": "object",
"properties": { "order_id": { "type": "string", "description": "The order ID, e.g. ORD-1001" } },
"required": ["order_id"]
} }
}
}
- Send messages +
toolConfigto the model (Converse API). - The model replies with
stopReason: "tool_use"and{ name, input }. - Your code runs the tool and sends back a
toolResultmessage. - The model writes the final answer (or calls another tool).
The model chooses tools from their descriptions. Clear names, descriptions and parameter descriptions are the single biggest factor in agent accuracy. Missing required parameters make a good agent ask a clarifying question.
Building blocks of an agent
| Block | Purpose |
|---|---|
| Instructions | Role, goals, tone and limits |
| Model | Strong reasoning and tool-use ability (e.g. Claude Sonnet/Haiku, Nova Pro) |
| Tools / actions | APIs and functions the agent may call |
| Knowledge | RAG over documents |
| Memory | Conversation history (short-term) and summaries across sessions (long-term) |
| Planner / orchestration | Decides the sequence of steps |
| Guardrails & permissions | What the agent is allowed to see and do |
Agent or workflow?
| Use a deterministic workflow (Step Functions) when… | Use an agent when… |
|---|---|
| Steps are known and fixed | Steps depend on the request and results |
| Compliance requires exact sequences | Natural-language goals, many possible paths |
| Lowest cost and latency | Flexibility is worth extra tokens and latency |
Many production systems combine both: a workflow that calls an agent for the flexible step, or an agent whose tools are well-defined workflows.
Risks and controls
- Least privilege for every tool (an agent with delete permissions will eventually delete).
- Confirmation / human approval before irreversible actions.
- Guardrails against prompt injection – including injection hidden in tool results and documents.
- Traces and logs of every reasoning step and tool call for debugging and audit.
- Limits on iterations, tokens and spend.
Practise it
Virtual lab · Amazon Web Services · 45 min
Build an AI agent with Bedrock Agents, a Lambda tool and a knowledge base
Create an order-support agent that decides when to call your Lambda function (looking up orders in DynamoDB), asks for missing details, answers policy questions from a knowledge base, and explains every step in its trace.
Quick revision
- Agents pursue goals with a Reason → Act → Observe loop.
- Tools are described by name, description and JSON schema; your code executes them.
- Good descriptions drive tool choice; agents ask for missing parameters.
- Instructions, model, tools, knowledge, memory and guardrails make an agent.
- Use workflows for fixed processes, agents for open-ended tasks – with least privilege and approvals.
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.