Page9/10
Building with LangChain & Frameworks · Page 1 of 1
Agent Frameworks & Tools
Building Agents with Frameworks
Why Use Frameworks?
Building agents from scratch is complex. Frameworks provide:
- Pre-built patterns (ReAct, CoT)
- Tool integration
- Memory management
- Orchestration logic
LangChain
Popular Python framework for building LLM applications.
Components:
1. LLM (OpenAI, Anthropic, etc.)
2. Tools (functions agent can use)
3. Agent executor (orchestration)
4. Memory (conversation history)
5. Chains (sequences of steps)
Example:
from langchain.agents import initialize_agent
from langchain.llms import OpenAI
llm = OpenAI(api_key="...")
tools = [SearchTool(), Calculator(), Python]
agent = initialize_agent(
llm=llm,
tools=tools,
agent_type="ReAct",
memory=ConversationMemory()
)
result = agent.run("What's 2^10 + sqrt(16)?")
# Output: 1028 (computed by agent)
AutoGPT Pattern
Autonomous agent that:
- Sets goals
- Breaks into tasks
- Executes tasks
- Reviews progress
- Iterates
Loop:
Agent thinks: "Goal: Write essay"
→ Task 1: Research (execute)
→ Task 2: Outline (execute)
→ Task 3: Write (execute)
→ Review: Essay complete?
→ If not done: Create new task
→ If done: Return result
OpenAI Function Calling
Modern approach: Function calling in LLM API.
Define tools:
{
"name": "search",
"description": "Search the web"
}
LLM decides to use tool:
{
"function_name": "search",
"arguments": {"query": "..."}
}
System executes and returns result
Comparison: Frameworks
| Framework | Best For | Language |
|---|---|---|
| LangChain | Flexible agents, chains | Python |
| AutoGPT | Autonomous workflows | Python |
| Semantic Kernel | Microsoft integration | C#, Python |
| Crew AI | Multi-agent systems | Python |
Choosing a Framework
Choose LangChain if:
- Need flexibility
- Building production system
- Python preferred
Choose AutoGPT if:
- Want fully autonomous behavior
- Don't need customization
Choose built-in APIs if:
- Simple use case
- No external dependencies
main.py
Loading...
OUTPUT
▶Click "Run Code" to execute…