Homework — Tool Use
Three extended challenges to solidify your tool-use skills.
File-System Personal Assistant
Build a Claude assistant that can manage files using real pathlib operations. Define three tools:
- read_file(path) — reads and returns the content of a text file
- write_file(path, content) — writes content to a file, creating parent directories if needed
- list_directory(path) — returns a formatted list of files and subdirectories at the given path
Use pathlib.Path for all operations. Add appropriate error handling (file not found, permission denied, etc.).
Test sequence
- Ask the assistant: "Create a file called
hello.txtin/tmp/assistant_test/with the content 'Hello from Claude!'" - Ask: "List what's in
/tmp/assistant_test/" - 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.
delete_file tool for this exercise. Limit writes to a sandboxed directory like /tmp/.
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.
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:
- How many rounds did the loop run?
- Were all 5 calls made in one round, or spread across multiple?
- Does rephrasing the query (e.g. making independence more explicit) change the behaviour?
Document your findings in a markdown cell. There is no single correct answer — the goal is to observe and understand the model's behaviour.