Knowledge / Artificial Intelligence and Data Science / AI agents and tool use

AI agents and tool use

Artificial Intelligence and Data Science (B.E./B.Tech) · AI applications · free study notes for exams, placements and interviews

In short

An AI agent is a system that perceives its environment, decides what to do and acts through actuators or software tools to reach a goal. Classical AI (AICTE/CBCS "Artificial Intelligence" and GATE DA/CS syllabi) defines agents formally — PEAS, agent types, rationality — while modern practice builds agents on large language models that call external tools such as search, SQL, calculators and company APIs. The two views are examined together: theory questions on agent architectures and environment properties, and practical questions on function calling, the ReAct loop, memory and failure modes. Indian employers (TCS, Infosys, Wipro, Accenture, Fractal, Sprinklr, Zoho, Freshworks, Razorpay, Jio, startups building copilots) now hire specifically for "agentic AI" roles, so this topic appears in both exam papers and placement technical rounds.

Explained

Classical agent theory (what exams define)

LLM-based agents: anatomy

The agent loop and prompting patterns

Multi-agent systems

Evaluation, reliability and cost

Indian context, law and practice

Key points

Formulas and examples

Agent function: f : P* → A — P* = set of all percept sequences, A = set of actions. The agent program implements f with bounded memory.
Rational action: a* = argmax over a of Σ P(s' | s, a) · U(s') — P = transition probability, U = utility of resulting state s' (dimensionless utility units).
Expected utility with cost: EU(a) = Σ P(outcome) · U(outcome) − C(a), where C(a) = cost of the action in ₹ or tokens.
End-to-end success of an n-step agent (independent steps): S = p₁ × p₂ × … × pₙ; if all equal, S = pⁿ.
Expected steps with retries, success probability p per attempt, max k attempts: P(success) = 1 − (1 − p)k.
Cost per task (₹) = Σ over turns [ (input tokens × rate_in + output tokens × rate_out) ] + Σ tool API charges. Rates are usually quoted per million tokens (MTok) in USD; convert at the day's USD-INR rate.
Tokens per agent run ≈ Σ over steps [ system prompt + tool schemas + history so far + new observation + generated text ] — note history is re-sent every step, so context grows roughly quadratically with steps.
Tool-call accuracy = (calls with correct tool AND valid arguments) / (total tool calls).
Amdahl-style latency: T_total = T_model × n_steps + Σ T_tool; parallel tool calls replace Σ T_tool by max(T_tool).

Example 1 — Error compounding and where to spend effort. A document-processing agent has 4 steps with reliabilities 0.95, 0.90, 0.98, 0.92.

Example 2 — Retries on a flaky tool. A tool succeeds with p = 0.7 per attempt; the agent allows k = 3 attempts.

Example 3 — Token growth and cost of an agent run. System prompt + tool schemas = 1,200 tokens. History grows by 400 tokens per step (model text + observation). The agent runs 6 steps and generates 150 output tokens per step.

Example 4 — Latency: sequential vs parallel tool calls. Model latency 1.2 s per step; three independent API tools take 0.8 s, 1.5 s and 0.6 s.

Example 5 — ReAct trace for a GST query (tool-use pattern).

User: What is the total GST on our three largest October invoices?

Thought: I need the invoice amounts first. Use sql_query.
Action: sql_query
Action Input: {"q":"SELECT id, amount, gst_rate FROM invoices
               WHERE month='2026-10' ORDER BY amount DESC LIMIT 3"}
Observation: [{id:4471, amount:250000, gst_rate:18},
              {id:4458, amount:180000, gst_rate:5},
              {id:4440, amount:120000, gst_rate:18}]

Thought: Compute GST per invoice and sum. Use calculator (do not do arithmetic in my head).
Action: calculator
Action Input: {"expr":"250000*0.18 + 180000*0.05 + 120000*0.18"}
Observation: 75600

Final Answer: Total GST = 45,000 + 9,000 + 21,600 = Rs 75,600.

(Check: 250000×0.18 = 45,000; 180000×0.05 = 9,000; 120000×0.18 = 21,600; sum = ₹75,600. Slabs 5%/18%/40% apply from 22 September 2025.)

DimensionFixed chain / workflowAgent (model-controlled loop)
Control flowWritten by the developerDecided by the model at run time
PredictabilityHigh, testableLow, needs tracing and evals
Cost per taskKnownVariable, needs a budget cap
Handles novel inputsPoorlyWell
DebuggingStack traceTrace of thoughts, calls, observations
Best forKnown, repeatable processesOpen-ended, branching tasks
PatternTool callsToken costAdapts to errors
Chain-of-ThoughtNoneLowNo
ReActInterleaved, one at a timeHighYes
ReWOO / plan-firstPlanned upfront, batchedLowerWeakly
ReflexionReAct + self-critique retriesHighestStrongly
RAG pipelineOne fixed retrievalLowestNo

Where it is used

Interview questions

Common mistakes

Related topics

Large language models and prompt engineering · Retrieval-augmented generation and vector databases · Text embeddings and semantic search · Natural language processing basics · Reinforcement learning and Markov decision processes · Search and planning algorithms in AI

Open in the Knowledge reader →Find jobs →