Back to Tracker
Phase 3 — Applied AI
AI Agents
Agents are LLMs that take actions in the world — using tools, managing memory, and orchestrating multi-step tasks. The architecture powering GPT-4o, Claude, Gemini products.
Agent ArchitectureTool Use
Memory SystemsMulti-Agent
LangChain / LangGraphReliability
What Makes Something an "Agent"?
FOUNDATION
An LLM is a text predictor. An agent is an LLM that perceives its environment, decides what action to take, executes that action, and uses the result to decide the next action — in a loop.
The Agent Loop
while not done:
observation = perceive(environment)
thought = llm.think(observation, memory)
action = llm.decide(thought, tools)
result = execute(action)
memory.update(result)
if action == "finish":
break
4 Core Components
LLM BrainReasoning, planning, decision-making
ToolsAPIs, search, code execution, DB access
MemoryShort-term (context), long-term (vector DB)
PlannerOrchestrates multi-step task decomposition
Key insight: A chatbot answers questions. An agent takes actions. The moment an LLM can call a function, write a file, or trigger an API — it's an agent.
Agent Memory Systems
HIGH YIELD
In-Context Memory (Short-Term)
The conversation history currently in the context window. Limited to the model's context limit (4K–200K tokens). Cheap and fast.
Problem: Gets truncated on long tasks. Solution: summarization or sliding window.
External Memory (Long-Term)
Vector database storing past interactions, facts, or user preferences. Agent queries it each turn via semantic search.
memory.store(user_id, event="User prefers Python")
relevant = memory.retrieve(user_id, query, top_k=3)
# inject into system prompt
Episodic Memory
Stored records of past task executions. Agent can recall "last time I did X, I did Y, and it worked." Implemented as structured logs in a DB.
Semantic Memory
General knowledge about the world/domain stored as embeddings. This is what RAG retrieves from. Not user-specific.
Working Memory (Scratchpad)
Intermediate results during task execution. Often a structured dict the agent writes to and reads from between steps.
Tool Use — How Agents Interact with the World
Tools are functions the LLM can invoke. The LLM outputs a structured tool call; your code executes it and feeds the result back.
Common Tool Categories
| Category | Examples | Use Case |
| Search | Google Search API, Bing, Tavily | Real-time information retrieval |
| Code Execution | Python REPL, Jupyter kernel | Math, data analysis, file manipulation |
| Database | SQL queries, Firestore, Redis | Persistent data read/write |
| APIs | Stripe, Slack, GitHub, Calendar | Business actions in external systems |
| File System | Read/write/delete files | Document processing, code generation |
| Other LLMs | Specialist subagents | Delegation in multi-agent systems |
# Tool definition (OpenAI format)
tools = [
{
"type": "function",
"function": {
"name": "search_web",
"description": "Search the web for recent information",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"},
"num_results": {"type": "integer", "default": 5}
},
"required": ["query"]
}
}
}
]
# Agent loop
response = llm.chat(messages, tools=tools)
if response.tool_calls:
for call in response.tool_calls:
result = execute_tool(call.name, call.arguments)
messages.append({"role": "tool", "content": result})
Security: Never give an agent tools it doesn't need for the current task (principle of least privilege). A bug that causes the agent to call delete_database() is catastrophic.
Multi-Agent Architectures
Complex tasks are broken down across specialized agents. An orchestrator agent delegates to subagents with specific skills.
Orchestrator–Worker Pattern
Orchestrator
├── Plan: [Step 1, Step 2, Step 3]
├── → ResearchAgent.run(step1)
├── → CodeAgent.run(step2)
└── → ReviewAgent.run(step3)
→ synthesize(results) → final answer
Each subagent is an LLM with its own system prompt, tools, and memory. Orchestrator does not execute — only delegates.
Patterns Comparison
| Pattern | Best For |
| Single agent | Simple tasks, low cost |
| Orchestrator + workers | Parallel sub-tasks |
| Pipeline (sequential) | ETL, multi-step transforms |
| Debate (multiple agents) | High-stakes decisions |
| Hierarchical | Very complex, long-horizon tasks |
Interview Q: "Design an AI agent that can research a topic and write a blog post." — Answer: Orchestrator decomposes task → ResearchAgent (web search tool) finds sources → WriterAgent (no tools) generates draft given sources → EditorAgent reviews for quality → return final post. Each agent has a focused system prompt and only the tools it needs.
LangChain & LangGraph — Frameworks to Know
LangChain Concepts
ChainSequential steps: prompt → LLM → output parser
AgentLLM decides which tool to call each step
ToolPython function with description for the LLM
MemoryConversationBuffer / VectorStoreRetriever
LCELLangChain Expression Language — pipe-based chains
LangGraph — Stateful Agents
LangGraph models the agent as a directed graph where nodes are LLM calls or functions, and edges are transitions based on output.
graph = StateGraph(AgentState)
graph.add_node("think", agent_think)
graph.add_node("act", call_tool)
graph.add_edge("think", "act")
graph.add_conditional_edges(
"act",
should_continue,
{"continue": "think", "end": END}
)
Use LangGraph when you need cycles (retry logic, self-correction) or complex conditional branching.
Agent Reliability & Failure Modes
| Failure Mode | Cause | Fix |
| Infinite loop | Agent keeps calling tools without finishing | Max step limit + timeout |
| Tool hallucination | Agent calls a non-existent tool or wrong args | Strict JSON schema validation |
| Context overflow | Long task exhausts context window | Summarize history periodically |
| Task drift | Agent deviates from original goal | Re-inject goal in every prompt |
| Compounding errors | Error in step 2 corrupts all downstream steps | Checkpoint + human-in-the-loop at key steps |
| Prompt injection | Malicious tool output hijacks agent | Output validation layer before execution |
Production rule: Agents are not reliable enough for fully autonomous production use in high-stakes domains. Always add: step limits, output validation, human approval gates for irreversible actions (send email, charge card, delete data).
Interview Q: "How do you evaluate whether an AI agent is working correctly?" — Answer: (1) Task completion rate on a golden test set. (2) Tool call accuracy (did it call the right tool with right args?). (3) Step efficiency (fewer steps = better). (4) Human preference ratings on final output. Use tracing tools like LangSmith or Arize to log every agent step.