beginner15 min readGuide 1 of 12Updated Jun 15, 2025

Getting Started with Agents

Your first steps into the world of AI agent development. Understand what agents are, how they work, and build your first one.

Prerequisites

  • 1Basic Python or TypeScript knowledge
  • 2A terminal / command-line environment
  • 3An API key from OpenAI or Anthropic

What you will learn

  • What an AI agent is and how it differs from a chatbot
  • The core agent loop: Perceive, Reason, Act
  • How to choose a framework for your first project
  • How to install dependencies and run a hello-world agent

What Is an AI Agent?

An AI agent is a software system that uses a large language model (LLM) as its reasoning engine to autonomously perceive its environment, make decisions, and take actions to achieve a goal. Unlike a simple chatbot that responds to a single prompt, an agent operates in a loop — it observes, thinks, acts, and then observes again until the task is done.

Here is the simplest mental model:

while not done:
    observation = perceive(environment)
    thought     = reason(observation, memory)
    action      = decide(thought, available_tools)
    result      = execute(action)
    memory.update(result)

This loop is the beating heart of every agent framework. Whether you use LangGraph, CrewAI, or the OpenAI Agents SDK, the underlying principle is identical.

Agents vs Chatbots

It is important to understand the distinction between a chatbot and an agent:

FeatureChatbotAgent
InteractionSingle turn or multi-turn conversationAutonomous multi-step execution
Tool UseRarely uses external toolsActively calls APIs, databases, code interpreters
MemoryLimited to context windowCan persist state across sessions
Goal-DirectedResponds to user messagesWorks toward completing a defined objective
AutonomyLow — waits for user inputHigh — decides its own next steps

An agent can call tools, search the web, write and execute code, read files, and make decisions about what to do next without waiting for human input at every step.

Choosing a Framework

For your first agent, we recommend starting with one of these beginner-friendly options:

  • OpenAI Agents SDK — Best if you are already using OpenAI models. Minimal setup, well-documented.
  • Anthropic Claude Agent SDK — Deep MCP integration, strong safety features, supports Python and TypeScript.
  • Smolagents (Hugging Face) — Ultra-minimal, perfect for learning. Your agent writes and executes code to achieve goals.

For a detailed comparison, see the Choosing Your Stack guide.

Installing Dependencies

Python Setup

Set up a Python project with the OpenAI Agents SDK. You will need Python 3.10 or later.

# Create a project directory
mkdir my-first-agent && cd my-first-agent

# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install the OpenAI Agents SDK
pip install openai-agents

# Set your API key
export OPENAI_API_KEY="sk-..."

Alternatively, if you prefer Anthropic:

pip install anthropic
export ANTHROPIC_API_KEY="sk-ant-..."

TypeScript Setup

Prefer TypeScript? Set up a Node.js project with the Vercel AI SDK.

# Create a project directory
mkdir my-first-agent && cd my-first-agent

# Initialize the project
npm init -y

# Install the Vercel AI SDK with Anthropic provider
npm install ai @ai-sdk/anthropic zod

# Set your API key
export ANTHROPIC_API_KEY="sk-ant-..."

Hello World Agent

Python

Here is a minimal agent using the OpenAI Agents SDK. It creates an agent with a system prompt and runs it with a single task:

from agents import Agent, Runner

agent = Agent(
    name="Greeter",
    instructions="You are a helpful assistant. Answer concisely.",
)

result = Runner.run_sync(
    agent,
    "What are the three laws of robotics?"
)

print(result.final_output)

Run it:

python agent.py

TypeScript

Here is the same agent using the Vercel AI SDK with Anthropic:

import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

const { text } = await generateText({
  model: anthropic("claude-sonnet-4-20250514"),
  system: "You are a helpful assistant. Answer concisely.",
  prompt: "What are the three laws of robotics?",
});

console.log(text);

Run it:

npx tsx agent.ts

You should see the agent respond with Asimov's three laws. Congratulations — you have just built your first AI agent!

Both approaches manage the agent loop for you. Under the hood they send the prompt to the model, collect the response, check if any tool calls are needed, execute them, and loop until done.

Adding a Tool

Agents become powerful when they can use tools. Let us give our agent a simple calculator.

Python

from agents import Agent, Runner, function_tool

@function_tool
def calculate(expression: str) -> str:
    """Evaluate a math expression and return the result."""
    try:
        return str(eval(expression))
    except Exception as e:
        return f"Error: {e}"

agent = Agent(
    name="MathAgent",
    instructions="You are a helpful math assistant. Use the calculate tool for arithmetic.",
    tools=[calculate],
)

result = Runner.run_sync(agent, "What is 247 * 38 + 19?")
print(result.final_output)

TypeScript

import { generateText, tool } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { z } from "zod";

const { text } = await generateText({
  model: anthropic("claude-sonnet-4-20250514"),
  system: "You are a helpful math assistant. Use the calculate tool for arithmetic.",
  prompt: "What is 247 * 38 + 19?",
  tools: {
    calculate: tool({
      description: "Evaluate a math expression and return the result",
      parameters: z.object({
        expression: z.string().describe("The math expression to evaluate"),
      }),
      execute: async ({ expression }) => {
        try {
          return String(eval(expression));
        } catch (e) {
          return "Error: invalid expression";
        }
      },
    }),
  },
  maxSteps: 5,
});

console.log(text);

When the agent encounters an arithmetic question, it will call the calculate tool rather than attempting mental math. This is the essence of tool-augmented generation.

Security note: The eval() function is used here for simplicity. Never use eval() with untrusted input in production — it can execute arbitrary code. For production math evaluation, use a safe library like simpleeval (Python) or mathjs (JavaScript).

Next Steps

You now understand the agent loop and have a working agent with tool use. From here, you can:

Common Mistakes to Avoid

  • !Forgetting to set the API key environment variable before running the agent
  • !Giving the agent too broad of instructions — be specific about what it should and should not do
  • !Not handling tool errors — always return meaningful error messages from tools
  • !Using Python older than 3.10 which lacks required syntax features

Explore Related Content