Module 10 Lesson 1: Agent Fundamentals
The Autonomous Mind. Understanding the difference between a static Chain and a dynamic Agent that makes its own decisions.
Agent Fundamentals: Chains vs. Agents
Up until now, you have built Chains. A chain has a fixed path: Input -> Prompt -> Model -> Output. Even if you have 10 steps, the path is hardcoded by you, the developer.
An Agent is different. An agent uses an LLM as a Reasoning Engine to determine which steps to take and in what order.
1. The Decision Loop
- Observe: Look at the user's query and the tools available.
- Think: "To solve this, I first need to search the web, then calculate the total."
- Act: Call the tool.
- Observe: Look at the tool's output.
- Repeat: Keep going until the problem is solved.
2. When to use an Agent
- Chain: "Translate this text to French." (Always the same step).
- Agent: "Research the top 3 AI trends of 2024 and email me a summary." (Needs dynamic steps: Search $\rightarrow$ Read $\rightarrow$ Summarize $\rightarrow$ Send).
3. Visualizing the Control Loop
graph TD
User[Query] --> LLM[Reasoning Engine]
LLM -->|Think| Decision{Wait, do I need a tool?}
Decision -->|Yes| T[Tool Call]
T --> result[Tool Result]
result --> LLM
Decision -->|No| Answer[Final Response]
4. The ReAct Pattern
Most LangChain agents follow the ReAct (Reason + Act) pattern.
- Thought: "I need to find the capital of France. I will use the search tool."
- Action:
search("capital of France") - Observation: "Paris"
- Thought: "I have the answer. I will respond to the user."
5. Engineering Tip: Latency vs. Flexibility
Agents are "Slower" than chains because they usually require Recursive calls to the LLM. Every "Step" adds 1-2 seconds of waiting. Only use an agent if the path to the answer truly cannot be predicted.
Key Takeaways
- Agents use LLMs to dynamically choose their own path.
- Chains are deterministic; Agents are autonomous.
- The ReAct loop is the standard reasoning framework.
- Use Agents for Open-ended tasks where the steps aren't known in advance.