WikipediaQueryRunTool

WikipediaQueryRunTool(
    language: str = 'en',
    top_k: int = 3,
    verbose: bool = False
)

Tool for querying Wikipedia and returning summarized page results.
This tool uses the wikipediaapi package to perform searches against a specified language edition of Wikipedia and returns up to top_k page summaries.
Public methods:
query_run(query: str) -> list[str] | str

Attributes:
language (str): Language code for the Wikipedia edition (e.g., ‘en’, ‘es’).
top_k (int): Max number of page summaries returned (≤ MAX_PAGE_RETRIEVE).
verbose (bool): If True, enables debug logging to stdout.
wiki_cli (WikipediaClient): Internal client for Wikipedia API calls.
Initialize the WikipediaQueryRunTool.

Parameters:
NameDescription
languageType: str

Default: ‘en’
top_kType: int

Default: 3
verboseType: bool

Default: False

Instance Attributes

description



func



function_schema


Get the schema for the function.
This is the old way of handling function calls with OpenAI and compatible frameworks.
It is provided for backward compatibility.

name



realtime_tool_schema


Get the schema for the tool.
This is the preferred way of handling function calls with OpeaAI and compatible frameworks.

tool_schema


Get the schema for the tool.
This is the preferred way of handling function calls with OpeaAI and compatible frameworks.

Instance Methods

query_run

query_run(self, query: str) -> str | list[str]

Search Wikipedia and return formatted page summaries.
Truncates query to MAX_QUERY_LENGTH before searching.

Parameters:
NameDescription
querySearch term(s) to look up in Wikipedia.

Type: str
Returns:
TypeDescription
str | list[str]list[str]: Each element is “Page: <title> Summary: <text>”. str: Error message if no results are found or on exception. Note: Automatically handles API exceptions and returns error strings for robust operation

register_for_execution

register_for_execution(self, agent: ConversableAgent) -> 

Registers the tool for direct execution by a ConversableAgent.
This method registers the tool so that it can be executed by the agent, typically outside of the context of an LLM interaction.

Parameters:
NameDescription
agentThe agent to which the tool will be registered.

Type: ConversableAgent

register_for_llm

register_for_llm(self, agent: ConversableAgent) -> 

Registers the tool for use with a ConversableAgent’s language model (LLM).
This method registers the tool so that it can be invoked by the agent during interactions with the language model.

Parameters:
NameDescription
agentThe agent to which the tool will be registered.

Type: ConversableAgent

register_tool

register_tool(self, agent: ConversableAgent) -> 

Register a tool to be both proposed and executed by an agent.
Equivalent to calling both register_for_llm and register_for_execution with the same agent.
Note: This will not make the agent recommend and execute the call in the one step. If the agent recommends the tool, it will need to be the next agent to speak in order to execute the tool.

Parameters:
NameDescription
agentThe agent to which the tool will be registered.

Type: ConversableAgent