🤖
AI Development
AI Agent Development Notes
Core concepts behind AI agents, tools, memory, planning, and multi-agent systems.
Back to Notes Library
AI Agent Development Notes
What is an AI Agent?
An AI Agent is an LLM-powered system that can:
1. Reason about a goal
2. Plan a sequence of actions
3. Use tools to take actions (web search, code execution, APIs)
4. Observe results and adjust
5. Loop until the goal is achieved
text
Goal → Think → Act → Observe → Think → Act → ... → DoneCore Agent Components
1. LLM (The Brain)
- Decides what to do next
- Reasons about tool outputs
- Generates final responses
2. Tools
Functions the agent can call to interact with the world:
python
def search_web(query: str) -> str:
"""Search the internet for information"""
return results
def run_python(code: str) -> str:
"""Execute Python code and return output"""
return output3. Memory
| Type | Description | Example |
|---|---|---|
| Short-term | Current conversation context | Chat history |
| Long-term | Persistent storage | Vector database |
| Episodic | Past experiences | Previous tasks |
| Semantic | World knowledge | LLM weights |
4. Planning
- ReAct — Reason + Act interleaved
- Tree of Thoughts — Explore multiple reasoning paths
- Plan-and-Execute — Create full plan then execute
ReAct Pattern
text
Question: What is the population of Tokyo?
Thought: I need to search for the current population of Tokyo.
Action: search_web("Tokyo population 2024")
Observation: Tokyo's population is approximately 13.9 million.
Thought: I have the answer.
Answer: Tokyo's population is approximately 13.9 million people.LangChain Basics
python
from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor
from langchain_community.tools import DuckDuckGoSearchRun
from langchain import hub
# Setup
llm = ChatOpenAI(model="gpt-4o", temperature=0)
tools = [DuckDuckGoSearchRun()]
prompt = hub.pull("hwchase17/react")
# Create agent
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Run
result = agent_executor.invoke({"input": "What is the latest news about AI?"})Multi-Agent Systems
Multiple specialized agents collaborate:
text
User Request
↓
Orchestrator Agent
/ | \
Research Code Writer
Agent Agent Agent
\ | /
Final ResponseFrameworks
- LangGraph — Graph-based multi-agent workflows
- AutoGen — Microsoft's multi-agent framework
- CrewAI — Role-based multi-agent teams
- AgentVerse — Agent simulation platform
LangGraph Example
python
from langgraph.graph import StateGraph, END
from typing import TypedDict
class AgentState(TypedDict):
messages: list
next: str
def research_node(state: AgentState):
return {"messages": state["messages"] + ["research done"]}
def write_node(state: AgentState):
return {"messages": state["messages"] + ["writing done"]}
# Build graph
workflow = StateGraph(AgentState)
workflow.add_node("research", research_node)
workflow.add_node("write", write_node)
workflow.add_edge("research", "write")
workflow.add_edge("write", END)
workflow.set_entry_point("research")
app = workflow.compile()Tool Calling (OpenAI Format)
python
from openai import OpenAI
client = OpenAI()
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
}
}
]
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
tools=tools
)Agent Evaluation Metrics
| Metric | Description |
|---|---|
| Task Completion Rate | % of tasks successfully completed |
| Steps to Complete | Average actions needed |
| Hallucination Rate | % of false tool calls |
| Latency | Time to complete task |
| Cost | Token usage per task |
Best Practices
- Small, focused tools — one tool per action
- Clear tool descriptions — LLM relies on descriptions
- Add error handling — tools should return meaningful errors
- Limit max iterations — prevent infinite loops
- Log everything — debug agent behavior
- Use streaming — show progress to users
- Test with evals — automated test suites for agents
10K+ Members Growing Daily
Get Free AI Notes Daily
Join AiTechWorlds on Telegram and get daily AI tips, prompt engineering templates, coding resources, and exclusive content — 100% free!
📚 Free Study Notes🤖 AI Tips Daily⚡ Prompt Templates💻 Coding Resources
Join Free Channel
No spam. Leave anytime.