A minimal implementation of an agentic AI assistant. Made as simple as possible for educational purposes.
Read the accompanying blog post at https://samdobson.uk/posts/how-to-build-an-agent/
MiniAgent is an interactive command-line agent that can list, read and edit files, using Claude Haiku as the model.
The agent maintains conversation context across multiple turns and automatically executes tool calls as needed to fulfil user requests.
This implementation demonstrates the core concepts of building an AI agent:
- Conversation Management - Maintaining multi-turn dialogue with tool results
- Agentic Loop - The request ’ inference ’ tool execution ’ response cycle
- Tool Use Pattern - How to define tools with schemas and connect them to Python functions
Agentclass - Orchestrates the conversation loop and tool execution- Tool definitions (
READ_FILE_TOOL,LIST_FILES_TOOL,EDIT_FILE_TOOL) - Define capabilities available to the model _run_inference()- Makes API calls to the LLM with tool schemas_execute_tool()- Routes tool calls to their Python implementations
pip install anthropic
python agent.pyRemeber to set the ANTHROPIC_API_KEY environment variable before running.