Skip to content

🍳 Cookbook: Agentic Search Engine

Build an AI-powered search assistant that combines web search, scraping, and LLM summarization into a single intelligent API.

🎯 What You'll Build

A service that: 1. Searches the web (Brave, Google, Bing) 2. Scrapes relevant pages for full content 3. Uses AI to summarize findings with citations


πŸ—οΈ Phase 1: Clone & Setup

1. Get the Code

git clone https://github.com/traylinx/agentic-search-engines.git
cd agentic-search-engines

2. Install Dependencies

pip install -r requirements.txt

3. Configure Environment

cp .env.example .env
nano .env

Key Variables:

# LLM Configuration
LLM_MODEL=openai/gpt-oss-20b
LLM_SUMMARY_MODEL=llama-3.3-70b-versatile
TRAYLINX_BASE_URL=https://switchai.traylinx.com/v1

# Search Providers (get free keys)
BRAVE_API_KEY=your-brave-key
# Optional: GOOGLE_API_KEY, BING_API_KEY


πŸš€ Phase 2: Run the Service

python api.py
# Server running at http://localhost:8000

πŸ§ͺ Phase 3: Test the Flows

The complete orchestration: search β†’ scrape β†’ AI summarize.

curl -X POST http://localhost:8000/v1/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What are the latest trends in AI agents?",
    "flow": "agentic",
    "params": {
      "use_search": true,
      "providers": ["brave"]
    }
  }'

Response:

{
  "answer": "Based on my research, the latest trends in AI agents include...",
  "sources": [
    {"title": "...", "url": "https://..."},
    {"title": "...", "url": "https://..."}
  ]
}

Flow 2: Search Only

Just get raw search results without AI processing.

curl -X POST http://localhost:8000/v1/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Python async best practices",
    "flow": "search_only"
  }'

Flow 3: Scrape Only

Extract content from a specific URL.

curl -X POST http://localhost:8000/v1/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "extract main content",
    "flow": "scrap_only",
    "params": {
      "urls": ["https://example.com/article"]
    }
  }'

πŸ€– Phase 4: OpenAI-Compatible Chat

Use it like a drop-in replacement for ChatGPTβ€”with live web access!

curl -X POST http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "agentic-search",
    "messages": [
      {"role": "user", "content": "What is the weather in Tokyo right now?"}
    ]
  }'

The service automatically detects intent: - "Show me videos about X" β†’ Video search - "Extract text from URL" β†’ Web scraping - General questions β†’ Search + Summarize


πŸ” Phase 5: Enable A2A Authentication

To let other agents call your search service, add Sentinel auth.

1. Get Agent Credentials

From console.traylinx.com: - TRAYLINX_CLIENT_ID - TRAYLINX_CLIENT_SECRET

2. Add to .env

TRAYLINX_CLIENT_ID=ag-xxx
TRAYLINX_CLIENT_SECRET=ts-xxx
AUTH_SERVICE_URL=https://sentinel.traylinx.com/validate

3. Call as an Agent

curl -X POST http://localhost:8000/v1/search \
  -H "X-Agent-Secret-Token: your-token" \
  -H "X-Agent-User-Id: your-agent-id" \
  -H "Content-Type: application/json" \
  -d '{"query": "AI news", "flow": "agentic"}'

πŸ›οΈ Architecture Overview

          Request
             β”‚
             β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚ Intent Router β”‚ ← Detects: search/scrape/video/news
     β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”
     β–Ό               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Search  β”‚   β”‚  Scraper  β”‚
β”‚  Agent  β”‚   β”‚   Agent   β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
     β”‚              β”‚
     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
            β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚ LLM Summary β”‚ ← Generates cited answer
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“š Next Steps

  • Deploy to production with Docker
  • Add Redis caching for faster repeated queries
  • Integrate with your own agent via A2A tools