Manual wikipedia integration
Deja vu? It should feel familiar. We're building the Wikipedia integration now, with three tool functions this time. Watch how much code is copy-pasted from the arXiv integration.
def search_articles(topic: str, max_results: int = 5) -> List[str]:
"""Search for articles on Wikipedia based on a topic."""
search_results = wikipedia.search(topic, results=max_results)
articles_data = []
article_titles = []
for title in search_results:
try:
page = wikipedia.page(title)
articles_data.append({
"title": page.title,
"summary": page.summary[:500],
"url": page.url,
"content_length": len(page.content)
})
article_titles.append(page.title)
except (wikipedia.exceptions.DisambiguationError,
wikipedia.exceptions.PageError):
continue
# Save to disk...
return article_titles
def get_article_content(article_title: str) -> str:
"""Get the full content of a Wikipedia article."""
try:
page = wikipedia.page(article_title)
return page.content[:2000] + "..." \
if len(page.content) > 2000 else page.content
except wikipedia.exceptions.DisambiguationError as e:
return f"Disambiguation: {e.options[:5]}"
except wikipedia.exceptions.PageError:
return f"Page not found: {article_title}"Three tool functions for Wikipedia. Different API, same pattern.
Now the boilerplate. We need JSON schemas for all three Wikipedia functions. That's 57 lines of schema definitions. Then the same mapping dict. Then the same execute_tool dispatcher, copy-pasted from the arXiv file. Then the same LLM tool-call loop.
You could refactor the dispatcher and loop into a shared module. But the schemas are still hand-written per function, the mapping dict still needs updating for every new tool, and when you combine arXiv and Wikipedia in one app, you need to merge schemas, merge mappings, and handle routing. It is solvable, but you are basically building your own protocol at that point.
Wikipedia boilerplate scorecard: - Tool functions (actual logic): ~57 lines - JSON schemas: ~57 lines (3 tools this time) - Name-to-function mapping: ~5 lines - Execute dispatcher: ~18 lines (copy-pasted) - LLM tool-call loop: ~46 lines (copy-pasted) - Total glue code: ~126 lines We're at 2 integrations and already ~234 lines of glue code. The pattern is clear.
Quiz: Quiz
Loading practice…