Agentic Challenges
Try these after completing all 5 agentic steps.
Knowledge Check
-
What is the difference between a regular LLM call and an agentic LLM call?
-
What does
tool_choice="auto"mean in the OpenAI API? -
Why do we limit the agent loop to a maximum number of turns?
-
What is the purpose of
tool_call_idin the tool response message? -
How does chain-of-thought prompting improve AI reasoning?
Code Challenges
Challenge 1: Write Tests First (TDD)
Practice test-driven development: write the test for the weather tool before you build the tool.
def test_get_weather_known_city():
from agent import get_weather
result = get_weather("Paris")
assert "°C" in result
def test_get_weather_unknown_city():
from agent import get_weather
result = get_weather("Atlantis")
assert "not available" in result
Run the tests — they will fail because get_weather doesn't exist yet. Now build the tool and make them pass.
Challenge 2: Weather Agent
Add a real weather tool that calls a free weather API (like wttr.in or OpenWeatherMap) instead of the mock get_weather function.
Hint: wttr.in doesn't need an API key:
response = requests.get(f"https://wttr.in/{city}?format=%C+%t")
Challenge 2: SQL Query Agent
Build a tool that lets the AI query the SQLite database directly:
def query_database(sql: str) -> str:
"""Execute a SQL query and return results."""
# Only allow SELECT statements for safety
...
Then test: "How many messages have I sent?" or "Show me all messages from today."
Challenge 3: Multi-Memory Agent
Add a "remember" and "forget" tool so the AI can store and recall facts across conversations:
User: "Remember that my name is Alice"
AI: "I'll remember that." (calls remember("name", "Alice"))
User: "What's my name?"
AI: "Your name is Alice." (calls recall("name") → "Alice")
Store memories in a dictionary or a simple JSON file.
Open-Ended Project: Custom Research Assistant
Build a research assistant that can:
- Search Wikipedia for background information
- Search a custom knowledge base (a JSON file with facts)
- Summarize findings into a report
- Save the report to a file
Requirements:
- Agent takes a topic as input
- Searches multiple sources
- Compiles a structured report with sections
- Saves the report to a .md file
Stretch goals: - Add a "generate image" tool using DALL-E - Add a "translate" tool using a translation API - Add a "send email" tool (mock) - Build a web UI for the research agent using Flask
Example flow:
User: "Research renewable energy and write a report"
1. search_wikipedia("Solar power") → summary
2. search_wikipedia("Wind power") → summary
3. search_wikipedia("Hydroelectric power") → summary
4. save_report("renewable-energy.md", report_text)
5. AI: "I've written a report on renewable energy to renewable-energy.md"