home / skills / doanchienthangdev / omgkit / ai-agents
This skill helps you build autonomous AI agents with tool use and planning strategies to automate multi-step workflows.
npx playbooks add skill doanchienthangdev/omgkit --skill ai-agentsReview the files below or copy the command above to add this skill to your agents.
---
name: ai-agents
description: Building AI agents - tool use, planning strategies (ReAct, Plan-and-Execute), memory systems, agent evaluation. Use when building autonomous AI systems, tool-augmented apps, or multi-step workflows.
---
# AI Agents
Building AI agents with tools and planning.
## Agent Architecture
```
┌─────────────────────────────────────┐
│ AI AGENT │
├─────────────────────────────────────┤
│ ┌──────────┐ │
│ │ BRAIN │ (Foundation Model) │
│ │ Planning │ │
│ │ Reasoning│ │
│ └────┬─────┘ │
│ │ │
│ ┌───┴───┐ │
│ ↓ ↓ │
│ ┌─────┐ ┌──────┐ │
│ │TOOLS│ │MEMORY│ │
│ └─────┘ └──────┘ │
└─────────────────────────────────────┘
```
## Tool Definition
```python
tools = [{
"type": "function",
"function": {
"name": "search_database",
"description": "Search products by query",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string"},
"category": {"type": "string", "enum": ["electronics", "clothing"]},
"max_price": {"type": "number"}
},
"required": ["query"]
}
}
}]
```
## Planning Strategies
### ReAct (Reasoning + Acting)
```python
REACT_PROMPT = """Tools: {tools}
Format:
Thought: [reasoning]
Action: [tool_name]
Action Input: [JSON]
Observation: [result]
... repeat ...
Final Answer: [answer]
Question: {question}
Thought:"""
def react_agent(question, tools, max_steps=10):
prompt = REACT_PROMPT.format(...)
for _ in range(max_steps):
response = llm.generate(prompt)
if "Final Answer:" in response:
return extract_answer(response)
action, input = parse_action(response)
observation = execute(tools[action], input)
prompt += f"\nObservation: {observation}\nThought:"
```
### Plan-and-Execute
```python
def plan_and_execute(task, tools):
# Step 1: Create plan
plan = llm.generate(f"Create step-by-step plan for: {task}")
steps = parse_plan(plan)
# Step 2: Execute each step
results = []
for step in steps:
result = execute_step(step, tools)
results.append(result)
# Step 3: Synthesize
return synthesize(task, results)
```
### Reflexion (Self-Reflection)
```python
def reflexion_agent(task, max_attempts=3):
memory = []
for attempt in range(max_attempts):
solution = generate(task, memory)
success, feedback = evaluate(solution)
if success:
return solution
reflection = reflect(task, solution, feedback)
memory.append({"solution": solution, "reflection": reflection})
```
## Memory Systems
```python
class AgentMemory:
def __init__(self):
self.short_term = [] # Recent turns
self.long_term = VectorDB() # Persistent
def add(self, message):
self.short_term.append(message)
if len(self.short_term) > 20:
self.consolidate()
def consolidate(self):
summary = summarize(self.short_term[:10])
self.long_term.add(summary)
self.short_term = self.short_term[10:]
def retrieve(self, query, k=5):
return {
"recent": self.short_term[-5:],
"relevant": self.long_term.search(query, k),
}
```
## Agent Evaluation
```python
def evaluate_agent(agent, test_cases):
return {
"task_success": mean([agent.run(c["task"]) == c["expected"] for c in test_cases]),
"avg_steps": mean([agent.step_count for _ in test_cases]),
"avg_latency": mean([measure_time(agent.run, c["task"]) for c in test_cases]),
}
```
## Best Practices
1. Start with simple tools, add complexity gradually
2. Add reflection for complex tasks
3. Limit max steps to prevent infinite loops
4. Log all agent actions for debugging
5. Use evaluation to measure progress
This skill provides practical patterns and code-style recipes for building AI agents that use tools, planning strategies, memory, and evaluation. It focuses on orchestrating a foundation model (the agent 'brain') with external tools and memory stores to solve multi-step or tool-augmented tasks. The content is language-agnostic conceptually and includes concrete JavaScript-friendly structures and algorithms.
The skill outlines an agent architecture where a central model performs planning and reasoning while calling tools and consulting memory. It covers three planning strategies—ReAct (interleaved reasoning and tool use), Plan-and-Execute (explicit plan then step execution), and Reflexion (iterative self-reflection and improvement). It also describes a two-tier memory: short-term turn buffer and long-term vector store with consolidation, plus basic evaluation metrics for automated testing.
How do I choose between ReAct and Plan-and-Execute?
Use ReAct when the task needs flexible interleaving of reasoning and tool use or when tools provide critical evidence; use Plan-and-Execute when tasks can be decomposed into clear steps and you want deterministic step execution.
How should memory consolidation be tuned?
Consolidate when short-term buffers reach a modest size (example: 20 turns). Summarize the most important turns into embeddings for long-term retrieval and tune k (retrieval size) based on task complexity and latency constraints.