CrawlForge
HomePlaygroundUse CasesIntegrationsPricingDocumentationBlog
How to Use CrawlForge with OpenAI Agents SDK
Tutorials
Back to Blog
Tutorials

How to Use CrawlForge with OpenAI Agents SDK

C
CrawlForge Team
Engineering Team
April 13, 2026
8 min read
Updated April 14, 2026

On this page

OpenAI's Agents SDK provides a production-ready framework for building autonomous AI agents with tool use, handoffs, and guardrails. CrawlForge adds the missing piece: live web access. By connecting CrawlForge's 26 scraping tools to your OpenAI agents, you enable them to search the web, extract structured data, read documentation, and conduct multi-source research -- all within the Agents SDK's orchestration framework.

This guide shows you how to define CrawlForge tools as OpenAI agent functions and build agents that act on real-time web data.

Table of Contents

  • Prerequisites
  • Architecture: CrawlForge + OpenAI Agents
  • Step 1: Create the CrawlForge Tool Functions
  • Step 2: Build a Web Research Agent
  • Step 3: Add Structured Data Extraction
  • Advanced: Multi-Agent Web Pipeline
  • Credit Cost Breakdown
  • Best Practices
  • Next Steps

Prerequisites

Bash
pip install openai-agents
# or for the TypeScript/Node.js SDK:
npm install @openai/agents-sdk dotenv
Bash
# .env
OPENAI_API_KEY=sk-xxxxx
CRAWLFORGE_API_KEY=cf_live_xxxxx

Get your CrawlForge API key at crawlforge.dev/signup -- 1,000 free credits included.

Architecture: CrawlForge + OpenAI Agents

The OpenAI Agents SDK uses a tool pattern similar to the function calling API but with richer orchestration. You define tools as functions with JSON Schema parameters, and the agent decides when and how to call them.

User Query -> OpenAI Agent -> Tool Selection -> CrawlForge API -> Results -> Agent Response

CrawlForge's REST API at https://crawlforge.dev/api/v1/tools/ maps cleanly to the Agents SDK's tool definition format. Each tool becomes a function the agent can invoke.

Step 1: Create the CrawlForge Tool Functions

First, create a reusable CrawlForge client and tool definitions:

Typescript
// lib/crawlforge-tools.ts
import { tool } from '@openai/agents-sdk';
import { z } from 'zod';

const CRAWLFORGE_BASE = 'https://crawlforge.dev/api/v1/tools';

async function callCrawlForge(toolName: string, params: Record<string, unknown>) {
  const response = await fetch(`${CRAWLFORGE_BASE}/${toolName}`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.CRAWLFORGE_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(params),
  });

  if (!response.ok) {
    throw new Error(`CrawlForge error: ${response.status} ${response.statusText}`);
  }

  return response.json();
}

// Search the web (5 credits)
export const searchWebTool = tool({
  name: 'search_web',
  description: 'Search Google and return top results with titles, URLs, and snippets.',
  parameters: z.object({
    query: z.string().describe('Search query'),
    limit: z.number().default(5).describe('Max results to return'),
  }),
  execute: async ({ query, limit }) => {
    return callCrawlForge('search_web', { query, limit });
  },
});

// Extract page content (2 credits)
export const extractContentTool = tool({
  name: 'extract_content',
  description: 'Extract the main readable content from a web page URL.',
  parameters: z.object({
    url: z.string().url().describe('Full URL to extract content from'),
  }),
  execute: async ({ url }) => {
    return callCrawlForge('extract_content', { url });
  },
});

// Structured scraping (2 credits)
export const scrapeStructuredTool = tool({
  name: 'scrape_structured',
  description: 'Extract structured data from a web page using CSS selectors.',
  parameters: z.object({
    url: z.string().url().describe('URL to scrape'),
    selectors: z.record(z.string()).describe('Map of field names to CSS selectors'),
  }),
  execute: async ({ url, selectors }) => {
    return callCrawlForge('scrape_structured', { url, selectors });
  },
});

// Fetch raw URL (1 credit)
export const fetchUrlTool = tool({
  name: 'fetch_url',
  description: 'Fetch raw HTML content from a URL. Cheapest option for simple retrieval.',
  parameters: z.object({
    url: z.string().url().describe('URL to fetch'),
  }),
  execute: async ({ url }) => {
    return callCrawlForge('fetch_url', { url });
  },
});

Step 2: Build a Web Research Agent

Create an agent that uses CrawlForge tools to research topics:

Typescript
// agents/researcher.ts
import { Agent, run } from '@openai/agents-sdk';
import {
  searchWebTool,
  extractContentTool,
  scrapeStructuredTool,
} from '../lib/crawlforge-tools';

const researchAgent = new Agent({
  name: 'Web Researcher',
  model: 'gpt-4o',
  instructions: `You are a thorough web researcher. When asked about a topic:
1. Search the web for relevant, recent sources
2. Read the top 2-3 results to gather comprehensive information
3. Synthesize findings into a clear, cited summary
4. Always mention the URLs you sourced data from

Use search_web to find sources, then extract_content to read them.
Prefer extract_content over fetch_url when you need readable text.`,
  tools: [searchWebTool, extractContentTool, scrapeStructuredTool],
});

// Run the agent
async function research(topic: string) {
  const result = await run(researchAgent, {
    messages: [{ role: 'user', content: topic }],
  });

  console.log(result.finalOutput);
  return result;
}

// Example usage
await research('What are the latest trends in web scraping regulation in 2026?');

The agent will autonomously:

  1. Call search_web to find relevant articles (5 credits)
  2. Call extract_content on the top results (2 credits each)
  3. Synthesize a cited summary

Step 3: Add Structured Data Extraction

Build a data extraction agent that pulls specific fields from web pages:

Typescript
// agents/extractor.ts
import { Agent, run } from '@openai/agents-sdk';
import { scrapeStructuredTool, fetchUrlTool } from '../lib/crawlforge-tools';

const extractorAgent = new Agent({
  name: 'Data Extractor',
  model: 'gpt-4o',
  instructions: `You are a data extraction specialist. When given a URL and a data request:
1. Determine the best CSS selectors to extract the requested data
2. Use scrape_structured to pull the data
3. Return the results in clean JSON format

For simple JSON APIs, use fetch_url instead (it costs 1 credit vs 2).`,
  tools: [scrapeStructuredTool, fetchUrlTool],
});

async function extractData(url: string, description: string) {
  const result = await run(extractorAgent, {
    messages: [{
      role: 'user',
      content: `Extract from ${url}: ${description}`,
    }],
  });

  return result.finalOutput;
}

// Extract pricing data
await extractData(
  'https://stripe.com/pricing',
  'All plan names, prices, and key features'
);

Advanced: Multi-Agent Web Pipeline

The Agents SDK supports handoffs between specialized agents. Build a pipeline where a researcher finds sources and hands off to an analyst:

Typescript
// agents/pipeline.ts
import { Agent, run } from '@openai/agents-sdk';
import {
  searchWebTool,
  extractContentTool,
  scrapeStructuredTool,
} from '../lib/crawlforge-tools';

const collectorAgent = new Agent({
  name: 'Data Collector',
  model: 'gpt-4o',
  instructions: `You collect raw data from the web. Search for sources,
extract their content, and pass the raw data to the analyst.
Focus on gathering data, not analyzing it.`,
  tools: [searchWebTool, extractContentTool, scrapeStructuredTool],
  handoff_description: 'Collects raw web data for analysis',
});

const analystAgent = new Agent({
  name: 'Data Analyst',
  model: 'gpt-4o',
  instructions: `You analyze data collected by the Data Collector.
Identify patterns, compare data points, and produce actionable insights.
Always structure your output with clear sections and data tables.`,
  tools: [], // No web tools needed -- works with collected data
  handoffs: [collectorAgent], // Can request more data if needed
});

const orchestrator = new Agent({
  name: 'Research Orchestrator',
  model: 'gpt-4o',
  instructions: `You manage research projects. Delegate data collection to
the Data Collector and analysis to the Data Analyst. Ensure the final
output answers the user's question completely.`,
  handoffs: [collectorAgent, analystAgent],
});

// Run the multi-agent pipeline
const result = await run(orchestrator, {
  messages: [{
    role: 'user',
    content: 'Compare the pricing and features of the top 3 web scraping APIs in 2026',
  }],
});

console.log(result.finalOutput);

This pipeline separates concerns: the collector gathers data (using CrawlForge credits), and the analyst processes it (no credits needed). Total cost depends on sources fetched -- typically 15-25 credits for a 3-source comparison.

Credit Cost Breakdown

Agent WorkflowTools UsedEstimated Credits
Single search + summarysearch_web + extract_content7
3-source researchsearch_web + 3x extract_content11
Structured extraction (1 page)scrape_structured2
Multi-agent comparison (3 sources)search_web + 3x extract_content + scrape_structured15
Deep research reportdeep_research10

The CrawlForge Free tier (1,000 credits) supports roughly 90 search-and-extract workflows per month. The Professional plan ($99/month, 50,000 credits) handles production agent workloads.

Best Practices

Choose the cheapest tool first. The agent's instructions should guide it toward fetch_url (1 credit) when full HTML is acceptable, and extract_content (2 credits) only when clean text is needed. Reserve deep_research (10 credits) for complex multi-source queries.

Limit agent steps. Set a maximum number of tool invocations to control costs. Most research tasks complete in 3-5 tool calls.

Use handoffs for complex pipelines. Rather than one agent with many tools, split responsibilities. The collector agent handles web access (credits), while the analyst agent processes data (no credits).

Cache tool outputs. If your agent repeatedly accesses the same URL, implement response caching to avoid duplicate credit charges.

Monitor usage. Check your credit consumption in the CrawlForge dashboard and set alerts for unexpected spikes.

Next Steps

You now have OpenAI agents that can access live web data. Continue building:

  • 26 CrawlForge tools overview -- register more tools for your agents
  • Stealth mode scraping -- access sites with anti-bot protection
  • Deep research automation -- use the 10-credit deep_research tool for comprehensive reports
  • CrawlForge Quick Start -- full MCP setup guide

Give your OpenAI agents eyes on the web. Start free with 1,000 credits -- no credit card required.

Try this yourself — no signup needed

Run any of CrawlForge's 27 scraping and extraction tools in the playground, then start free with 1,000 credits.

1,000 free credits • Refills monthly • No credit card required

Tags

openaiagents-sdkintegrationweb-scrapingai-agentstutorialfunction-calling

About the Author

C

CrawlForge Team

Engineering Team

Building the most comprehensive web scraping MCP server. We create tools that help developers extract, analyze, and transform web data for AI applications.

Stay updated with the latest insights

Get tutorials, product updates, and web scraping tips delivered to your inbox.

No spam. Unsubscribe anytime.

Put this into practice

Test CrawlForge's tools on any URL — free, no signup.

On this page

Related Articles

How to Use CrawlForge with LangGraph Agents
Tutorials

How to Use CrawlForge with LangGraph Agents

Build stateful web scraping agents with LangGraph and CrawlForge. TypeScript guide covering graph nodes, state management, and conditional scraping flows.

C
CrawlForge Team
|
Apr 24
|
8m
How to Use CrawlForge with Mastra AI Agents
Tutorials

How to Use CrawlForge with Mastra AI Agents

Build AI agents with web scraping capabilities using Mastra and CrawlForge. TypeScript setup guide with tool integration, workflows, and agent examples.

C
CrawlForge Team
|
Apr 21
|
7m
How to Give ChatGPT Web Scraping with MCP Connectors (2026)
Tutorials

How to Give ChatGPT Web Scraping with MCP Connectors (2026)

Connect ChatGPT to web scraping with custom MCP connectors -- why CrawlForge needs a remote wrapper, the FastMCP bridge to build, and how to add it in ChatGPT.

C
CrawlForge Team
|
Jun 16
|
11m

Footer

CrawlForge

Enterprise web scraping for AI Agents. 27 specialized MCP tools designed for modern developers building intelligent systems.

Product

  • Features
  • Playground
  • Pricing
  • Use Cases
  • Integrations
  • Alternatives
  • Changelog

Resources

  • Getting Started
  • API Reference
  • Templates
  • Guides
  • Blog
  • Glossary
  • FAQ
  • Sitemap

Developers

  • MCP Protocol
  • Claude Desktop
  • Cursor IDE
  • LangChain
  • LlamaIndex

Company

  • About
  • Contact
  • Privacy
  • Terms
  • Acceptable Use
  • Cookies

Stay updated

Get the latest updates on new tools and features.

Built with Next.js and MCP protocol

© 2025-2026 CrawlForge. All rights reserved.