0Pricing
AI Agents · Lesson

Common Tool Sets (Web, Calculator, RAG)

The starter toolbox: search the web, do math, query your knowledge base — covers 80% of demos.

Common Tool Sets (Web, Calculator, RAG) is a free AI Agents lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Starter Toolbox

Three tools cover 80% of agent demos:

  1. web_search — search the public web
  2. calculator — eval math expressions
  3. retrieve — search internal knowledge base (RAG)

Tool 1: Web Search

Use Tavily, Serper, or Brave Search API:

import requests

def web_search(query: str, k: int = 5):
    r = requests.post('https://api.tavily.com/search',
        json={'api_key': TAVILY_KEY, 'query': query, 'max_results': k})
    results = r.json()['results']
    return [
        {'title': r['title'], 'url': r['url'], 'snippet': r['content'][:300]}
        for r in results
    ]

Web Search Tool Schema

schema_search = {'type': 'function', 'function': {
    'name': 'web_search',
    'description': 'Search the public web. Use for current events or facts after the knowledge cutoff.',
    'parameters': {'type': 'object', 'properties': {
        'query': {'type': 'string', 'description': 'What to search for'},
        'k': {'type': 'integer', 'default': 5}
    }, 'required': ['query']}
}}
import json
print(json.dumps(schema_search, indent=2))

Tool 2: Calculator

Models cannot reliably do arithmetic in their head. A calculator tool fixes most numerical errors:

import math

ALLOWED = {k: getattr(math, k) for k in ['sqrt','log','exp','sin','cos','tan','pi','e']}

def calculator(expression: str) -> str:
    try:
        return str(eval(expression, {'__builtins__': {}}, ALLOWED))
    except Exception as e:
        return f'Error: {e}'

print(calculator('sqrt(16) + 2'))

Calculator Tool Schema

schema_calc = {'type': 'function', 'function': {
    'name': 'calculator',
    'description': 'Evaluate a math expression like 2 + 3 * sqrt(16). Use for any arithmetic.',
    'parameters': {'type': 'object', 'properties': {
        'expression': {'type': 'string'}
    }, 'required': ['expression']}
}}
import json
print(json.dumps(schema_calc, indent=2))

Tool 3: RAG / Knowledge Retrieval

from langchain_openai import OpenAIEmbeddings
from langchain_community.vectorstores import Chroma

store = Chroma(persist_directory='./db', embedding_function=OpenAIEmbeddings())

def retrieve(query: str, k: int = 4):
    docs = store.similarity_search(query, k=k)
    return [{'text': d.page_content, 'source': d.metadata.get('source')} for d in docs]

Retrieve Tool Schema

schema_retrieve = {'type': 'function', 'function': {
    'name': 'retrieve',
    'description': 'Search the internal knowledge base for company-specific information (policies, docs, history).',
    'parameters': {'type': 'object', 'properties': {
        'query': {'type': 'string'},
        'k': {'type': 'integer', 'default': 4}
    }, 'required': ['query']}
}}
import json
print(json.dumps(schema_retrieve, indent=2))

Tool 4: Code Interpreter (Bonus)

For data tasks, give the agent a Python sandbox:

def run_python(code: str) -> str:
    # Use a sandboxed environment (E2B, Firecracker, gVisor)
    return sandbox.run(code).stdout

Tool 5: HTTP Fetch (Bonus)

For fetching specific URLs (after web_search returns a promising link):

def fetch_url(url: str) -> str:
    r = requests.get(url, timeout=10)
    return BeautifulSoup(r.text, 'html.parser').get_text()[:5000]

Tool Description Tips

  • Say WHEN to use the tool, not just what it does
  • Mention typical inputs and outputs
  • Note limitations ("only works for English text", "5-second timeout")

Avoid Tool Overlap

Two tools with overlapping purposes confuse the model. If search_web and retrieve both "search", clarify in descriptions which one to use when.

Tool-Use Eval

Build a small test set with 50 questions: each has a "correct" tool to call. Run your agent; measure how often it picks the right tool. Hugely informative metric.

Hidden Tools

Some tools are useful but not always — show them only when relevant. E.g. refund_order only when the user is authenticated and asking about a refund.

Best Way to Improve Selection

Your agent is picking the wrong tool too often. What is the simplest fix?

Recap

The starter toolbox: web_search, calculator, retrieve. Build it, eval it, iterate on descriptions. This covers most early agent use cases.

Frequently asked questions

Is the “Common Tool Sets (Web, Calculator, RAG)” lesson free?

Yes — the full text of “Common Tool Sets (Web, Calculator, RAG)” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.

What will I learn in “Common Tool Sets (Web, Calculator, RAG)”?

The starter toolbox: search the web, do math, query your knowledge base — covers 80% of demos. You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AI Agents?

No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Common Tool Sets (Web, Calculator, RAG)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AI Agents lesson?

Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. ReAct: Reason + Act Pattern
  2. Implementing ReAct from Scratch
  3. Common Tool Sets (Web, Calculator, RAG)
  4. Detecting and Recovering from Tool Errors
← Back to AI Agents