Web Search Technical Reference
Complete technical reference for crocbot’s web search subsystem. Designed to be exhaustive for maintainers and extensible for adding new providers.Table of Contents
- Architecture Overview
- Supported Providers
- Configuration Schema
- Provider: Brave Search
- Provider: Perplexity Sonar
- Model Selection Logic
- API Key Resolution
- Caching Layer
- Tool Parameters
- Response Formats
- Error Handling
- Adding a New Provider
Architecture Overview
Source Files
Supported Providers
Configuration Schema
Full TypeScript definition fromsrc/config/types.tools.ts:
JSON Config Example (Complete)
Provider: Brave Search
Endpoint
Authentication
Request Parameters
Freshness Parameter
Validation regex:
/^(\d{4}-\d{2}-\d{2})to(\d{4}-\d{2}-\d{2})$/
Response Type
API Key Sources
Resolution order:tools.web.search.apiKey(config)BRAVE_API_KEY(environment variable)
Notes
- Use the “Data for Search” plan, NOT “Data for AI”
- Free tier available at https://brave.com/search/api/
freshnessparameter is Brave-exclusive (returns error for Perplexity)
Provider: Perplexity Sonar
Endpoints
Full endpoint:
{baseUrl}/chat/completions
Authentication
Request Body
Response Type
Available Models
API Key Sources
Resolution order (with source tracking):tools.web.search.perplexity.apiKey(config) → source:"config"PERPLEXITY_API_KEY(env) → source:"perplexity_env"OPENROUTER_API_KEY(env) → source:"openrouter_env"
Model Selection Logic
Current Behavior
The model is statically configured. There is no automatic selection based on query complexity.What This Means
The agent does NOT automatically escalate to
sonar-reasoning-pro for complex queries.
Manual Override Options
Users who want deep research must either:- Configure globally: Set
tools.web.search.perplexity.modelto"perplexity/sonar-reasoning-pro" - Create multiple agents: Configure different agents with different models
- Future enhancement: Implement query analysis to auto-select model (see Adding a New Provider)
Recommended Configuration by Use Case
API Key Resolution
Brave
Perplexity (with Base URL inference)
Base URL Resolution Matrix
Caching Layer
Constants
Cache Key Format
normalizeCacheKey(key).trim().toLowerCase()
Cache Entry Structure
Eviction Policy
- TTL-based expiration: Entries older than
cacheTtlMinutesare removed on read - LRU eviction: When cache reaches 100 entries, oldest entry is removed before insert
Cache Response Flag
Cached responses includecached: true in the result payload.
Tool Parameters
Schema Definition
Parameter Defaults
Response Formats
Brave Response
Perplexity Response
Cached Response
Any response can include"cached": true if served from cache.
Error Handling
Missing API Key
Invalid Freshness
Unsupported Freshness (Perplexity)
API Errors
Adding a New Provider
Step 1: Update Provider List
Insrc/agents/tools/web-search.ts:
Step 2: Add Config Types
Insrc/config/types.tools.ts:
Step 3: Add API Key Resolution
Step 4: Add Provider Handler
Step 5: Update Dispatcher
InrunWebSearch():
Step 6: Update Cache Key
Step 7: Add Missing Key Error
Step 8: Update Description
Step 9: Write Tests
Insrc/agents/tools/web-search.test.ts:
Step 10: Update Documentation
- Add
docs/tools/newprovider.md - Update
docs/tools/web.mdwith new provider option - Update this technical reference
Quick Reference
Environment Variables
Defaults Summary
Config Paths
TODO / Future Enhancements
- Dynamic model selection: Analyze query complexity to auto-select Perplexity model
- Hybrid search: Combine Brave structured results with Perplexity synthesis
- Google Custom Search: Add as alternative traditional search provider
- Bing Search: Add as alternative traditional search provider
- SearXNG: Add self-hosted meta-search option
- Query rewriting: Improve search quality with query expansion
Last updated: 2026-02-01
