Skip to main content

Overview

Wikipedia tool allows you to search Wikipedia and retrieve article content. No API key required. The user asks a factual question; the agent searches Wikipedia and returns a summary.

Installation

pip install "praisonai[tools]"
No API key required!

Quick Start

1

Simple Usage

from praisonai_tools import WikipediaTool

# Initialize
wiki = WikipediaTool()

# Search
results = wiki.search("Python programming")
print(results)
2

With Configuration

Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.
Usage with Agent
from praisonaiagents import Agent
from praisonai_tools import WikipediaTool

agent = Agent(
    name="Researcher",
    instructions="You are a research assistant. Use Wikipedia to find information.",
    tools=[WikipediaTool()]
)

response = agent.chat("Tell me about quantum computing")
print(response)

Available Methods

search(query, max_results=5)

Search Wikipedia for articles.
from praisonai_tools import WikipediaTool

wiki = WikipediaTool()
results = wiki.search("machine learning", max_results=5)

# Returns:
# [{"title": "Machine learning"}, {"title": "Deep learning"}, ...]

get_page(title)

Get full Wikipedia page content.
page = wiki.get_page("Python (programming language)")

# Returns:
# {
#     "title": "Python (programming language)",
#     "url": "https://en.wikipedia.org/wiki/...",
#     "summary": "...",
#     "content": "...",
#     "categories": [...]
# }

summary(title, sentences=5)

Get a brief summary of an article.
summary = wiki.summary("Artificial intelligence", sentences=3)

# Returns:
# {"title": "Artificial intelligence", "summary": "..."}

Configuration Options

wiki = WikipediaTool(
    language="en"  # Wikipedia language (en, es, fr, de, etc.)
)

# For Spanish Wikipedia
wiki_es = WikipediaTool(language="es")

Function-Based Usage

from praisonai_tools import wikipedia_search

# Quick search without instantiating class
results = wikipedia_search("neural networks", max_results=3)

CLI Usage

# Use with praisonai (no API key needed)
praisonai --tools WikipediaTool "What is quantum computing according to Wikipedia?"

Error Handling

from praisonai_tools import WikipediaTool

wiki = WikipediaTool()
result = wiki.get_page("Some Ambiguous Term")

if "error" in result:
    if result["error"] == "Disambiguation":
        print(f"Multiple options: {result['options']}")
    else:
        print(f"Error: {result['error']}")
else:
    print(f"Title: {result['title']}")

Common Errors

ErrorCauseSolution
wikipedia not installedMissing dependencyRun pip install wikipedia
DisambiguationMultiple pages matchUse one of the returned options
Page not foundArticle doesn’t existCheck spelling or search first

Supported Languages

Use ISO language codes:
  • en - English
  • es - Spanish
  • fr - French
  • de - German
  • zh - Chinese
  • ja - Japanese
  • And many more…

How It Works


Best Practices

Wikipedia works without credentials — ideal for quick factual lookups.
When a title matches multiple pages, pick from the returned options instead of guessing.
Fetch summaries rather than full articles so the agent works with fewer tokens.

ArXiv

Academic papers

PubMed

Medical research

HackerNews

Tech news