[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-92996":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":13,"stars30d":14,"stars90d":13,"forks30d":13,"starsTrendScore":13,"compositeScore":15,"rankGlobal":8,"rankLanguage":8,"license":16,"archived":17,"fork":17,"defaultBranch":18,"hasWiki":19,"hasPages":17,"topics":20,"createdAt":8,"pushedAt":8,"updatedAt":21,"readmeContent":22,"aiSummary":23,"trendingCount":13,"starSnapshotCount":13,"syncStatus":24,"lastSyncTime":25,"discoverSource":26},92996,"build-ai-agents-free","Moh4696\u002Fbuild-ai-agents-free","Moh4696",null,"Python",146,38,1,0,61,47.87,"MIT License",false,"master",true,[],"2026-07-22 04:02:07","# How to Build AI Agents Completely Free in 2026\n\n### the ultimate beginner's guide\n\n**$0 · no credit card · no prior experience · open-source**\n\nbuilding an AI agent shouldn't be something only engineers get to do. it should be\nsimple enough that anyone willing to follow along can build one that actually works.\n\nand here's the thing most \"build an AI agent\" tutorials won't tell you: they sneak\nin a paid API key around step 3. this one doesn't. you can build a real, working\nagent — one that reasons, calls tools, and loops until a task is done — without\nspending a cent. no credit card, no trial that expires, no bait-and-switch. and no\nprior experience needed.\n\n---\n\n## the free stack\n\neverything here is free, forever:\n\n- **langchain + langgraph — the framework.** MIT-licensed, hit 1.0 this year, and\n  its new `create_agent` is the fastest way to stand up an agent that actually\n  works. langgraph also leads every open-source agent framework in enterprise\n  adoption, with **34.5M downloads a month** (per firecrawl's 2026 framework\n  report). → https:\u002F\u002Fgithub.com\u002Flangchain-ai\u002Flangchain\n- **groq (or google's gemini free tier) — the brain.** groq runs open models like\n  llama 3.3 70b at **~300 tokens\u002Fsec** and hands out **~14,400 requests a day** with\n  no card. gemini gives you **1,500 requests\u002Fday** and a **million-token context\n  window** if you'd rather. → https:\u002F\u002Fconsole.groq.com · https:\u002F\u002Faistudio.google.com\n- **your own machine — that's it.** python and a text editor.\n\n> **one honest catch up front:** \"free\" tiers change monthly and most of them train\n> on your prompts. keep anything sensitive off them. we'll cover the fallback setup\n> so a provider quietly killing a model doesn't take your agent down with it.\n\nby the end you'll have an agent that can search, use a tool you wrote yourself, and\nremember a conversation — running entirely on $0.\n\n---\n\n## what an AI agent actually is 🤖\n\nbefore we build one, let's clear up what an \"agent\" even means, because the word gets\nthrown around a lot.\n\na normal **chatbot** does one thing: you ask, it answers. done. it can't look\nanything up, can't take an action, can't check its own work. it just talks.\n\nan **agent** is different. an agent is a model that runs in a **loop** — it thinks\nabout the task, does something, looks at the result, and decides what to do next. it\nkeeps going until the job is actually finished.\n\nthat loop has three moves:\n\n1. **plan** — the model reads the task and decides what to do. *\"the user wants\n   today's weather in lagos. I don't know that. I should use the weather tool.\"*\n2. **act** — it calls a tool. a web search, a calculator, a function you wrote,\n   anything you give it access to.\n3. **observe** — it reads what the tool gave back, then loops. either it has enough\n   to answer, or it plans the next step.\n\nthat's the whole trick. a chatbot is a mouth. an agent is a mouth with hands and\neyes. it can reach out into the world, see what happened, and adjust.\n\nthe model provides the reasoning. langchain wires up the loop and the tools. that's\nwhat we're building.\n\n---\n\n## setup (5 minutes, still $0)\n\nthree things to install, one free key to grab. no credit card anywhere.\n\n> 🎬 **watch the 90-second setup demo** *(silent screen recording of the folder +\n> `.env` + `agent.py` steps below):*\n\nhttps:\u002F\u002Fgithub.com\u002FMoh4696\u002Fbuild-ai-agents-free\u002Freleases\u002Fdownload\u002Fv1.0\u002Fbuildagent.mp4\n\n**a. python.** if you don't have it, get python 3.10 or newer from\n[python.org](https:\u002F\u002Fpython.org). to check what you've got, open a terminal and run\n(anything 3.10+ works):\n\n```bash\npython3 --version\n```\n\n**b. make a project folder.** somewhere easy to find, make a folder for this build\nand move into it (everything else happens inside here):\n\n```bash\nmkdir my-agent\ncd my-agent\n```\n\n**c. install langchain + groq.** one line:\n\n```bash\npip install -U \"langchain[groq]\" python-dotenv\n```\n\nthat pulls in langchain (the framework), the groq connector (so your agent can reach\ngroq's free models), and python-dotenv (which reads your key from a file). all in one\ngo.\n\n**d. grab your free groq key.** go to\n[console.groq.com](https:\u002F\u002Fconsole.groq.com), sign in with google or github, and open\nthe **\"API Keys\"** tab. click create, copy the key. no card, no trial clock — it's\nfree to start.\n\n**e. make your `.env` file.** this is where the key lives — a plain text file named\nexactly `.env`, with the dot at the front and nothing after it. the dot makes it a\n\"hidden\" file, which is normal. here's how to create it:\n\n```bash\n# mac \u002F linux\ntouch .env\n\n# windows\ntype nul > .env\n```\n\nthen open that file in any text editor and paste your key in, like this:\n\n```bash\nGROQ_API_KEY=your_key_here\n```\n\nswap `your_key_here` for the key you copied. save it.\n\n> **one rule:** never share this file, and never commit it to github. your key is a\n> password — anyone who has it can run up your account. keeping it in `.env` keeps it\n> out of your code and out of trouble.\n\nthat's the whole setup. python, one install, one free key. next we write the agent.\n\n---\n\n## your first agent\n\nopen `agent.py` and paste this in. this is a complete, working agent. it loads your\nkey, connects to a free groq model, and answers you. we'll go line by line right\nafter.\n\n> 📄 in this repo: [`src\u002F01_first_agent.py`](src\u002F01_first_agent.py)\n\n```python\nfrom dotenv import load_dotenv\nfrom langchain.agents import create_agent\nfrom langchain_groq import ChatGroq\n\n# load your GROQ_API_KEY from the .env file\nload_dotenv()\n\n# the brain: a free groq model\nmodel = ChatGroq(model=\"llama-3.3-70b-versatile\")\n\n# the agent: model + a system prompt telling it how to behave\nagent = create_agent(\n    model=model,\n    tools=[],\n    system_prompt=\"You are a helpful assistant. Be concise and accurate.\",\n)\n\n# ask it something\nresult = agent.invoke(\n    {\"messages\": [{\"role\": \"user\", \"content\": \"explain what an AI agent is in two sentences.\"}]}\n)\n\n# print the agent's reply\nprint(result[\"messages\"][-1].content)\n```\n\nrun it:\n\n```bash\npython3 agent.py\n```\n\nafter a second, you'll see the model answer in your terminal. that's your agent\nrunning on a free model, no card, entirely from your own machine.\n\n**what each part does:**\n\n- `load_dotenv()` reads your groq key out of the `.env` file so the code can use it\n  without the key ever being written into the code itself.\n- `ChatGroq(model=\"llama-3.3-70b-versatile\")` picks the brain. this is a free llama\n  model served by groq, fast enough that replies feel instant.\n- `create_agent(...)` builds the agent. right now `tools=[]` is empty, so this is\n  really just a smart chatbot. the `system_prompt` is the standing instruction it\n  follows every time.\n- `agent.invoke(...)` sends it a message and runs the loop until it has an answer.\n- `result[\"messages\"][-1].content` grabs the last message in the conversation — the\n  agent's reply — and prints it.\n\nright now it can only talk. it has no tools, so if you ask it something it doesn't\nknow — today's news, a live price, anything real-time — it'll guess or admit it\ncan't. that's the next section: giving it tools, so it can actually go find things\nout.\n\n---\n\n## giving your agent tools\n\nright now your agent can only talk. **tools** are what turn it from a chatbot into\nsomething that acts: it can search the web, run a calculation, hit an API, or call any\nfunction you write. the model decides *when* to use a tool based on what you ask. you\njust hand it the options.\n\nwe'll add two: a web search it didn't write, and a function you did.\n\nfirst, one more free install (no key needed — duckduckgo search is free):\n\n```bash\npython3 -m pip install -U duckduckgo-search langchain-community\n```\n\nnow update `agent.py`:\n\n> 📄 in this repo: [`src\u002F02_agent_with_tools.py`](src\u002F02_agent_with_tools.py)\n\n```python\nfrom dotenv import load_dotenv\nfrom langchain.agents import create_agent\nfrom langchain.tools import tool\nfrom langchain_groq import ChatGroq\nfrom langchain_community.tools import DuckDuckGoSearchRun\n\nload_dotenv()\n\nmodel = ChatGroq(model=\"llama-3.3-70b-versatile\")\n\n# tool 1 — web search (prebuilt, free, no key)\nsearch = DuckDuckGoSearchRun()\n\n# tool 2 — a function you wrote yourself\n@tool\ndef word_count(text: str) -> int:\n    \"\"\"Count how many words are in a piece of text.\"\"\"\n    return len(text.split())\n\n# hand both tools to the agent\nagent = create_agent(\n    model=model,\n    tools=[search, word_count],\n    system_prompt=\"You are a helpful assistant. Use your tools when they help answer accurately.\",\n)\n\nresult = agent.invoke(\n    {\"messages\": [{\"role\": \"user\", \"content\": \"search for the latest langchain version, then tell me how many words your answer is.\"}]}\n)\n\nprint(result[\"messages\"][-1].content)\n```\n\nrun it:\n\n```bash\npython3 agent.py\n```\n\nwatch what happens: the agent reads your request, realizes it needs current info,\ncalls the search tool, reads the result, then calls your `word_count` tool on its own\nanswer. all in one loop, no extra code from you. that's the **plan → act → observe**\ncycle running for real.\n\n**the part that matters — how the agent knows what a tool does:**\n\nlook at the `word_count` function. two things make it a tool:\n\n- the **`@tool` decorator** — that's what registers it so the agent can call it.\n- the **docstring** `\"\"\"Count how many words are in a piece of text.\"\"\"` — this isn't\n  a comment for you, it's the description the model reads to decide *when* to use the\n  tool. the type hints (`text: str → int`) tell it what to pass in and what it gets\n  back.\n\nthat's the whole pattern. any python function becomes a tool: write the function, add\na clear docstring, slap `@tool` on top, drop it in the list. want your agent to check\nyour database, send an email, hit a weather API? same three steps.\n\n> **one honest heads-up:** the free duckduckgo search rate-limits and will\n> occasionally throw an error if you hammer it. that's normal for a no-key free tool.\n> if it fails, wait a few seconds and rerun — and in the fallback section, we'll make\n> the agent survive a tool failing instead of crashing.\n\n---\n\n## giving your agent memory\n\ntry this on your current agent: tell it your name, then in a second message ask what\nyour name is. it won't know. every time you call it, it starts from a blank slate — no\nmemory of what you just said.\n\nthat's because each `invoke` is independent. to make it remember, you give it two\nthings: a **checkpointer** (which saves the conversation) and a **thread_id** (a label\nthat says \"these messages belong to the same chat\").\n\nupdate `agent.py`:\n\n> 📄 in this repo: [`src\u002F03_agent_with_memory.py`](src\u002F03_agent_with_memory.py)\n\n```python\nfrom dotenv import load_dotenv\nfrom langchain.agents import create_agent\nfrom langchain_groq import ChatGroq\nfrom langgraph.checkpoint.memory import InMemorySaver\n\nload_dotenv()\n\nmodel = ChatGroq(model=\"llama-3.3-70b-versatile\")\n\n# the checkpointer saves conversation state between calls\nagent = create_agent(\n    model=model,\n    tools=[],\n    system_prompt=\"You are a helpful assistant. Be concise and accurate.\",\n    checkpointer=InMemorySaver(),\n)\n\n# a thread_id labels the conversation — same id = same memory\nconfig = {\"configurable\": {\"thread_id\": \"chat-1\"}}\n\n# first message\nr1 = agent.invoke(\n    {\"messages\": [{\"role\": \"user\", \"content\": \"hi! my name is m0h.\"}]},\n    config,\n)\nprint(r1[\"messages\"][-1].content)\n\n# second message — same thread_id, so it remembers\nr2 = agent.invoke(\n    {\"messages\": [{\"role\": \"user\", \"content\": \"what's my name?\"}]},\n    config,\n)\nprint(r2[\"messages\"][-1].content)\n```\n\nrun it:\n\n```bash\npython3 agent.py\n```\n\nthis time the second answer comes back with your name. the agent remembered because\nboth calls shared `thread_id: \"chat-1\"`, and the checkpointer held onto the history in\nbetween.\n\n**the mental model:**\n\n- the **checkpointer** is the notebook. it writes down the conversation after every\n  turn.\n- the **thread_id** is which page of the notebook you're on. same id, same page, same\n  memory. change the id to `\"chat-2\"` and you start a fresh conversation with no\n  history — handy when one agent serves different users.\n\n> **one honest limit:** `InMemorySaver` keeps memory in your computer's RAM, so it\n> vanishes the moment your script stops. that's fine for learning and prototyping. for\n> a real app that remembers across restarts, you swap it for a database-backed\n> checkpointer (langchain has ones for postgres and redis). same `thread_id` idea,\n> just written to disk instead of memory. we're staying free and local, so\n> `InMemorySaver` is exactly right for now.\n\n---\n\n## the fallback setup\n\n### (so a dead free tier doesn't kill your agent)\n\nhere's the thing nobody tells you in the tutorial: **free tiers change without\nwarning.** a provider tightens a rate limit, or quietly deletes the exact model your\ncode was calling, and your agent — which you didn't touch — suddenly throws errors.\nthis actually happens. one dev woke up to a dead pipeline because a provider removed a\nmodel overnight.\n\nthe fix is simple: **don't bet everything on one provider.** set up a backup, so if\ngroq is down or rate-limited, your agent falls back to gemini (or a local model) and\nkeeps running.\n\nfirst, add a second free provider. we'll use google's gemini free tier as the backup:\n\n```bash\npython3 -m pip install -U langchain-google-genai\n```\n\ngrab a free gemini key at [aistudio.google.com](https:\u002F\u002Faistudio.google.com) (google\naccount, no card), and add it to your `.env`:\n\n```bash\nGROQ_API_KEY=your_groq_key\nGOOGLE_API_KEY=your_gemini_key\n```\n\nnow make a model that fails over. the idea: try to build the agent on groq. if that\nprovider errors out, catch it and rebuild on gemini instead — same tools, same\neverything.\n\n> 📄 in this repo: [`src\u002F04_agent_with_fallback.py`](src\u002F04_agent_with_fallback.py)\n\n```python\nfrom dotenv import load_dotenv\nfrom langchain.agents import create_agent\nfrom langchain_groq import ChatGroq\nfrom langchain_google_genai import ChatGoogleGenerativeAI\n\nload_dotenv()\n\n# define your providers in order of preference — all free\ndef get_model():\n    try:\n        # first choice: groq (fastest)\n        model = ChatGroq(model=\"llama-3.3-70b-versatile\")\n        model.invoke(\"ping\")  # quick test that it actually responds\n        print(\"using groq\")\n        return model\n    except Exception as e:\n        # groq is down or rate-limited — fall back to gemini\n        print(f\"groq failed ({e}); falling back to gemini\")\n        return ChatGoogleGenerativeAI(model=\"gemini-2.5-flash\")\n\nagent = create_agent(\n    model=get_model(),\n    tools=[],\n    system_prompt=\"You are a helpful assistant. Be concise and accurate.\",\n)\n\nresult = agent.invoke(\n    {\"messages\": [{\"role\": \"user\", \"content\": \"say hi and tell me which model you are.\"}]}\n)\nprint(result[\"messages\"][-1].content)\n```\n\nnow if groq is having a bad day, your agent quietly switches to gemini and keeps\nworking. you can chain a third provider the same way — add another `except` layer for\nopenrouter, or a local ollama model that needs no key at all.\n\n**why this pattern and not a fancier one:** langchain has a built-in\n`with_fallbacks()`, but as of 2026 it doesn't always play nicely when handed straight\nto an agent — it can throw a confusing error. the plain `try\u002Fexcept` above is boring,\nbut it works every time, and you can read exactly what it does. boring and reliable\nbeats clever and fragile.\n\n> **the rule to remember:** never hardcode a single free model as if it'll be there\n> forever. name a primary, name a backup, and your agent survives the day a provider\n> changes its mind.\n\n---\n\n## bonus: the complete agent\n\nthis repo also ships [`src\u002Fagent.py`](src\u002Fagent.py) — the full version that combines\n**all three upgrades at once**: provider fallback (groq → gemini), both tools\n(duckduckgo search + your `word_count`), and memory (`InMemorySaver` + `thread_id`).\nrun it to see the whole thing working end to end:\n\n```bash\npython3 src\u002Fagent.py\n```\n\n---\n\n## where to go from here\n\nyou have a working agent now. it reasons, uses tools, remembers, and survives a\nprovider going down — all free, from your own machine. that's the same core loop the\nagents at uber and klarna run on.\n\nwhere to take it next:\n\n- **build a real tool.** `word_count` was a warm-up. write one that checks your\n  calendar, reads a file, or hits an API you actually use. same pattern every time:\n  function, docstring, `@tool`, drop it in.\n- **add more and let it choose.** give the agent five tools and it picks the right\n  ones per request, chaining them when needed. that's the whole point of an agent over\n  a chatbot.\n- **make memory permanent.** swap `InMemorySaver` for a postgres or redis checkpointer\n  so it remembers across restarts, not just one run.\n- **when to start paying — if ever.** free tiers are built for what you're doing:\n  learning, side projects, low traffic. two signals it's time: real users depend on\n  it, or it can't fail during business hours. even then, deepseek runs a dollar or two\n  a month. don't pay before you hit one.\n- **the real price of free.** most no-key models train on your prompts. keep anything\n  private or client-confidential off them; switch to a paid tier or local ollama the\n  moment it's sensitive.\n\nno credit card, no course, no degree. just a few free tools and a couple of commands.\nwhat you built today is a foundation. now go point it at something.\n\n---\n\n*~m0h · built for [@exploraX_](https:\u002F\u002Fx.com\u002FexploraX_)*\n","这是一个面向初学者的零成本AI智能体构建指南项目，提供无需付费API、无需编程经验即可搭建真实可用AI代理的完整开源方案。核心基于LangChain\u002FLangGraph框架实现推理-执行-观察闭环，支持接入Groq或Gemini免费API作为大模型后端，并强调本地开发环境兼容性与容错设计。适用于个人学习、教学演示、原型验证等轻量级自动化任务场景，如信息检索、工具调用和多轮对话记忆等。",2,"2026-07-11 02:30:35","CREATED_QUERY"]