Lesson 07 Tool Use & Function Calling
Theme:

Homework — Tool Use

Three extended challenges to solidify your tool-use skills.

Work in a new notebook or Python script for each task. Submit your code and a brief write-up of what you observed.
TASK 1

File-System Personal Assistant

Build a Claude assistant that can manage files using real pathlib operations. Define three tools:

Use pathlib.Path for all operations. Add appropriate error handling (file not found, permission denied, etc.).

Test sequence

  1. Ask the assistant: "Create a file called hello.txt in /tmp/assistant_test/ with the content 'Hello from Claude!'"
  2. Ask: "List what's in /tmp/assistant_test/"
  3. Ask: "Read back the file you just created"

Verify that the file actually exists on disk after step 1 using your terminal or file explorer.

Safety note: Do not give the assistant a delete_file tool for this exercise. Limit writes to a sandboxed directory like /tmp/.
TASK 2

Mock Web Search Tool

Add a web_search(query) tool that returns plausible fake search results. Implement a dict-based lookup that returns 3 results for any query containing certain keywords:

MOCK_SEARCH_RESULTS = {
    "python": [
        {"title": "Python.org", "url": "https://python.org", "snippet": "Python is a high-level, interpreted language..."},
        {"title": "Python Tutorial - W3Schools", "url": "https://w3schools.com/python", "snippet": "Learn Python with examples and exercises..."},
        {"title": "Real Python", "url": "https://realpython.com", "snippet": "In-depth Python tutorials and articles..."},
    ],
    # Add entries for: "machine learning", "API", "database", "cloud", "security"
}

For queries not in your dict, return a generic set of plausible results.

Test

Ask Claude: "Research what Python is and give me a 3-sentence summary based on your search results." Verify Claude calls web_search before answering.

TASK 3

Parallel Tool Call Benchmark

Design a task that should trigger 5 independent tool calls and measure whether Claude executes them in parallel (1 round) or sequentially (5 rounds).

Suggested query

query = """
Using the calculator tool, compute these 5 results independently:
1. 123 * 456
2. 789 + 321
3. 1000 - 437
4. 96 / 4
5. 25 * 25

Report all 5 answers.
"""

Measurement

Instrument your tool loop to count tool calls per round:

round_stats = []  # list of (round_num, num_tool_calls)
# ... in your loop ...
round_stats.append((round_num, len(tool_calls_this_round)))

After the loop completes, print round_stats and answer:

Document your findings in a markdown cell. There is no single correct answer — the goal is to observe and understand the model's behaviour.