Comma Agents
@comma-agents/coreToolsBuilt-in

webfetch

Fetch content from a URL and return it as markdown, plain text, or raw HTML.

The webfetch tool retrieves content from a URL and converts it into a format suitable for the agent to read. By default it returns markdown, which strips away navigation chrome and keeps the meaningful content of a page.

import { createAgent } from "@comma-agents/core";

const agent = createAgent({
  name: "researcher",
  model: "openai/gpt-4o",
  tools: ["webfetch"],
});

Parameters

The agent provides these parameters when invoking the tool:

ParameterTypeDescription
urlstringThe fully-qualified URL to fetch. Must be a valid URL.
format"markdown" | "text" | "html"?Output format. Defaults to "markdown".
timeoutnumber?Request timeout in seconds. Defaults to 30.

Format options

ValueDescription
"markdown"Converts HTML to Markdown. <script>, <style>, <noscript>, and <iframe> elements are stripped.
"text"Converts HTML to Markdown then strips remaining syntax, returning plain readable text.
"html"Returns the raw HTML response body without modification.

Behavior

  • Redirects are followed automatically.
  • If the response is not OK (status ≥ 400), the output is prefixed with [HTTP <status> <statusText>] so the agent knows the request did not succeed.
  • Content is truncated at 50,000 characters by default. A [Content truncated to N characters] notice is appended when truncation occurs.
  • The abort signal from the agent context is propagated — cancelling the agent also cancels the in-flight request.

Metadata

The tool returns the following metadata (not sent to the model):

FieldTypeDescription
urlstringThe original requested URL.
finalUrlstringThe URL after following any redirects.
statusCodenumberHTTP response status code.
contentTypestringValue of the Content-Type response header.
formatstringThe format used for this request.
durationMsnumberTotal request duration in milliseconds.
truncatedbooleanWhether the content was truncated.
originalLengthnumberThe full content length before truncation.

On this page