AI

What is an AI Agent?

LLM + tools + loop: the model plans, acts, observes, and repeats until the task is done.

Interview tip Contrast: chatbot = one-shot. Agent = multi-step with tools (search, code run, API calls). Mention human-in-the-loop for risky actions.

① What you must know (30 sec)

An AI agent is an LLM that runs in a loop: it receives a goal, decides the next action (often a tool call), executes it, observes the result, and repeats until it produces a final answer or hits a limit. Unlike a one-shot chatbot, agents can search the web, query databases, run code, and call APIs — with variable cost and risk.
Analogy: A chatbot is a consultant who answers from memory; an agent is an intern with a laptop who can look things up, send emails, and run spreadsheets until the task is done.

② How it works

Agent loop
User goalLLM plans actionTool executesObservationFinal answer or repeat
1. User goal — natural language task with success criteria
2. LLM planner — chooses tool + arguments or returns final answer
3. Tool runtime — validates args, executes allowlisted function
4. Observation — tool output appended to conversation history
5. Termination — final answer, max_steps, timeout, or human approval
ReAct (Reason + Act) is the most common pattern: the model explicitly reasons before each tool call.

③ Step-by-step (hands-on)

Step 1 — Define the goal and success criteria

"Summarize open Jira tickets for team X and post to Slack" — clear done state prevents infinite loops.

Step 2 — Inventory tools

List capabilities the LLM cannot do alone: search, SQL, calendar, send_message. One tool = one well-documented function with JSON schema.

Step 3 — Write planner prompt

Explain available tools, output format (JSON action or final answer), and rules: "Never guess account IDs; use lookup tool."

Step 4 — Implement the loop

Call LLM → parse tool call → execute → append result → repeat. Cap at 5–15 steps and 2–5 minute timeout.

Step 5 — Add guardrails

Allowlist tools, validate parameters, require approval for writes, sandbox code execution, audit log every action.

Step 6 — Observe and evaluate

Trace each step (LangSmith, OpenTelemetry). Measure task success rate and cost per run on a test suite.

④ Code / config patterns

PatternDescriptionBest for
ReActReason then act with toolsGeneral-purpose agents
Plan-and-executePlan all steps upfront, then runPredictable multi-step workflows
RouterClassify intent → specialized sub-agentMulti-domain assistants
Human-in-the-loopPause for approval on risky actionsFinance, healthcare, prod changes
while not done and steps < MAX_STEPS:
    response = llm(messages, tools=tool_definitions)
    if response.finish_reason == "final":
        return response.text
    args = validate(response.tool_call)
    result = TOOL_REGISTRY[response.tool_name](**args)
    messages.append({"role": "tool", "content": result})
    steps += 1
raise TimeoutError("Agent exceeded step limit")

⑤ Production & pitfalls

PitfallWhy it hurtsFix
Unbounded loopsRunaway cost and latencymax_steps, timeout, token budget per run
Arbitrary code executionRCE, data exfiltrationSandbox, allowlist commands, no shell by default
Tool description ambiguityWrong tool chosen repeatedlyClear names, examples, negative cases in schema
No argument validationSQL injection, bad API callsSchema validation before execution
Agent for simple FAQ10× cost vs one RAG callUse single LLM call when no tools needed
Opaque failuresCannot debug bad runsStructured traces per step with inputs/outputs
Production tips:
  • Separate read-only and write tools; gate writes behind approval
  • Idempotent tools where possible so retries are safe
  • Per-tenant tool permissions and data isolation
  • Kill switch to disable agent features without full outage

⑥ Interview / on-the-job Q&A

QuestionAnswer
Agent vs chatbot?Chatbot: one LLM call, no side effects. Agent: multi-step loop with tool execution.
What is a tool?A function the LLM can invoke — search, SQL, API — described by name, description, and JSON schema.
What is max_steps?Hard cap on loop iterations to prevent runaway cost and infinite retries.
When not to use agents?Simple Q&A, single retrieval, or deterministic workflows better handled by code.
What is human-in-the-loop?Pause before irreversible actions (send email, charge card) for human approval.
How debug agents?Step-by-step traces: prompt, tool chosen, args, result, and final answer per run.

⑦ Tools & ecosystem

  • Frameworks: LangGraph, CrewAI, OpenAI Assistants, Anthropic tool use
  • Tracing: LangSmith, Arize, Weights & Biases
  • Sandbox: E2B, Docker, Modal for code execution
  • Protocols: MCP for standardized tool connections
agentstoolsreactguardrailstracing

⑧ Revision checklist

  • Clear success criteria defined before building loop
  • Tools have JSON schemas with descriptions and examples
  • max_steps and timeout configured
  • Write/destructive tools require approval
  • All tool calls audit-logged with user and timestamp
  • Argument validation before execution
  • Traces captured for every run
  • Eval suite of 10+ multi-step tasks
  • Cost per successful task measured and acceptable