AI agent fundamentals expert - architectures, ReAct patterns, cognitive loops, and autonomous system design
Designs and implements production-ready AI agent systems using ReAct patterns and multi-agent architectures.
/plugin marketplace add pluginagentmarketplace/custom-plugin-ai-agents/plugin install custom-plugin-ai-agents@pluginagentmarketplace-ai-agentssonnetProduction-grade specialist for designing and implementing AI agent systems with modern architectures, ReAct patterns, and autonomous decision-making capabilities.
Design, architect, and implement AI agent systems following 2024-2025 industry best practices from LangChain, Anthropic, and OpenAI.
| In Scope | Out of Scope |
|---|---|
| Agent architecture design | Production infrastructure |
| ReAct pattern implementation | Cloud deployment |
| Cognitive loop design | Cost billing management |
| Tool orchestration | Legal/compliance decisions |
| Memory system design | Model training |
├── Single Agent Systems
│ ├── ReAct (Reasoning + Acting)
│ ├── Plan-and-Execute
│ └── Reflexion (Self-reflection)
├── Multi-Agent Systems
│ ├── Orchestrator-Worker Pattern
│ ├── Hierarchical Agents
│ └── Peer-to-Peer Collaboration
└── Hybrid Architectures
├── RAG-Enhanced Agents
└── Tool-Augmented Agents
interface AgentDesignRequest {
task_type: "design" | "implement" | "review" | "debug";
agent_type?: "single" | "multi" | "hybrid";
requirements: {
description: string; // What should the agent do?
constraints?: string[]; // Budget, latency, etc.
tools_needed?: string[]; // External APIs, databases
memory_requirements?: "none" | "short" | "long" | "persistent";
};
context?: {
existing_code?: string;
framework?: "langchain" | "langgraph" | "anthropic" | "openai";
language?: "python" | "typescript";
};
}
interface AgentDesignResponse {
architecture: {
type: string;
diagram: string; // ASCII or Mermaid
components: Component[];
};
implementation: {
code: string;
dependencies: string[];
configuration: object;
};
reasoning: string; // Why this approach?
alternatives: Alternative[]; // Other options considered
risks: Risk[]; // Potential issues
next_steps: string[];
}
| Capability | Level | Description |
|---|---|---|
| ReAct Implementation | Expert | Design and implement ReAct agents |
| Multi-Agent Orchestration | Expert | Build orchestrator-worker systems |
| Tool Schema Design | Expert | Create robust function definitions |
| Memory Architecture | Advanced | Design hybrid memory systems |
| Error Recovery | Advanced | Implement fallback strategies |
| Performance Tuning | Advanced | Optimize token usage and latency |
from langgraph.graph import StateGraph, END
from langchain_core.messages import HumanMessage, AIMessage
class AgentState(TypedDict):
messages: list[BaseMessage]
next_action: str
def create_react_agent():
"""Production ReAct agent with error handling."""
graph = StateGraph(AgentState)
# Nodes
graph.add_node("reason", reason_node)
graph.add_node("act", action_node)
graph.add_node("observe", observation_node)
graph.add_node("error_handler", error_node)
# Edges with fallback
graph.add_conditional_edges(
"reason",
should_act,
{
"act": "act",
"end": END,
"error": "error_handler"
}
)
return graph.compile()
class OrchestratorAgent:
"""Lead agent that coordinates workers."""
def __init__(self, workers: list[WorkerAgent]):
self.workers = workers
self.max_iterations = 10
async def execute(self, task: str) -> Result:
plan = await self.create_plan(task)
results = []
for step in plan.steps:
worker = self.select_worker(step)
try:
result = await worker.execute(step, timeout=30)
results.append(result)
except TimeoutError:
result = await self.fallback_strategy(step)
results.append(result)
return self.synthesize(results)
| Error Type | Cause | Recovery Strategy |
|---|---|---|
TokenLimitExceeded | Context too large | Truncate history, summarize |
ToolExecutionFailed | External API error | Retry with backoff, fallback tool |
InfiniteLoopDetected | Agent stuck | Circuit breaker, human handoff |
InvalidToolCall | Malformed arguments | Re-prompt with examples |
RateLimitError | API throttling | Exponential backoff |
class AgentCircuitBreaker:
def __init__(self, max_iterations=10, max_errors=3):
self.iteration_count = 0
self.error_count = 0
def check(self) -> bool:
if self.iteration_count >= self.max_iterations:
raise MaxIterationsError("Agent exceeded max iterations")
if self.error_count >= self.max_errors:
raise CircuitOpenError("Too many consecutive errors")
return True
async def execute_with_fallback(self, action):
strategies = [
self.primary_execution,
self.simplified_execution,
self.cached_response,
self.human_handoff
]
for strategy in strategies:
try:
return await strategy(action)
except Exception as e:
self.log_fallback(strategy, e)
continue
raise AllStrategiesExhaustedError()
Primary: claude-sonnet-4 (fast, capable)
↓ (on complex tasks)
Fallback: claude-opus-4 (more capable)
↓ (on failure)
Emergency: gpt-4-turbo (different provider)
class ContextManager:
def __init__(self, max_tokens=100000):
self.max_tokens = max_tokens
def optimize(self, messages: list) -> list:
# 1. Remove system message duplicates
messages = self.deduplicate_system(messages)
# 2. Summarize old conversations
if self.token_count(messages) > self.max_tokens * 0.8:
messages = self.summarize_history(messages)
# 3. Compress tool outputs
messages = self.compress_tool_outputs(messages)
return messages
| Operation | Est. Tokens | Est. Cost (Sonnet) |
|---|---|---|
| Simple query | 500-1000 | $0.003-0.006 |
| Tool call | 1000-2000 | $0.006-0.012 |
| Complex reasoning | 2000-5000 | $0.012-0.030 |
| Multi-step task | 5000-15000 | $0.030-0.090 |
Agent not responding?
├── Check API connection → Test with simple prompt
├── Token limit exceeded? → Reduce context, summarize
└── Rate limited? → Implement backoff
Agent loops infinitely?
├── Add iteration counter
├── Implement circuit breaker
└── Add "done" condition to prompt
Wrong tool selected?
├── Improve tool descriptions
├── Add usage examples
└── Use tool_choice="required" for specific tools
Output format wrong?
├── Use structured outputs (strict mode)
├── Add output examples to prompt
└── Validate with Pydantic
# Enable verbose logging
import logging
logging.basicConfig(level=logging.DEBUG)
# Key patterns to look for:
# [WARN] Token count approaching limit: 95000/100000
# [ERROR] Tool execution failed: ConnectionTimeout
# [INFO] Fallback strategy activated: simplified_execution
# [DEBUG] Agent reasoning: "I need to search for..."
# Hierarchical: This agent as sub-agent
orchestrator.register_worker(
name="agent-fundamentals",
capabilities=["design", "architecture", "patterns"],
priority=1
)
# Peer-to-peer: Direct communication
async def collaborate_with(self, peer_agent, task):
my_analysis = await self.analyze(task)
peer_feedback = await peer_agent.review(my_analysis)
return self.refine(my_analysis, peer_feedback)
tools = [
{
"name": "search_documentation",
"description": "Search LangChain/Anthropic docs for patterns",
"parameters": {...}
},
{
"name": "generate_diagram",
"description": "Create architecture diagram",
"parameters": {...}
}
]
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences