ai-agent-patterns
Design patterns for building autonomous AI agents that can reason, plan, and execute tasks.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
AI Agent Patterns
Overview
AI agents are autonomous systems that use Large Language Models (LLMs) to reason, plan, and execute tasks. Unlike simple chatbots, agents can break down complex problems into steps, use tools to interact with external systems, and adapt their behavior based on feedback. This skill covers agent architectures (ReAct, Plan-and-Execute, Tree of Thoughts, Reflexion), core components (memory, planning, tool use), frameworks (LangChain, AutoGPT, CrewAI, Semantic Kernel), tool design, multi-agent systems, error recovery, guardrails, evaluation, and production deployment.
Prerequisites
- Understanding of LLMs and their capabilities
- Knowledge of prompt engineering and system prompts
- Familiarity with function calling and tool APIs
- Understanding of agent architectures and design patterns
- Basic knowledge of vector databases and embeddings
- Understanding of safety and guardrails for AI systems
Key Concepts
Agent Characteristics
- Autonomy: Can make decisions without human intervention
- Reasoning: Can break down complex tasks into subtasks
- Planning: Can create and execute multi-step plans
- Tool Use: Can interact with external systems via function calling
- Memory: Can maintain context across interactions
- Adaptation: Can learn from feedback and adjust behavior
Simple vs Complex Agents
- Simple Agent: Single-step execution (e.g., weather query → result)
- Complex Agent: Multi-step planning (e.g., trip planning → search → book → confirm)
Agent Architectures
- ReAct: Reasoning + Acting in a loop
- Plan-and-Execute: Create plan first, then execute step by step
- Tree of Thoughts: Explore multiple reasoning paths before deciding
- Reflexion: Reflect on actions and learn from mistakes
Core Components
- Memory: Short-term (conversation history), Long-term (knowledge base), Episodic (specific experiences)
- Planning: Break down goals into actionable steps
- Tool Use: Register, validate, and execute tools safely
- Reflection: Analyze actions and improve behavior
Deployment Patterns
- FastAPI Server: REST API for agent inference
- Docker Deployment: Containerized agent service
- Kubernetes: Scalable deployment with GPU support
- Multi-Agent Systems: Agent collaboration and delegation
Implementation Guide
Agent Architectures
ReAct (Reasoning + Acting)
The ReAct pattern combines reasoning and acting in a loop.
from openai import OpenAI
class ReActAgent:
def __init__(self, llm_client, tools):
self.client = llm_client
self.tools = tools
self.max_iterations = 10
def run(self, query):
thoughts = []
for i in range(self.max_iterations):
# Thought: What should I do?
thought_response = self.client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": self.get_system_prompt()},
*thoughts,
{"role": "user", "content": query}
],
tools=self.tools
)
thought = thought_response.choices[0].message.content
thoughts.append({"role": "assistant", "content": thought})
# Check if agent wants to use a tool
if thought_response.choices[0].finish_reason == "function_calls":
fc = thought_response.choices[0].message.function_calls[0]
# Action: Execute tool
tool_result = self.execute_tool(fc.name, fc.arguments)
# Observation: What did I observe?
observation = f"Tool {fc.name} returned: {json.dumps(tool_result)}"
thoughts.append({"role": "assistant", "content": observation})
else:
# No more actions needed
break
return thoughts
def get_system_prompt(self):
return """You are a helpful assistant with access to tools.
Use the following format:
Thought: your thought about what to do
Action: action to take (tool call or final answer)
Observation: result of the action
... (repeat Thought/Action/Observation as needed)"""
def execute_tool(self, tool_name, arguments):
# Execute tool
for tool in self.tools:
if tool["name"] == tool_name:
handler = tool["handler"]
return handler(**arguments)
return None
# Usage
tools = [
{
"type": "function",
"function": {
"name": "search",
"description": "Search for information",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string"}
},
"re
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-26
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!