ai-agents-patternslisted
Install: claude install-skill Mattakushi432/Claude-Code-Skills-Custom-DevTools-Pack
# AI Agents Patterns
## ReAct Agent Loop (from scratch)
```python
from anthropic import Anthropic
client = Anthropic()
SYSTEM = """You are a helpful assistant with access to tools.
Use the following format:
Thought: reason about what to do
Action: tool_name
Action Input: input to the tool
Observation: result of the tool
... (repeat as needed)
Final Answer: your final response"""
def react_agent(question: str, tools: dict[str, callable], max_steps: int = 10) -> str:
messages = [{"role": "user", "content": question}]
for _ in range(max_steps):
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system=SYSTEM,
messages=messages,
stop_sequences=["Observation:"],
)
text = response.content[0].text
messages.append({"role": "assistant", "content": text})
if "Final Answer:" in text:
return text.split("Final Answer:")[-1].strip()
if "Action:" in text and "Action Input:" in text:
action = text.split("Action:")[1].split("\n")[0].strip()
action_input = text.split("Action Input:")[1].split("\n")[0].strip()
result = tools.get(action, lambda x: f"Unknown tool: {action}")(action_input)
messages.append({"role": "user", "content": f"Observation: {result}"})
return "Max steps reached"
```
## LangChain Tool Use
```python
from langchain_anthropic import ChatAnthropic
from langchain.agent