Skip to main content
This example demonstrates building a tool-based environment where models search Wikipedia to answer trivia questions. It showcases custom tool implementation, vector search with embeddings, and LLM-as-judge evaluation.

Overview

The Wiki Search environment provides:
  • Tools: Three custom Wikipedia search tools
  • Search: Semantic search using embeddings (ChromaDB + OpenAI)
  • Dataset: Wikipedia trivia questions
  • Evaluation: LLM judge for flexible answer matching
  • Format: Multi-turn tool use

Complete Implementation

Here’s the full working implementation from environments/wiki_search/wiki_search.py:

How It Works

1. Custom Tool Implementation

Three tools provide Wikipedia access: search_pages(query) - Semantic search for relevant articles
  • Uses embedding similarity (text-embedding-3-small)
  • Returns top 10 matching pages with IDs and titles
view_sections(page_id) - List sections of an article
  • Parses markdown headers to extract sections
  • Returns section IDs and names
read_section(section_id) - Read section content
  • Extracts text between markdown headers
  • Returns full content of the section

2. Vector Search with ChromaDB

Embedding-based search enables semantic matching:
Features:
  • Persistent storage (.chroma_db directory)
  • Lazy initialization (loads on first search)
  • Automatic upsert of missing pages
  • Concurrent access via semaphore (max 100 parallel)

3. LLM Judge Evaluation

JudgeRubric uses an LLM to evaluate answers:
Why judge evaluation?
  • Trivia answers have multiple valid phrasings
  • Example: “Barack Obama” = “Obama” = “Barack H. Obama”
  • Judge can handle paraphrasing and context

4. Tool Environment

ToolEnv provides tool calling capabilities:
The environment:
  • Extracts tool schemas from function signatures
  • Executes tool calls and returns results
  • Tracks tool usage metrics

Example Interaction

Question: Who painted the Mona Lisa?
Assistant: I’ll search for information about the Mona Lisa painting.Tool Call: search_pages("Mona Lisa painting")Tool Result:

Assistant: Let me view the sections of the Mona Lisa article.Tool Call: view_sections("mona_lisa")Tool Result:

Assistant: I’ll read the artist section.Tool Call: read_section("mona_lisa:artist")Tool Result:

Assistant: Based on the Wikipedia article, Leonardo da Vinci painted the Mona Lisa.Judge Evaluation: “yes”Result: ✓ Correct (reward = 1.0)

Running the Environment

Installation

Quick Evaluation

Custom Configuration

Configuration Options

Key Features

Tool Schema Generation

Verifiers automatically extracts tool schemas from Python functions:
Generated schema:

Concurrent Search with Semaphores

Manage concurrent ChromaDB access:
Prevents overwhelming the embedding API or ChromaDB.

Persistent Vector Storage

ChromaDB persists embeddings to disk:
  • First run: Embeds all Wikipedia titles (~slow)
  • Subsequent runs: Loads from .chroma_db/ (~fast)
  • Automatic incremental updates for new pages

Metrics Tracked

  • judge_reward: 1.0 if judge says “yes”, 0.0 otherwise
  • num_turns: Number of tool interactions
  • total_tool_calls: Total tools called
  • search_pages_calls: Number of search operations
  • view_sections_calls: Number of section list operations
  • read_section_calls: Number of section reads

Advanced Usage

Custom Wikipedia Corpus

Use your own Wikipedia subset:
Required format:

Different Embedding Models

Use alternative embedding models:

Custom Judge Prompts

Modify evaluation criteria:

Adding Tool Call Efficiency Rewards

Reward efficient tool usage:

Next Steps