- Shell execution (e.g., Bash)
- Web search providers (Bing, custom search APIs)
- ChatGPT plugins
- Image generation (DALL·E)
- Cloud storage and document sources (Google Drive)
- Notification services (Twilio)
- Knowledge sources (Wikipedia, YouTube, Yahoo Finance)
- Human-in-the-loop tools (allowing workflows that prompt a human to act)
All of the above are available as Python modules you can import and use directly. Below we demonstrate the Wikipedia tool and how to call it.
Wikipedia tool: wrapper vs tool
The Wikipedia integration in LangChain is exposed in two layers:- A utility wrapper (e.g.,
WikipediaAPIWrapper) that handles fetching pages and returning text. - A tool wrapper (e.g.,
WikipediaQueryRun) that exposes aruninterface used by agents or programmatic calls.
top_k_results (how many search results to fetch) and doc_content_chars_max (limits the number of characters returned for each page). These let you balance coverage versus token usage when passing content to an LLM.
Parameter quick reference:
Minimal example: import, configure, inspect, and call
Here is a concise example that demonstrates how to import, configure, inspect metadata, and call the Wikipedia tool:run method with a dictionary whose key is the argument name ("query") and whose value is the search string. For example, to fetch the top summary for “Neural Network”:
result contains the text retrieved from Wikipedia (bounded by doc_content_chars_max).
The Wikipedia tool returns external content suitable for RAG workflows. Tune
top_k_results and doc_content_chars_max to control coverage and token consumption. Use the retrieved text as context to an LLM or to populate a retrieval index.The tool only retrieves content from Wikipedia; it does not call an LLM. Always validate returned facts and be mindful of freshness, attribution, and rate limits when using third-party content.
Practical notes and recommended patterns
- Retrieval-only: The Wikipedia tool fetches content only. To generate answers or reason over content, pass the retrieved text into an LLM chain, prompt, or an agent that calls the LLM.
- RAG integration: Combine multiple sources (Wikipedia + other knowledge sources) and index them in a vector store for more robust retrieval.
- Tool composition: Wrap the Wikipedia tool invocation in functions or chaining mechanisms (e.g., LCEL or LangChain chains) and combine it with other tools (search, calculators, or user prompts) for multi-step agents.
- Rate limits & caching: Respect Wikipedia API rate limits and consider caching frequently fetched pages to reduce network load and latency.
Links and references
- LangChain Integrations: https://docs.langchain.com
- Wikipedia: https://www.wikipedia.org
- DALL·E: https://openai.com/dall-e
- Bash: https://www.gnu.org/software/bash/
- Twilio: https://www.twilio.com