Blog logo

Blog

Free

Build LLM-controlled agents from scratch with a minimal, open-source library

FreeFree tier
Inputs: textOutputs: text
Type
Open Source

About Blog

This blog post presents a small, open-source library for building intelligent agents guided by large language models (LLMs), heavily inspired by LangChain. The library implements a simple agent loop of Thought, Action, and Observation, where the LLM generates thoughts and actions, and tools (e.g., Python REPL, Google Search, Hacker News search) provide observations. The post includes the exact prompt template, tool interface code, and the core agent loop, all designed for educational clarity in under 100 lines of code. The goal is to help developers understand the fundamentals of LLM-controlled agents without the abstraction layers of larger frameworks.

Key Features

Simple agent loop: Thought → Action → Observation → Thought
Customizable tools: Python REPL, Google Search, Hacker News search
Clear prompt template with date, tool descriptions, and previous responses
Minimal Python codebase (under 100 lines) for easy understanding
Open-source on GitHub with full code and examples

Pros & Cons

Pros
  • Extremely lightweight and easy to understand – perfect for learning
  • Open-source with full code available on GitHub
  • Inspired by LangChain but removes abstraction complexity
  • Includes practical tools like Google Search and Python REPL
  • Well-documented blog post with prompt template and loop logic
Cons
  • Not production-ready – lacks error handling, scaling, and advanced features
  • Limited to a small set of built-in tools (only 3 shown)
  • Basic agent loop may not handle complex multi-step reasoning well
  • No built-in memory management beyond the prompt history

Best For

Learning how LLM-controlled agents work internallyEducational projects to understand agent loops and tool useRapid prototyping of simple tool-using AI assistantsExperimentation with custom tools and prompt engineering

FAQ

How does the agent work?
The agent runs in a loop: it gets a prompt with a question, then generates a Thought and an Action (which tool to use). The tool’s output becomes an Observation, which is appended to the prompt. This repeats until the agent has enough information to provide a Final Answer.
What tools are available in the library?
The library currently implements three tools: Python REPL (execute Python code), Google Search (via SerpAPI), and Hacker News search. Each tool is a Python class with a `use` method, a name, and a description.
What is the prompt template used?
The prompt template includes the current date, tool descriptions, tool names, the user question, and previous responses. It instructs the LLM to use a specific format: Thought, Action, Action Input, Observation, and finally Final Answer when ready.
Is this library production-ready?
No, it is designed for educational purposes to understand the core mechanics of LLM-controlled agents. It lacks robustness, error handling, and advanced features needed for production use.