Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To build your first AI agent, start with a narrow job, give it clear instructions, and run it once. You do not need an agent framework to understand that basic loop, but a framework can make tools and multi-step behavior easier to add. This tutorial walks through a working Python example, shows the equivalent JavaScript setup, and explains how to learn without paying for hosted inference. Free access is limited and varies by provider; “free” does not mean unlimited.

What is the simplest way to build an AI agent?

A useful first agent is a program that sends a task to a model under specific instructions and returns the model’s response. Begin with one turn and one responsibility, such as answering beginner history questions. In the OpenAI Agents SDK, an agent holds the instructions and model configuration, and a runner executes it and returns the result. Tools, memory, and multi-agent workflows are things to add when the task actually needs them—not prerequisites for a first run.

For a beginner, Python keeps setup short; JavaScript is equally viable if that fits your existing project. OpenAI’s official quickstarts cover both languages. The examples below use the Agents SDK and an API key, so they are not guaranteed to run at zero cost: check the provider’s current model pricing and account limits before making requests. Framework installation may be free while model inference is billed separately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build and run a first agent in Python

1. Create a project and install the SDK

Use a supported Python installation and a terminal. Create an isolated environment so the project’s packages do not interfere with other Python projects:

mkdir first-agent
cd first-agent
python -m venv .venv

Activate the environment, then install the SDK. On macOS or Linux:

source .venv/bin/activate
pip install openai-agents

On Windows PowerShell, activate it with:

.venvScriptsActivate.ps1
pip install openai-agents

If PowerShell blocks activation, use a terminal where you can activate the environment, or run the environment’s Python executable directly to install and launch the project. Do not install into a different Python environment from the one you use to run the script.

2. Set the API key outside the source file

Create an API key with your chosen provider and make it available to the process as OPENAI_API_KEY. For macOS or Linux, set it in the current shell:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
export OPENAI_API_KEY="your-api-key"

In Windows PowerShell:

$env:OPENAI_API_KEY="your-api-key"

Replace the example value with your actual key. Do not commit it to source control, include it in screenshots, or put it in a script that will be shared. Environment variables set this way generally apply only to the current shell session; set the value again in a new terminal. Use your provider’s secret-management guidance for deployed applications.

3. Define one focused agent and run it

Save this as agent.py:

import asyncio
from agents import Agent, Runner

async def main():
    tutor = Agent(
        name="History tutor",
        instructions=(
            "Answer history questions for beginners in plain language. "
            "If a question is ambiguous, say what needs clarification."
        ),
    )

    result = await Runner.run(
        tutor,
        "Why was the printing press important in Europe?"
    )
    print(result.final_output)

if __name__ == "__main__":
    asyncio.run(main())

Run it from the activated environment and the directory containing the file:

python agent.py

The program should print the model’s answer. That confirms the basic path—credentials, instructions, model call, and output—is working. Model names and availability can change; select a model supported by your account using the SDK’s documented configuration if you need to set one explicitly.

Prefer JavaScript or TypeScript?

The same first-run idea works in a Node.js project. The JavaScript Agents SDK quickstart uses the @openai/agents package; its example setup also installs zod. Create a project and install them:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mkdir first-agent-js
cd first-agent-js
npm init -y
npm install @openai/agents zod

Set OPENAI_API_KEY in the shell as above. Save the following as agent.mjs:

import { Agent, run } from "@openai/agents";

const tutor = new Agent({
  name: "History tutor",
  instructions:
    "Answer history questions for beginners in plain language. " +
    "If a question is ambiguous, say what needs clarification.",
});

const result = await run(
  tutor,
  "Why was the printing press important in Europe?"
);
console.log(result.finalOutput);

Run it with node agent.mjs. The example uses an ES module file so you do not have to change the project’s package configuration. The SDK’s TypeScript examples and type definitions are useful once you add structured inputs or tools; keep this first run small enough that you can identify whether a problem is in setup or agent behavior.

Can you build an AI agent for free?

Yes, for learning and small prototypes, if you use a free hosted tier that currently covers the model you select or run a model locally. Neither option promises unlimited use. Hosted providers impose usage or rate limits, and free eligibility, available models, and prices can change. Verify the current provider pricing and account terms before relying on a free tier for an application.

  • Gemini API: Google lists free access for eligible models, including free input and output tokens on its free tier, subject to caps. Treat this as a way to learn or prototype, not a fixed production allowance; check current model eligibility and limits.
  • Hugging Face inference providers: the current pricing documentation describes a $0.10 allowance for free users and says it is subject to change. It is a small allowance, not an unlimited free endpoint.
  • Local inference: Hugging Face documents a local-app route that includes Ollama and an OpenAI-compatible API server. Local inference avoids per-call hosted charges, but depends on your computer’s hardware and the model’s license. You still need to review the license and requirements for the particular model you choose.
  • OpenAI Agents SDK: the SDK is a framework, not a guarantee of free model usage. The Python and JavaScript examples above need a working provider key; confirm the relevant account and model costs before running them.

For a first experiment, set a small task and stop if the provider’s displayed limits or billing terms are unclear. Do not design around a free-tier number as though it will remain unchanged.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What should you add after the first run?

Add capabilities in response to a real requirement. This sequence keeps debugging manageable and helps you distinguish an agent problem from a tool, state, or deployment problem.

Add one tool

A tool lets the model request an action your program can perform, such as looking up a record or running a calculation. Define a narrow input schema, validate the arguments, execute the function, and return a result the agent can use. Decide what should happen on invalid input, a timeout, or a failed tool call. Do not give a tool broader access than the task needs, and require confirmation before consequential actions.

Add conversation state or memory only when needed

A one-turn example does not remember earlier messages. A conversational application needs a way to associate turns with a conversation, such as an SDK session or application-managed state. Longer-term memory is a separate design decision: choose what is retained, where it is stored, when it expires, and how a user can correct or delete it. Avoid sending sensitive data to a model or retaining it without a clear need.

Use handoffs and workflows for genuine multi-step tasks

If a task needs distinct specialist behavior, sequential steps, or review, orchestration can help. The OpenAI Agents SDK documents agents-as-tools, handoffs, guardrails, and structured outputs. A handoff or workflow adds coordination and failure paths, so do not introduce one merely to make a small single-purpose agent appear more advanced.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inspect runs and evaluate changes

Use run history or tracing to inspect model calls and tool actions. Test representative inputs, ambiguous requests, malformed tool inputs, and failure cases. Record the expected outcome before changing instructions or adding a tool; otherwise, a response that sounds plausible can mask a regression. Evaluate safety and correctness for the actual task, not just whether the agent returns text.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which framework or model path should a beginner choose?

Choose based on the next thing you need to learn rather than framework popularity. Microsoft’s Agent Framework getting-started tutorial, last updated 2026-08-25, progresses from a first agent to tools, conversations, memory, workflows, a harness, and hosting. That staged approach is useful regardless of which stack you select.

Path Good fit for Trade-off to check
OpenAI Agents SDK A first agent using Python or JavaScript, followed by tools and documented orchestration features. The SDK and model usage are separate concerns; verify provider access, model choice, and cost.
Microsoft Agent Framework Learning incrementally through agents, tools, conversations, memory, workflows, and hosting. Check the current language and model-provider support for your intended application before committing.
Google ADK Developers who want Google’s framework for building, managing, evaluating, and deploying AI-powered agents. Confirm the model and service choices, free-tier eligibility, and limits for your region and account.
Local model stack Experimenting without per-call hosted inference charges, or exploring a local-app workflow such as Ollama with an OpenAI-compatible server. Hardware, setup, response quality, and model license all matter; local does not mean cost-free in time or computing resources.

Compare the options on first-run setup, language support, tool calling, state and memory, handoffs and workflows, tracing and evaluation, hosting, model-provider flexibility, privacy, and free-tier limits. The best beginner path is usually the one you can run and inspect—not the one with the longest feature list.

Or skip the browser setup

If your agent needs website screenshots, ScreenshotNeo provides a screenshot API and MCP server. For the browser-based DIY route, you would need to set up and maintain browser capture yourself. This one-call example requests a screenshot; the API also returns PDFs when configured to do so.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for ScreenshotNeo free.

Troubleshooting a first agent

  • Missing API key: confirm the variable is named OPENAI_API_KEY and was set in the same shell session that launches Python or Node.js. Do not print the key while debugging.
  • Authentication failure: check that the key is valid for the provider and account you intend to use, that it has not been revoked, and that the code is configured for that provider. A package install does not create credentials.
  • Model access or billing error: verify the model is available to the account and that its current usage terms permit the request. Free access may be capped or unavailable for a particular model.
  • Import or module error: install the package in the active Python virtual environment or the project’s Node.js directory. For Python, check that python and pip point to the same environment.
  • No useful answer: narrow the instructions to one role and make the expected response clear. Try a straightforward prompt before introducing tools, memory, or a workflow.
  • Tool does not run: check the declared input schema, validate values, and handle tool exceptions and timeouts. The model can request a tool; your application remains responsible for executing and reporting its result.
  • Unexpectedly high usage: avoid loops that repeatedly call the model, test with short prompts, and review provider usage and current pricing. A framework does not set a universal cost per run.

Frequently Asked Questions

Do I need an agent framework to make my first AI agent?

No. A model call with focused instructions is enough to learn the basic loop; a framework becomes useful as you add tools, state, or orchestration.

Can I use a local model with an agent?

Yes, if your chosen model and serving setup are compatible with the framework. Hugging Face documents a local-app approach that includes Ollama and an OpenAI-compatible API server; hardware and model licensing still apply.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.