Skip to content
VirtualLP Virtual Learning Platform

AI Agents Explained: Reasoning, Tools and Function Calling

14 min read Topic 28 of 30 1 hands-on lab

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"]
    } }
  }
}
  1. Send messages + toolConfig to the model (Converse API).
  2. The model replies with stopReason: "tool_use" and { name, input }.
  3. Your code runs the tool and sends back a toolResult message.
  4. The model writes the final answer (or calls another tool).
Descriptions matter

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.

Open lab

Quick revision

  1. Agents pursue goals with a Reason → Act → Observe loop.
  2. Tools are described by name, description and JSON schema; your code executes them.
  3. Good descriptions drive tool choice; agents ask for missing parameters.
  4. Instructions, model, tools, knowledge, memory and guardrails make an agent.
  5. 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.