Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

AI Agents: State, Chat SDK, MCP Client, and Search Tools

How stateful AI agents work: the Agent class, chat and MCP channels, durable execution, and when to use hosted search APIs.

This page summarizes how major providers document AI agents: primarily the Cloudflare Agents SDK (stateful agents on Workers) and the Perplexity Agent API (hosted agent runs with built-in search and tools). It also notes where Brave Search API and Cloudflare AI Search fit when your agent must retrieve web or indexed content.

What an AI agent is in provider documentation

Section titled “What an AI agent is in provider documentation”

Cloudflare defines agents as programs that remember context, talk to users, and act without constant hand-holding:

Start building agents that can remember context, communicate with users, and act on their own. Pick the path that matches what you want to build first.

— Cloudflare, Getting started

The same docs position the Agent class as the central abstraction: an overview of the SDK with deeper pages per feature (Agent class).

Perplexity’s Agent API is documented as a quick path to multi-provider models, tools, and streaming—not as a replacement for your own runtime, but as a managed execution layer (Agent API Quickstart, Deep Research Workflows).

Common conclusion: “Agent” usually means state + channels + tools + model calls. Cloudflare gives you the runtime and wiring on Workers; Perplexity gives you a remote agent endpoint with search-oriented tools pre-integrated.

Agent class: server API, client SDK, and routing

Section titled “Agent class: server API, client SDK, and routing”

Cloudflare’s Routing guide covers naming and request patterns:

This guide explains how requests are routed to agents, how naming works, and patterns for organizing your agents.

Misconfigured names or duplicate agent IDs are a common reason clients connect to the wrong Durable Object instance.

The Agent class reference groups server features by concern. The table below is a reader’s map (not every method); follow the linked pages for signatures.

Feature area Representative methods Documentation focus
State setState(), onStateChanged(), initialState Store and sync state
RPC from clients @callable() decorator Callable methods
Scheduling schedule(), scheduleEvery(), listSchedules() Schedule tasks
Durable execution runFiber(), stash(), keepAliveWhile() Durable execution (linked from Agent class)
Queues queue(), dequeue(), getQueue() Queue tasks
Real-time onConnect(), onMessage(), broadcast() WebSockets (Agent class)
HTTP / SSE onRequest() HTTP and SSE (Agent class)
Email onEmail(), replyToEmail() Email agent example
Workflows runWorkflow(), waitForApproval() Using Agents with Workflows
MCP addMcpServer(), getMcpServers() MCP Client API
Sub-agents subAgent(), abortSubAgent() Sub-agents
Agents as tools runAgentTool(), hasAgentToolRun() Agents as tools

Client-side: useAgent, AgentClient, and chat hooks

Section titled “Client-side: useAgent, AgentClient, and chat hooks”

The same page lists client entry points—WebSocket AgentClient, HTTP agentFetch(), React useAgent(), and useAgentChat() for chat UIs (Client SDK next-steps links).

Module helpers such as agentTool() convert a Think or AIChatAgent subclass into an AI SDK tool definition (Agents as tools).

Getting started: first agent vs existing project

Section titled “Getting started: first agent vs existing project”

Cloudflare offers two onboarding paths:

After a working agent, docs point to the Client SDK, Agent class internals, and full Agents API reference.

Examples list end-to-end builds: chat, Slack, voice, browser, and email agents.

The Runtime docs split concerns into lifecycle, execution, and operations (Configuration, Cross-domain authentication, Tracing).

getCurrentAgent() (getCurrentAgent()) resolves the active agent inside handlers—useful when logic is split across modules.

MCP Client ties into persistence: the page explicitly points to Store and sync state for agent persistence when connecting tools.

Chat agents: AIChatAgent, persistence, and autonomous replies

Section titled “Chat agents: AIChatAgent, persistence, and autonomous replies”

Chat is the most documented channel:

Chat agents also notes building interfaces with AIChatAgent and useAgentChat.

For long-horizon designs, Think documents Sessions (context blocks, compaction, search), sub-agents, durable execution via runFiber(), and when to drop to full LLM control with AIChatAgent.

Workflows, webhooks, and durable AI agents

Section titled “Workflows, webhooks, and durable AI agents”

Using Agents with Workflows covers runWorkflow() implementation details. Build a Durable AI Agent links Agents SDK Workflows—AgentWorkflow, lifecycle callbacks, and bidirectional communication.

Webhooks and Push notifications extend agents beyond interactive chat; callable methods expose RPC-style endpoints for external systems.

Search: Perplexity Agent API tools vs Cloudflare AI Search vs Brave

Section titled “Search: Perplexity Agent API tools vs Cloudflare AI Search vs Brave”

Agents often need fresh or domain-specific facts. The cluster documents three different layers.

Perplexity Agent API (hosted tools and filters)

Section titled “Perplexity Agent API (hosted tools and filters)”

Start in the Agent API Playground to test parameters interactively.

Tooling pages include Fetch URL Content (“Fetch and extract content from specific URLs”) and vertical search tools such as Image Search, People Search, and Finance Search.

Agent API Filters documents domain, date range, and location filters; Academic and Scholarly Search extends filter reference for scholarly use cases.

Long runs use Background Mode:

Submit, poll, stream, and cancel long-running agent runs.

— Perplexity, Daily AI Stock News PDF with Skills

Related cookbooks: Daily News Digest with LLM Deduplication, Function Calling End-to-End, Structured Output Extraction, Streaming Citation Parsing.

Configuration extras: Profiles (versioned request profiles), Model Fallback, Effort, OpenAI Compatibility, Image Attachments, and Agent API Models (prompt guidance).

The Perplexity Search SDK is explicitly agents-first:

The SDK is agents-first: it is designed to be driven by coding agents, not learned from prose documentation. The canonical usage reference is the SDK’s Agent Skill, which covers installation, authentication, the full method surface, workflow patterns, and known pitfalls:

— Perplexity, Perplexity Search SDK

Cloudflare AI Search (your indexed knowledge)

Section titled “Cloudflare AI Search (your indexed knowledge)”

For agents that answer over your corpus, docs focus on the Search Workers binding and guides such as Talk to your knowledge base (chatCompletions() and search() from a Worker), Create a simple search engine, Search across multiple instances, Fetch and index single web pages (Items binding), and Bring your own generation model.

AI SDK describes building a stateful chat agent that searches your instance.

Brave Search API (web results as a service)

Section titled “Brave Search API (web results as a service)”

Brave Search API documentation centers on obtaining an API key and making a first request; Web Search covers the web search service surface. You typically call it from your agent code (e.g., a Cloudflare Worker agent or Perplexity tool pipeline), not as a full agent runtime.

Need Typical choice in this cluster
Stateful agent on your infra with WebSockets, email, MCP Cloudflare Agents SDK
Managed agent run with search tools, filters, background jobs Perplexity Agent API
RAG over documents you control Cloudflare AI Search
Raw web search JSON for custom tool implementation Brave Search API

Connect external systems with MCP Client API (addMcpServer(), etc.). For protected MCP servers, Handle OAuth with MCP servers starts with connecting without OAuth, then OAuth patterns.

Agents as tools lets one agent invoke another via runAgentTool()—useful for delegating research or specialized sub-agents (Sub-agents describes isolated AIChatAgent children with direct client routing).

Docs for agents lists per-agent setup (installation, skills, MCP, prompts, troubleshooting) if you are feeding documentation into coding agents.

Integrations and alternate runtimes (when not to start from zero)

Section titled “Integrations and alternate runtimes (when not to start from zero)”

Perplexity documents framework bridges—LangChain, LiteLLM, Mastra, LiveKit Agents, and others—each pointing to that framework’s agent docs.

Cloudflare lists voice (Voice agent), browser automation (Stagehand), OpenAI Apps SDK demos, and Orchestrator Models & Pricing on the Perplexity side for routing calls.

Use these when you already committed to a framework; otherwise start from Cloudflare Quick start or Perplexity Agent API Quickstart.

  1. Deploy or run the smallest path for your stack: Cloudflare Quick start or a first call via Agent API Quickstart / Agent API Playground.

  2. Confirm routing and identity: clients reach the intended agent instance (Routing; use getCurrentAgent() where helpers cross modules (getCurrentAgent())).

  3. For chat UIs, verify message persistence and response hooks (Chat agent example, Autonomous responses).

  4. For search behavior, exercise the right layer: Agent API tool docs (e.g. Fetch URL Content), Talk to your knowledge base, or a Brave Search API test request—and enable Tracing on Cloudflare where available.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page disagrees with the linked official docs, email yimasynthetic@gmail.com with the page URL and the exact sentence you believe is wrong so it can be corrected.