Back to Introduction to Agentic AI
Lesson 3
25 min

Building Your First Agent

Hands-on tutorial to create a simple autonomous agent.

Building Your First Agent

Let's build a simple research agent that can search the web and summarize findings.

Prerequisites

  • Node.js 18+
  • OpenAI API key
  • Basic TypeScript knowledge

Step 1: Setup

npm install ai @ai-sdk/openai

Step 2: Define Tools

const tools = {
  searchWeb: {
    description: 'Search the web for information',
    parameters: z.object({
      query: z.string(),
    }),
    execute: async ({ query }) => {
      // Implementation
      return results
    },
  },
}

Step 3: Create the Agent

import { generateText } from 'ai'

const result = await generateText({
  model: 'openai/gpt-4.1',
  prompt: 'Research the latest developments in quantum computing',
  tools,
  maxSteps: 5,
})

What's Happening?

The agent will:

  1. Analyze the goal
  2. Decide to use the searchWeb tool
  3. Execute searches
  4. Synthesize findings
  5. Return a comprehensive summary

This is your first autonomous agent!

    Building Your First Agent | Introduction to Agentic AI | AgenticAI.dk | AgenticAI.dk