Project: an agent with tools
Build an agent that uses two or three tools to answer questions it could not answer alone, such as checking the health of a GitHub repository or finding recent news on a topic.
Words on this page (7)
- agent
- : A model run in a loop that chooses its own tools and steps until the task is done.
- tool
- : A function the model can ask your program to run, described by a name, description and argument schema.
- repo
- : Repository: a project folder tracked by git, usually hosted on GitHub.
- tool use
- : The model asks your program to run a function and reads the result.
- logarithm
- : The power you raise a base to in order to get a number. log base 2 of 8 is 3 because 2 to the power 3 is 8.
- API
- : Application programming interface: a way for one program to call another, usually over HTTP.
- JSON
- : A text format for structured data: keys and values in braces, like {"name": "Ada"}.
The brief
The user asks "Is this open-source project well maintained?" The calls for recent commits, open issues and the latest release, then writes a verdict with numbers.
Steps
- Define the tools with clear descriptions and schemas.
- Write the loop by hand: call the model, run , append results, repeat until the model answers, with a step limit.
- Validate every argument before running a tool.
- When a tool fails, return an instructive error as the result.
- every call and result.
- Save the conversation so it can resume.
Check yourself
Run ten different projects, including one that does not exist and one with no recent activity. Read the logs. Count how often the agent picks the wrong tool or loops. Fix descriptions and limits, then rerun the same ten.
Done when
The agent answers five test questions using its tools. A that does not exist produces a recovered answer, not a crash. A step limit stops it when you force a tool to keep failing. Every tool call is logged with its arguments and result.
Stretch
Add a second tool for the project's documentation and let the agent decide which to use. Try a smaller model for the tool steps and compare cost and accuracy.
Starter
Python. Reuse the loop from the agent loop lesson and give it two real tools backed by the GitHub (no key needed for light use). Install pip install requests.
import requests
def recent_commits(repo: str) -> str:
r = requests.get(f"https://api.github.com/repos/{repo}/commits", params={"per_page": 5}, timeout=10)
if r.status_code == 404:
return f"No repository named '{repo}'. Use the form owner/name, for example pallets/flask."
r.raise_for_status()
return "\n".join(f"{c['commit']['author']['date'][:10]} {c['commit']['message'].splitlines()[0]}" for c in r.json())
def run_tool(name, args):
if name == "recent_commits":
return recent_commits(args["repo"])
raise ValueError(f"unknown tool {name}")Add a second tool for open issues and one for the latest release. Write the tool descriptions carefully: they are what the model sees.
A builder's repo-health agent works on ten projects, then loops forever on one that has no releases. The log shows the tool returned an empty list and the model kept asking again. They add a clear "no releases found" result and a step limit. A real agent project is mostly this: reading logs, adding limits, improving error messages.
Check yourself
What stops an agent loop from running forever?
Not quite. Combine the model's answer with step, cost and time limits.
A tool receives a repository name that does not exist. What should it return?
Not quite. The model can adjust when the error says what happened.
In ten test runs, the agent picks the wrong tool in four. Where do you look first?
Not quite. The description is how the model chooses, so fix it and rerun the same ten.
You got 0 of 3 right.
Go deeper
- ArticleHow to build an agentArticle
Thorsten Ball · The hand-written loop, in code.
- Article
Anthropic · Tool descriptions and error messages.
- DocsGitHub REST APIDocs
GitHub · The data source for the health tools.
Spotted a mistake or something unclear? Report it on GitHub.