🤖 Agentic AI Cheat Sheet
Complete guide to AI agents, frameworks, patterns, and implementation strategies
Definition
Key Characteristics
• Reasoning: Makes logical decisions
• Goal-oriented: Works toward objectives
• Adaptive: Learns from interactions
• Tool usage: Leverages external resources
vs Traditional AI
Agentic AI: Plans sequences of actions, uses tools, and adapts strategies to accomplish complex, multi-step tasks autonomously.
Agent Architecture
- Perception: Process inputs from environment
- Planning: Develop strategies to reach goals
- Action: Execute decisions and use tools
- Memory: Store and recall past experiences
- Reflection: Learn from outcomes
Tool Integration
• Web search and browsing
• Code execution environments
• Database queries
• File system operations
• API calls to external services
• Mathematical calculators
Reasoning Patterns
• Tree-of-Thoughts: Multiple reasoning paths
• ReAct: Reasoning + Acting interleaved
• Plan-and-Execute: Strategic planning first
• Self-Reflection: Critique own outputs
LangChain
from langchain.llms import OpenAI
# Define tools
tools = [Tool(name=”Calculator”, func=calculator)]
# Create agent
agent = initialize_agent(tools, OpenAI(),
agent=”zero-shot-react-description”)
LlamaIndex
from llama_index.tools import QueryEngineTool
# Create query tool
query_tool = QueryEngineTool.from_defaults(
query_engine, name=”documents”
)
agent = OpenAIAgent.from_tools([query_tool])
AutoGPT
1. Set high-level goal
2. Agent breaks into sub-tasks
3. Executes tasks using tools
4. Self-evaluates progress
5. Adjusts strategy as needed
ReAct Pattern
Action: search_web(“weather Paris today”)
Observation: Current weather is 22°C, sunny
Thought: Now I have the information requested
Action: respond(“Weather in Paris: 22°C, sunny”)
Multi-Agent System
• Planner Agent: Creates strategies
• Executor Agent: Performs actions
• Critic Agent: Evaluates results
• Coordinator: Manages communication
Chain-of-Thought
Step 1: Convert percentage to decimal (15% = 0.15)
Step 2: Multiply: $47.50 × 0.15 = $7.125
Step 3: Round to nearest cent: $7.13
Answer: The tip should be $7.13
GPT-4, function calling, assistants API for agent development
Open-source models, transformers library, agent toolkits
Constitutional AI, tool use, long context windows
Command models, retrieval-augmented generation
LLM application debugging, monitoring, and evaluation
ML experiment tracking, agent performance monitoring
Business Automation
• Document processing and analysis
• Email management and responses
• Data entry and validation
• Report generation and insights
Developer Assistance
• API documentation creation
• Test case generation
• Code review and optimization
• Architecture recommendations
Research & Analysis
• Data analysis and visualization
• Market research automation
• Scientific hypothesis generation
• Competitive intelligence gathering
Agent Design
• Implement proper error handling
• Add human oversight for critical decisions
• Design for observability and debugging
• Start simple, iterate and improve
Safety & Security
• Implement rate limiting and timeouts
• Use sandboxed execution environments
• Monitor for malicious behavior
• Regular security audits and testing
Performance
• Optimize tool selection strategies
• Monitor token usage and costs
• Implement proper retry mechanisms
• Profile and optimize critical paths
Simple LangChain Agent
from langchain.tools import DuckDuckGoSearchRun, Tool
from langchain_openai import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
# Initialize LLM
llm = ChatOpenAI(model=”gpt-4″, temperature=0)
# Create tools
search = DuckDuckGoSearchRun()
tools = [
Tool(
name=”web_search”,
description=”Search the web for current information”,
func=search.run
)
]
# Create prompt template
prompt = ChatPromptTemplate.from_messages([
(“system”, “You are a helpful AI assistant with web search capabilities.”),
(“human”, “{input}”),
(“placeholder”, “{agent_scratchpad}”)
])
# Create and run agent
agent = create_openai_tools_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
# Use the agent
result = agent_executor.invoke({
“input”: “What’s the latest news about AI agents?”
})
print(result[“output”])