Nanoagents AI Agent

by codebasics-community• 25•• Scanned•Claim this listing•Request removal
Productivity & Workflowagentic aiaillm agent

A nano, minimalistic, and lightweight library for building ReACT-based AI agents that use tools to solve tasks.

Nanoagents is an open-source ai agent by codebasics-community, written mainly in Python, with 25 GitHub stars and the Apache-2.0 license. Its code was last updated May 7, 2026. The latest PyPI release is nanoagents 0.1.0, published Feb 26, 2025, with 20 downloads last week.

nanoagents

A nano, minimalistic, and lightweight library for building ReACT-based AI agents that use tools to solve tasks.

PyPI version Python License Codebasics Community


What is nanoagents?

nanoagents implements the ReACT (Reason + Act) loop in under 200 lines of pure Python — no framework lock-in, no hidden magic.
You bring your own LLM callable. The library handles reasoning, tool dispatch, retries, and history.

This is a Codebasics community project — built in public, contributions welcome.


How it works

The agent runs a tight loop:

Task → [Thought → Action → Observation] × N → Final Answer

Each iteration the agent:

  1. Formats a structured prompt (task + tools + history).
  2. Calls your LLM function.
  3. Parses the JSON response.
  4. Dispatches the chosen tool and records the observation.
  5. Repeats until it produces a final_answer or hits max_steps.

Installation

# Preferred
uv add nanoagents

# pip
pip install nanoagents

Requires Python ≥ 3.11.
The library has zero mandatory dependencies — bring your own LLM client.


Quick Start

from nanoagents import Agent
from groq import Groq

def call_llm(prompt: str) -> str:
    client = Groq(api_key="YOUR_GROQ_API_KEY")
    response = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[{"role": "user", "content": prompt}],
    )
    return response.choices[0].message.content


agent = Agent(llm=call_llm)


@agent.tool("add")
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b


@agent.tool("multiply")
def multiply(a: int, b: int) -> int:
    """Multiply two numbers."""
    return a * b


result = agent.run("Calculate (5184 + 3348432) * 29")
print(result)

Alternative: add_tool for lambdas or runtime registration

agent.add_tool("square", lambda x: x ** 2, "Square a number")

API Reference

Agent

ParameterTypeDefaultDescription
llmCallable[[str], str]—Your LLM function. Takes a prompt, returns text.
max_stepsint10Maximum ReACT iterations before raising.
max_retriesint3Retries on malformed LLM output or tool errors.

Methods

MethodDescription
agent.tool(name)Decorator — register a function as a tool.
agent.add_tool(name, func, desc)Imperative tool registration.
agent.run(task: str) -> strExecute the ReACT loop and return final answer.

Tool

AttributeDescription
nameTool identifier used by the LLM in JSON output.
descDescription injected into the system prompt.
schemaAuto-parsed list of {name, type} arg dicts.

Project Layout

nanoagents/
├── nanoagents/
│   ├── __init__.py       # Public surface: Agent, Tool
│   └── nanoagent.py      # Core implementation
├── tests/
│   └── test.py           # Integration smoke test
├── docs/
│   ├── architecture.md   # Internals deep-dive
│   └── demos/            # Runnable demo scripts
│       ├── README.md
│       ├── 01_calculator.py
│       ├── 02_string_tools.py
│       ├── 03_llm_providers.py
│       └── 04_research_agent.py
├── CONTRIBUTING.md       # How to contribute
├── CHANGELOG.md          # Version history
├── CODE_OF_CONDUCT.md    # Community standards
├── LICENSE               # Apache 2.0
├── uv.lock               # Locked dependency graph
└── pyproject.toml        # Build config (PEP 621)

Demos

The docs/demos/ directory contains four runnable scripts that progress from basic to real-world:

DemoWhat it shows
01_calculator.pyDecorator API, arithmetic tools, multi-step math
02_string_tools.pyadd_tool() API, string manipulation tools
03_llm_providers.pyGroq, OpenAI, Anthropic, Ollama, OpenAI-compat adapters
04_research_agent.pystdlib-only web fetch, Wikipedia, multi-tool chaining
GROQ_API_KEY=<your-key> uv run python docs/demos/01_calculator.py

Contributing

We welcome issues, bug reports, and pull requests.
Read CONTRIBUTING.md before opening a PR — it covers branching strategy, code style, testing requirements, and the review process.


Community

This project is part of the Codebasics open-source community.
Discussions happen on the Codebasics Discord and GitHub Discussions.


License

Apache 2.0 — free to use, modify, and distribute with attribution.

Nanoagents alternatives

View more →

Similar ai agents in Productivity & Workflow, ranked by GitHub stars. Compare licence, recent activity and scan status before you choose.

NameStarsLicenceLast updatedScan
Nanoagents (this page)
codebasics-community
25Apache-2.0May 7, 2026Scanned, no flagged issues
Paperclip
paperclipai
110kMITNov 1, 2026Scanned, no flagged issues
Ppt Master
hugohe3
72kMITOct 30, 2026Scanned, no flagged issues
Llama Index
run-llama
53kMITOct 26, 2026Scanned, see report
Nanobot
HKUDS
50kMITOct 31, 2026Scanned, no flagged issues
Sim
simstudioai
30kApache-2.0Nov 1, 2026Scanned, see report