{ "cells": [ { "cell_type": "markdown", "id": "0d4a77a4", "metadata": {}, "source": [ "# Building a One-Liner Research Agent\n", "\n", "Research tasks consume hours of expert time: market analysts manually gathering competitive intelligence, legal teams tracking regulatory changes, engineers investigating bug reports across documentation. The core challenge isn't finding information but knowing what to search for next based on what you just discovered.\n", "\n", "The Claude Agent SDK makes it possible to build agents that autonomously explore external systems without a predefined workflow. Unlike traditional workflow automations that follow fixed steps, research agents adapt their strategy based on what they find--following promising leads, synthesizing conflicting sources, and knowing when they have enough information to answer the question.\n", "\n", "## By the end of this cookbook, you'll be able to:\n", "\n", "- Build a research agent that autonomously searches and synthesizes information with a few lines of code\n", "\n", "This foundation applies to any task where the information needed isn't available upfront: competitive analysis, technical troubleshooting, investment research, or literature reviews.\n", "\n", "# Why Research Agents?\n", "\n", "Research is an ideal agentic use case for two reasons:\n", "\n", "1. **Information isn't self-contained**. The input question alone doesn't contain the answer. The agent must interact with external systems (search engines, databases, APIs) to gather what it needs.\n", "2. **The path emerges during exploration**. You can't predetermine the workflow. Whether an agent should search for company financials or regulatory filings depends on what it discovers about the business model. The optimal strategy reveals itself through investigation.\n", "\n", "In its simplest form, a research agent searches the web and synthesizes findings. Below, we'll build exactly that with the Claude Agent SDK's built-in web search tool in just a few lines of code.\n", "\n", "Note: You can also view the full list of [Claude Code's built-in tools](https://docs.claude.com/en/docs/claude-code/settings#tools-available-to-claude)" ] }, { "cell_type": "markdown", "id": "301fb086", "metadata": {}, "source": [ "# Prerequisites\n", "\n", "Before following this guide, ensure you have:\n", "\n", "**Required Knowledge**\n", "\n", "* Python fundamentals - comfortable with async/await, functions, and basic data structures\n", "* Basic understanding of agentic patterns - we recommend reading [Building effective agents](https://www.anthropic.com/engineering/building-effective-agents) first if you're new to agents\n", "\n", "**Required Tools**\n", "\n", "* Python 3.11 or higher\n", "* Anthropic API key [(get one here)](https://console.anthropic.com)\n", "\n", "**Recommended:**\n", "* Familiarity with the Claude Agent SDK concepts\n", "* Understanding of tool use patterns in LLMs\n", "\n", "\n", "## Setup\n", "\n", "First, install the required dependencies:" ] }, { "cell_type": "code", "execution_count": null, "id": "ab9830f9", "metadata": {}, "outputs": [], "source": "%%capture\n%pip install -U claude-agent-sdk python-dotenv" }, { "cell_type": "markdown", "id": "d88272cf", "metadata": {}, "source": [ "Note: Ensure your .env file contains:\n", "\n", "```bash\n", "ANTHROPIC_API_KEY=your_key_here\n", "```\n", "\n", "Load your environment variables and configure the client:" ] }, { "cell_type": "code", "execution_count": 2, "id": "c41abcdf", "metadata": {}, "outputs": [], "source": [ "from dotenv import load_dotenv\n", "\n", "load_dotenv()\n", "\n", "MODEL = \"claude-opus-4-6\"" ] }, { "cell_type": "markdown", "id": "041415b8", "metadata": {}, "source": [ "## Building Your First Research Agent\n", "\n", "Let's start with the simplest possible implementation: a research agent that can search the web and synthesize findings. With the Claude Agent SDK, this takes just a few lines of code.\n", "\n", "The key is the query() function, which creates a stateless agent interaction. We'll provide Claude with a single tool, WebSearch, and let it autonomously decide when and how to use it based on our research question." ] }, { "cell_type": "code", "execution_count": 3, "id": "b00890fb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "🤖 Using: WebSearch()\n", "🤖 Using: WebSearch()\n", "🤖 Using: WebSearch()\n", "✓ Tool completed\n", "✓ Tool completed\n", "✓ Tool completed\n", "🤖 Thinking...\n" ] } ], "source": [ "from utils.agent_visualizer import (\n", " display_agent_response,\n", " print_activity,\n", ")\n", "\n", "from claude_agent_sdk import ClaudeAgentOptions, query\n", "\n", "messages = []\n", "async for msg in query(\n", " prompt=\"Research the latest trends in AI agents and give me a brief summary and relevant citiations links.\",\n", " options=ClaudeAgentOptions(model=MODEL, allowed_tools=[\"WebSearch\"]),\n", "):\n", " print_activity(msg)\n", " messages.append(msg)" ] }, { "cell_type": "code", "execution_count": 4, "id": "e4556936", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
The AI agent market is experiencing explosive growth, nearly doubling from $3.7 billion (2023) to $7.38 billion (2025), with projections reaching $103.6 billion by 2032. According to PwC's 2025 survey, 79% of organizations have adopted AI agents, with 88% of executives piloting or scaling autonomous agent systems.
\n", "1. Rise of Multi-Agent Systems
\n",
"Instead of single AI systems trying to do everything, 2025 has introduced the \"orchestra approach\" where multiple specialized agents collaborate—one gathers research, another drafts reports, and a third reviews. Frameworks like CrewAI, AutoGen, and LangGraph are enabling this coordination across enterprise departments.
2. From Assistants to Autonomous Decision-Makers
\n",
"AI agents are evolving from knowledge assistants to self-directed workers that can take initiative, make decisions, and complete multi-step tasks without constant human input. By 2029, 80% of customer service issues are expected to be resolved entirely by autonomous agents.
3. Model Context Protocol (MCP)
\n",
"Anthropic's open standard provides a \"USB-C for AI\"—standardizing how language models connect with external systems, enabling structured multi-step workflows and access to real-time information.
4. Two-Speed Enterprise Landscape
\n",
"A divide is emerging: companies with existing automation are racing ahead with agentic AI, while others watch from the sidelines. Among highly automated enterprises, 50% have either adopted or are preparing to adopt autonomous agents.
The AI agent market is experiencing explosive growth, nearly doubling from $3.7 billion (2023) to $7.38 billion (2025), with projections reaching $103.6 billion by 2032. According to PwC's 2025 survey, 79% of organizations have adopted AI agents, with 88% of executives piloting or scaling autonomous agent systems.
\n", "1. Rise of Multi-Agent Systems
\n",
"Instead of single AI systems trying to do everything, 2025 has introduced the \"orchestra approach\" where multiple specialized agents collaborate—one gathers research, another drafts reports, and a third reviews. Frameworks like CrewAI, AutoGen, and LangGraph are enabling this coordination across enterprise departments.
2. From Assistants to Autonomous Decision-Makers
\n",
"AI agents are evolving from knowledge assistants to self-directed workers that can take initiative, make decisions, and complete multi-step tasks without constant human input. By 2029, 80% of customer service issues are expected to be resolved entirely by autonomous agents.
3. Model Context Protocol (MCP)
\n",
"Anthropic's open standard provides a \"USB-C for AI\"—standardizing how language models connect with external systems, enabling structured multi-step workflows and access to real-time information.
4. Two-Speed Enterprise Landscape
\n",
"A divide is emerging: companies with existing automation are racing ahead with agentic AI, while others watch from the sidelines. Among highly automated enterprises, 50% have either adopted or are preparing to adopt autonomous agents.
Let me search for the file in different locations:
Found it. Let me read the image:
This is a dumbbell chart (also called a connected dot plot) that compares the prevalence of different project types between two Anthropic products: Claude.ai (blue dots) and Claude Code (orange dots).
\n", "| Pattern | \n", "Implication | \n", "
|---|---|
| Claude Code dominates Startup Work | \n", "Developers building products at startups prefer the code-focused interface for rapid development | \n", "
| Claude.ai leads in educational contexts | \n", "The conversational nature of Claude.ai makes it more approachable for learning, research, and coursework | \n", "
| Personal Projects are universal | \n", "Both platforms serve individual developers working on side projects equally well | \n", "
| Enterprise usage is balanced | \n", "Both products have found their place in professional enterprise environments | \n", "
The chart reveals clear product differentiation:
\n",
"- Claude Code is preferred for active software development (startups, personal coding projects, open source)
\n",
"- Claude.ai excels in knowledge work and learning (tutorials, academic research, coursework)
This aligns with the nature of each product—Claude Code is a development tool while Claude.ai is a general-purpose AI assistant with a broader conversational interface.
Based on my research, here's how recent news and data validate or provide context for the chart analysis:
\n", "The chart showed Claude Code usage for Startup Work at 32.9% vs only 13.1% for Claude.ai—the largest gap in the data. Recent news strongly confirms this:
\n", "\n", "\n", "\"Startups are the main early adopters of Claude Code, suggesting that smaller, agile businesses are leveraging this AI tool to gain a technological advantage.\" - Blockchain News
\n", "
YC Startups as Case Studies:
\n",
"- HumanLayer (F24) - Built their entire platform with Claude Code
\n",
"- Ambral (W25) - Scaling AI-powered account management with sub-agent workflows
\n",
"- Vulcan Technologies (S25) - Using Claude Code for regulatory complexity
As noted by Anthropic's blog: \"Founders can now ship products directly from the terminal, compressing development cycles from weeks to hours.\"
\n", "The chart showed Claude.ai leading significantly in:
\n",
"- Tutorial or Learning: 12.2% (vs 0.7% for Claude Code)
\n",
"- Academic Research: 11.9% (vs 2.2%)
\n",
"- Coursework: 4.9% (vs 0.4%)
This aligns perfectly with Anthropic's dedicated education initiatives:
\n", "\n", "\n", "Anthropic launched \"Claude for Education\" with features like \"Learning Mode\" that uses Socratic questioning rather than giving direct answers. - VentureBeat
\n", "
Key Statistics from Anthropic's Education Report:
\n",
"- 39.3% of student conversations involve creating and improving educational content
\n",
"- 33.5% involve getting technical explanations for academic assignments
\n",
"- 57% of higher ed instructor chats involved developing curricula
\n",
"- 13% were conducting academic research
Early adopters include Northeastern University (50,000+ students across 13 campuses), London School of Economics, and Champlain College. - Anthropic Education Report
\n", "The chart showed Personal Projects and Startup Work (both development-heavy) as top uses for Claude Code (36% and 32.9%).
\n", "Anthropic's own research confirms:
\n", "\n", "\n", "\"About 44% of API traffic involved coding, compared with 36% on Claude.ai.\" - Anthropic Economic Index
\n", "\"Software development remains Claude's most common use case, making up more than a third of activity globally.\" - eWeek
\n", "
The chart's overall pattern showing Claude Code for development and Claude.ai for knowledge work is confirmed by Fortune:
\n", "\n", "\n", "\"ChatGPT is emerging increasingly as a personal or exploratory tool... while Claude is a more work-focused productivity tool, used heavily for coding, research, and business automation.\" - Fortune
\n", "
Automation patterns differ by platform:
\n",
"- 77% of API tasks are automated (full task delegation)
\n",
"- ~50% of Claude.ai tasks are automated (more collaborative)
The chart's findings fit into the larger industry trend:
\n", "| Metric | \n", "2025 Data | \n", "
|---|---|
| AI-generated/assisted code | \n", "41% of all code globally | \n", "
| Developers using AI coding assistants | \n", "82% daily or weekly | \n", "
| Market size projection | \n", "$30.1 billion by 2032 | \n", "
| Google's AI-assisted code | \n", "25% | \n", "
Source: AI Coding Assistant Statistics
\n", "The chart showed Enterprise Work relatively balanced (Claude.ai: 25.9%, Claude Code: 23.8%). This makes sense given:
\n", "The chart's findings are strongly validated by recent data:
\n", "| Chart Finding | \n", "Validation Status | \n", "
|---|---|
| Startups prefer Claude Code (32.9% vs 13.1%) | \n", "âś… Confirmed by Anthropic & YC case studies | \n", "
| Education favors Claude.ai (12.2% vs 0.7%) | \n", "âś… Confirmed by Anthropic Education Report | \n", "
| Personal projects lead both platforms | \n", "âś… Confirmed by usage statistics | \n", "
| Claude Code = development tool | \n", "âś… Confirmed (44% API traffic is coding) | \n", "
| Claude.ai = knowledge/learning tool | \n", "âś… Confirmed by education initiatives | \n", "
The Claude Code SDK (now renamed to Claude Agent SDK) is a toolkit from Anthropic that allows developers to build AI agents using the same infrastructure that powers Claude Code.
\n", "Key capabilities:
\n",
"- Context management - Automatic compaction to prevent running out of context
\n",
"- Rich tool ecosystem - File operations, code execution, web search, MCP extensibility
\n",
"- Fine-grained permissions - Control over agent capabilities
\n",
"- Production features - Error handling, session management, monitoring
Available in:
\n",
"- TypeScript (@anthropic-ai/claude-code)
\n",
"- Python (pip install claude-code-sdk)
\n",
"- Command line
It enables building agents for coding automation, customer support, personal assistants, and more—all using the same core systems that power Claude Code.
\n", "Sources:
\n",
"- Agent SDK overview - Claude Docs
\n",
"- Building agents with the Claude Agent SDK
\n",
"- Anthropic Releases Claude Code SDK - InfoQ
Anthropic is an American AI safety company founded in 2021 by former OpenAI executives, including siblings Dario and Daniela Amodei. The company builds Claude, a family of large language models, with a focus on creating reliable, interpretable, and safe AI systems. Anthropic is valued at approximately $183 billion and has received major investments from Amazon, Google, Microsoft, and NVIDIA. Its Claude Code product recently reached $1 billion in run-rate revenue.
\n", "Sources:
\n",
"- Anthropic - Wikipedia
\n",
"- Anthropic Homepage
\n",
"- What's Anthropic AI? - Voiceflow
Based on my previous search results, here are Anthropic's main products:
\n", "Claude - Their flagship AI assistant and family of large language models, which incorporates \"Constitutional AI\" for safety. Named after mathematician Claude Shannon.
\n", "Claude Code - A developer tool that recently reached $1 billion in run-rate revenue just six months after public launch.
\n", "Bun - A JavaScript runtime that Anthropic recently acquired to accelerate Claude Code's capabilities.
\n", "Anthropic offers Claude through their website, API access for developers, and enterprise solutions.
\n", "Sources:
\n",
"- Anthropic Homepage
\n",
"- Anthropic acquires Bun as Claude Code reaches $1B milestone