Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama XTools WebFetch

From Leeroopedia
Revision as of 13:28, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Ollama_Ollama_XTools_WebFetch.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Agent Loop, Web Integration
Last Updated 2025-02-15 00:00 GMT

Overview

Implements the web page fetching tool for the Ollama agent loop, retrieving and extracting text content from URLs via Ollama's hosted API.

Description

WebFetchTool implements the Tool interface. Execute validates the URL, constructs a JSON request body, signs it using the Ollama Ed25519 key (~/.ollama/id_ed25519) for authentication with the ollama.com/api/web_fetch endpoint, sends the request with a 30-second timeout, and formats the response (title + content). Requires cloud features to be enabled; returns an error if cloud is disabled. Authentication failures return ErrWebFetchAuthRequired.

Usage

Registered as the "web_fetch" tool. Allows the LLM agent to read the full content of web pages found through search results or provided by the user.

Code Reference

Source Location

  • Repository: Ollama
  • File: x/tools/webfetch.go
  • Lines: 1-167

Signature

const webFetchAPI = "https://ollama.com/api/web_fetch"
const webFetchTimeout = 30 * time.Second

var ErrWebFetchAuthRequired = errors.New("web fetch requires authentication")

type WebFetchTool struct{}

func (w *WebFetchTool) Name() string
func (w *WebFetchTool) Description() string
func (w *WebFetchTool) Schema() api.ToolFunction
func (w *WebFetchTool) Execute(args map[string]any) (string, error)

type webFetchRequest struct {
    URL string `json:"url"`
}

type webFetchResponse struct {
    Title   string   `json:"title"`
    Content string   `json:"content"`
    Links   []string `json:"links,omitempty"`
}

Import

import "github.com/ollama/ollama/x/tools"

I/O Contract

Inputs

Name Type Required Description
url string Yes The URL to fetch and extract content from

Outputs

Name Type Description
output string Formatted title and extracted text content
error error Auth required, cloud disabled, or HTTP errors

Usage Examples

tool := &tools.WebFetchTool{}

output, err := tool.Execute(map[string]any{
    "url": "https://example.com/article",
})
// output: "Title: Example Article\n\nContent:\n..."

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment