๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #439

AI Agents

An AI agent is a system built around a language model that can take actions โ€” not just generate text, but plan, use tools, and interact with external systems to accomplish a goal across multiple steps, rather than producing a single one-shot response.

What Distinguishes an Agent from a Plain LLM Call

Plain LLM CallAgent
One prompt in, one response outCan take multiple steps, observing results and deciding what to do next
Limited to what it can generate from its own knowledgeCan call external tools (search, calculators, APIs, code execution) to gather information or take real actions
No persistent goal-tracking across stepsMaintains and works toward a defined goal, potentially across many steps and tool calls

The Core Agent Loop

# A simplified conceptual agent loop
def run_agent(goal, tools, max_steps=10):
    history = [f"Goal: {goal}"]

    for step in range(max_steps):
        # 1. The LLM decides: respond directly, or call a tool?
        decision = llm.generate(prompt=build_prompt(history, tools))

        if decision.is_final_answer:
            return decision.answer

        # 2. Execute the chosen tool call
        tool_result = tools[decision.tool_name](**decision.tool_args)

        # 3. Observe the result and continue the loop
        history.append(f"Called {decision.tool_name}, got: {tool_result}")

    return "Max steps reached without a final answer"

This "reason, act, observe" cycle โ€” often called the ReAct pattern in the literature โ€” repeats until the agent determines it has enough information to produce a final answer, or reaches a step limit.

Why Agents Are Powerful, and Why They're Risky

Agents extend a language model's capability well beyond its fixed training knowledge โ€” they can look up current information, perform precise calculations a language model alone is unreliable at, and take real actions in external systems. But this power is exactly what makes agents riskier than a plain text-generation call: an agent that can execute code, make purchases, or send emails can cause real, potentially harmful consequences if it misinterprets its goal or a tool's output, which is why sandboxing, human approval checkpoints, and careful tool-permission scoping matter significantly more for agents than for simple text generation.

Common Agent Failure Modes

  • Looping โ€” repeatedly attempting the same failing action without recognizing it isn't working.
  • Goal drift โ€” gradually losing track of the original objective across many steps.
  • Tool misuse โ€” calling a tool with incorrect or nonsensical arguments, or misinterpreting a tool's output.
  • Unsafe actions โ€” taking a consequential, hard-to-reverse action (e.g. deleting data, sending a message) without appropriate safeguards or confirmation.

Common Mistakes

  • Granting an agent broad, unrestricted tool access without appropriate scoping or approval checkpoints for consequential actions โ€” this significantly amplifies the potential impact of any agent mistake or misinterpretation.
  • Not setting a maximum step limit โ€” an agent stuck in an unproductive loop can otherwise consume compute indefinitely without ever reaching a useful conclusion.

Interview Relevance

Q: "Why do AI agents introduce risks that a simple, single-turn LLM text generation call doesn't have?" A plain LLM call only produces text โ€” any harm from a mistake is limited to the text itself being wrong or unhelpful. An agent, by contrast, can take real actions through tool calls โ€” executing code, making API calls, modifying data, sending communications โ€” meaning a mistake (misinterpreting the goal, misusing a tool, looping unproductively) can cause real, sometimes hard-to-reverse consequences in external systems. This is why agents need additional safeguards โ€” sandboxed execution environments, human approval checkpoints for consequential actions, and carefully scoped tool permissions โ€” that a plain text-generation system doesn't require to the same degree.

Practice Question

Why is setting a maximum step limit an important safeguard for an AI agent, even when it appears to be "making progress" toward its goal?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

AI Agents โ€“ FAQs

Quick answers about learning AI Agents in Deep Learning.

This free note from CodingNow 2.0 explains AI Agents in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including AI Agents, is 100% free with no signup required.
With focused practice, most students grasp AI Agents in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now