Learning project: Building AI agents from scratch without frameworks
A Python implementation of the ReAct (Reasoning + Acting) pattern for AI agents using Claude API. Built to understand agent fundamentals before using frameworks like LangChain.
- ✅ ReAct loop with tool calling
- ✅ Modular tool system (auto-discovery)
- ✅ Unit tests (no token usage)
- ✅ Integration tests (optional)
- ✅ Loop protection (max iterations)
# Setup
uv venv
source .venv/bin/activate
uv sync
# Configure
cp .env.example .env
# Add your ANTHROPIC_API_KEY to .env
# Run
python main.py
# Test (no tokens)
pytest test_tools.py -v
# Integration tests (uses tokens)
pytest -m integration -vCreate tools/your_tool.py:
"""Your tool description"""
TOOL_DEFINITION = {
"name": "your_tool",
"description": "What it does",
"input_schema": {
"type": "object",
"properties": {
"param": {"type": "string", "description": "..."}
},
"required": ["param"]
}
}
def execute(tool_input: dict) -> str:
"""Execute the tool"""
return "result"That's it! Auto-discovered on next run.
{
"name": "calculator",
"input_schema": { ... } # JSON Schema
}{
"type": "function",
"function": {
"name": "calculator",
"parameters": { ... } # JSON Schema
}
}Note: Internal schema (properties, required) is standard JSON Schema for both.
- Understand ReAct pattern internals
- Build agents without framework magic
- Create production-ready code
- System prompts
- Streaming responses
- Persistent memory
MIT