Prompt: build a simple AI agent with tool calls (framework-agnostic)

PromptAI agents

Free template

A build prompt for a small, readable agent loop with a tool registry, argument validation, step limits, confirmation before risky actions, logging and offline tests.

Updated Oct 26, 2026 · Free to copy, change and use in your own projects. No sign-up needed. · Jump to the template

When to use this template

You want to understand and own how an AI agent works before you adopt a framework, or you need a small agent with only a few tools.

Tools it works with

Use it with any AI coding agent, and with any model API that supports tool calling (also called function calling). LangGraph and CrewAI are listed as frameworks to consider once you outgrow the hand-written loop.

How to use it

  1. Decide on one clear goal and two to four tools. Fewer tools with clear descriptions work better than many vague ones.
  2. Fill in the brackets: goal, tools, language, model provider, interface and the folder the file tools may use.
  3. Send the prompt to your coding agent. Review the file structure and tool schemas it proposes before you approve the code.
  4. Set your API key as an environment variable, run the tests (they should not need the model), then try the three example requests.
  5. Add new tools one at a time, and update the system prompt to say when each tool should be used.

The template

simple-agent-prompt.md 46 linesDownload file
# Prompt: build a simple AI agent with tool calls (framework-agnostic)

Give this prompt to your coding agent (or a chat assistant) to build a small, working agent from scratch.
It describes the agent loop itself, so it works with any model API that supports tool calling (also called function calling).
Fill in the brackets first.

---

Build a small, working AI agent with tool calling. Keep it simple and readable: one main file plus one file for tools. Do not use an agent framework; write the loop yourself so I can understand every step.

## What the agent should do
- Goal: [e.g. "Answer questions about my local Markdown notes and create new notes on request"]
- Tools it needs: [e.g. `search_notes(query)`, `read_note(path)`, `create_note(title, body)`]
- Language and runtime: [Python 3.11+ | TypeScript on Node.js 20+]
- Model provider: [PROVIDER AND MODEL NAME]. Use the provider's official SDK at the version I have installed, and check its documentation for the exact tool-calling request and response format. Do not guess field names.
- Interface: [command-line chat loop | single command with an argument | small HTTP endpoint]

## Architecture
1. Tool registry. Each tool has a name, a one-sentence description written for the model, a JSON Schema for its parameters, and a plain function that implements it. The registry produces the tool definitions in the format the provider expects.
2. Agent loop:
   - Send the system prompt, the conversation so far and the tool definitions to the model.
   - If the model returns tool calls, validate the arguments against the schema, run each tool, and append each result to the conversation in the format the provider expects (matched to its tool call ID if the API uses IDs).
   - If the model returns a final answer with no tool calls, print it and stop.
   - Repeat, with a hard limit of [8] steps per user request. If the limit is reached, stop and tell the user what was done so far.
3. System prompt. Write a short one that states the agent's goal, when to use each tool, that it must not invent tool results, and that it should ask the user when a request is ambiguous.

## Safety and reliability
- Tools that change things (write, delete, send, pay) must ask the user to confirm in the terminal before they run. Read-only tools can run without asking.
- Restrict file tools to one folder: [PATH]. Reject paths that escape it (for example with `..`).
- Catch tool errors and return them to the model as a short error message, instead of crashing, so the model can recover or explain.
- Truncate long tool results (for example to [4,000] characters) and say that they were truncated.
- Read the API key from an environment variable (for example `[PROVIDER]_API_KEY`) and fail with a clear message if it is missing. Never print the key or write it to a log.
- Add a timeout to every network call.

## Observability
- Log each step to the console in a readable way: the step number, which tool was called with which arguments, a short preview of the result, and the token usage if the API returns it.
- Add a `--verbose` flag that also prints the full messages sent to the model.

## Deliverables
1. The code, with a short README: setup, environment variables, how to run it, and how to add a new tool.
2. Unit tests for each tool function and for argument validation, which do not call the model.
3. One test of the loop that uses a fake model client returning scripted tool calls, so the loop can be tested offline.
4. A list of three example requests I can try, and what the agent should do for each one.

Work step by step: first show me the file structure and the tool schemas, wait for my approval, then write the code.

Tips

We wrote this template from public documentation and common practice; we have not measured its results. Tools change often, so check each tool's own documentation if something does not work as described. Found a mistake? Email [email protected].

More free templates

All templates →

Get new templates in the newsletter

Get new templates in the newsletter: we email you when we add new free templates, together with the daily AI picks. Free, no spam, unsubscribe any time.

We'll send a confirmation email first (double opt-in). Sign-ups are handled by Kit.