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.

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

This tutorial builds and runs one focused AI agent in your own Python application using the OpenAI Agents SDK. You will install the SDK, configure an API key, define an agent, send one prompt, print the result, and inspect the trace. The example is intentionally small: it demonstrates a working SDK integration, not unrestricted autonomous behavior.

The Agents SDK is different from OpenAI’s hosted Agents API. The SDK runs inside your application; the hosted API quickstart uses a managed harness and sandbox in OpenAI’s service. Choose one path for a project instead of mixing their setup instructions. This article uses the SDK.

What you will build

The first program has four moving parts:

  • An API key supplied through an environment variable.
  • One agent with a narrow instruction.
  • A runner call that sends a user request.
  • Printed final output and a trace you can inspect.

Use a harmless prompt whose answer is easy to check. Model output can vary between runs, so treat the response below as an example rather than a guaranteed string.

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

Prerequisites and safe configuration

  • Python 3 and a virtual environment, or a current Node.js project.
  • An OpenAI API key with access to the models available to your account.
  • A terminal and an editor.

Never commit a key to Git, paste it into a screenshot, or place it in browser-side code. Store it in your shell environment or a secret manager. The commands below use OPENAI_API_KEY.

Option A: Python SDK quickstart

1. Create an environment and install the package

python -m venv .venv
# macOS/Linux
source .venv/bin/activate
# Windows PowerShell: .venvScriptsActivate.ps1
pip install openai-agents

The official Python quickstart uses pip install openai-agents. If your project pins dependencies, record the installed version in its normal lock file.

2. Set the key

# macOS/Linux
export OPENAI_API_KEY="your_api_key_here"
# Windows PowerShell
$env:OPENAI_API_KEY="your_api_key_here"

3. Define one agent and run it

import asyncio
from agents import Agent, Runner

agent = Agent(
    name="Science explainer",
    instructions=(
        "Explain science questions for a curious 12-year-old. "
        "Use short paragraphs and one concrete analogy."
    ),
)

async def main():
    result = await Runner.run(
        agent,
        "Why does the Moon appear to change shape?"
    )
    print(result.final_output)

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

Save this as first_agent.py and run python first_agent.py. The runner manages the documented agent turn and returns a result whose final_output is printed. The exact wording depends on the model and run conditions.

What this code does—and does not do

  • Agent holds the name and behavioral instructions.
  • Runner.run executes the interaction in your application.
  • No tool, database, browser, or specialist handoff is involved yet.
  • The agent cannot take an external action merely because it is called an agent; you must add capabilities explicitly.

Option B: JavaScript SDK quickstart

1. Install the packages

npm init -y
npm install @openai/agents zod

The JavaScript quickstart installs both @openai/agents and zod. Keep the API key in the environment rather than source code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# macOS/Linux
export OPENAI_API_KEY="your_api_key_here"
# Windows PowerShell
$env:OPENAI_API_KEY="your_api_key_here"

2. Define and run the agent

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

const agent = new Agent({
  name: 'Science explainer',
  instructions:
    'Explain science questions for a curious 12-year-old. ' +
    'Use short paragraphs and one concrete analogy.',
});

const result = await run(
  agent,
  'Why does the Moon appear to change shape?'
);

console.log(result.finalOutput);

Run the file with the Node configuration used by your project (for example, an ES-module project). The result is an example response, not a fixed snapshot.

Inspect the first trace before expanding the prompt

After a successful run, open the Traces dashboard referenced by the official SDK quickstart. Traces let you inspect model calls, tool calls, handoffs, and guardrails. This is usually more useful than changing instructions blindly: you can see which step ran and where latency or an unexpected answer originated.

  1. Run the smallest working program.
  2. Open the trace for that run in the Traces dashboard.
  3. Check the model call and the final output.
  4. If tools or handoffs are later added, verify each corresponding span.
  5. Only then revise instructions or add constraints.

Add a tool only when the agent needs an action or external information

Instructions can shape an answer, but they do not grant access to your systems. A function tool is appropriate when the model must request a narrowly defined action, such as looking up a record or calculating a value. Keep the function’s inputs explicit, validate them, and enforce authorization in your application.

Hosted tools can provide capabilities maintained outside your process. Whichever tool type you choose, inspect its execution result in the trace and handle failures in code. Do not assume that a natural-language answer proves the underlying operation succeeded.

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

Use handoffs for genuine specialist routing

A handoff transfers responsibility to another agent. It is different from a tool call: a tool performs an operation, while a handoff lets a specialist agent take over the conversation. The Python quickstart demonstrates a triage pattern that routes homework questions to history or math specialists; the runner executes the individual agents, tool calls, and handoffs in that flow.

Add a handoff when routing is a real requirement, not simply to make a demo appear more autonomous. Define each specialist’s scope and test ambiguous requests, including cases where no specialist should accept the task.

SDK versus hosted Agents API

Choice Where it runs Best fit Important distinction
Agents SDK Inside your Python or JavaScript application Code-first integration with your own runner, tools, and application control Install the SDK package, define agents in code, and inspect SDK traces
Agents API Managed harness in OpenAI’s service; its quickstart uses a hosted sandbox Readers specifically exploring hosted execution It is a separate implementation path; do not combine its setup steps with the SDK example

The hosted route can be useful for exploring managed execution, but a completed turn alone does not guarantee that every tool succeeded. Inspect execution results when using that path.

Run the same request with cURL

cURL is useful for checking credentials and network access independently of your SDK code. It is not a replacement for the Agents SDK runner shown above; use the SDK for the worked agent example.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl https://api.openai.com/v1/models 
  -H "Authorization: Bearer $OPENAI_API_KEY"

A successful response confirms that the key can reach the API. It does not validate your agent instructions or tool logic.

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

Troubleshooting

“ModuleNotFoundError: No module named agents”

The package is probably installed into a different interpreter. Activate the virtual environment, then run python -m pip install openai-agents and execute the script with that same python.

JavaScript cannot resolve @openai/agents

Run the command from the directory containing package.json and confirm that npm install @openai/agents zod completed. Check your project’s module mode if top-level import is rejected.

Authentication or missing-key errors

Check that OPENAI_API_KEY is set in the same shell that launches the program. Avoid surrounding the value with accidental whitespace, and verify that a secret manager or process supervisor is passing it through.

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

The output is empty or different from the example

Model responses are not guaranteed to match a sample. Print the complete result object while debugging, inspect the trace, and verify that your prompt and instructions are the ones actually loaded by the process.

A tool appears to succeed but the external action failed

Separate the model’s final prose from the tool’s execution result. Return structured success or error data from the tool, enforce timeouts and permissions, and inspect the trace before telling a user that the action completed.

Runs are slow or unexpectedly expensive

Keep the first instruction and prompt short, avoid unnecessary handoffs, and set limits appropriate to your application. Measure the trace for model and tool latency before optimizing. The official material used here does not establish a universal price or latency figure, so check the current platform documentation for your account.

Or skip the browser setup

If your agent needs website screenshots, ScreenshotNeo provides a website screenshot API and MCP server. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

One GET request is enough:

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 documentation for all options. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients, so an AI agent can request captures without your implementing browser automation. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up free.

Next steps

  1. Keep the one-agent example in a small test project.
  2. Inspect its trace and record the behavior you need.
  3. Add one narrowly scoped tool, then test success and failure results.
  4. Introduce a specialist handoff only when routing improves the task.
  5. Move secrets, authorization, logging, and rate controls into your application before production use.

Frequently Asked Questions

Can I use the Python and JavaScript SDK examples in the same project?

You can, but each example is a separate implementation. Choose the language that owns your application and follow that SDK’s installation and runner conventions.

Does defining an Agent make it autonomous?

No. The example runs one requested turn. Tools, handoffs, scheduling, persistence, and authorization must be designed and implemented explicitly.

Where should I look when an answer is wrong?

Start with the trace. It shows the model call and, once added, tool calls, handoffs, and guardrails, allowing you to distinguish prompt problems from execution failures.

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

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.