What is an AI Agent?
LLM + tools + loop: the model plans, acts, observes, and repeats until the task is done.
① What you must know (30 sec)
② How it works
③ 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
| Pattern | Description | Best for |
|---|---|---|
| ReAct | Reason then act with tools | General-purpose agents |
| Plan-and-execute | Plan all steps upfront, then run | Predictable multi-step workflows |
| Router | Classify intent → specialized sub-agent | Multi-domain assistants |
| Human-in-the-loop | Pause for approval on risky actions | Finance, 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
| Pitfall | Why it hurts | Fix |
|---|---|---|
| Unbounded loops | Runaway cost and latency | max_steps, timeout, token budget per run |
| Arbitrary code execution | RCE, data exfiltration | Sandbox, allowlist commands, no shell by default |
| Tool description ambiguity | Wrong tool chosen repeatedly | Clear names, examples, negative cases in schema |
| No argument validation | SQL injection, bad API calls | Schema validation before execution |
| Agent for simple FAQ | 10× cost vs one RAG call | Use single LLM call when no tools needed |
| Opaque failures | Cannot debug bad runs | Structured traces per step with inputs/outputs |
- 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
| Question | Answer |
|---|---|
| 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
⑧ 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