Skip to content

Day 2 - Module 4: Exercises

These exercises are based on the concepts and code presented in Module 4: Solving Complex Problems with Tools & DSLs (src/04-complex-problems/).

Exercise 4.1: Modifying the Trucking DSL Plan

Goal: Observe how changing the input query affects the DSL plan generated by the LLM.

  1. Open the src/04-complex-problems/trucking-plan.py script.
  2. Locate the user message content:
    {"role": "user", "content": "I have a red box and 3 blue boxes..."},
    
  3. Modify the content to describe a different scenario. For example:
    • "I have 2 green boxes (10kg each) and 1 yellow box (5kg). Load them onto truck 1 and travel 250 km."
    • "Load 5 small packages (2kg each) onto truck 2. Calculate the total weight and then drive 50 km."
  4. Run the script (python trucking-plan.py).
  5. Analyze the output. Does the generated sequence of DSL commands (prepare_truck, load_box_on_truck, etc.) accurately reflect the new scenario you described?

Exercise 4.2: Triggering a Tool in the Trucking DSL Execution

Goal: Modify the input to encourage the LLM to use an available tool within the DSL execution flow.

  1. Open the src/04-complex-problems/trucking-execute.py script.
  2. Locate the user_query variable:
    user_query = "I have a red box and 3 blue boxes..."
    
  3. Modify the user_query to explicitly ask for information that requires a tool. For example:
    • "Load the red box (15kg) and blue box (8kg) onto truck 1. If the current time is before noon, travel 100 km. Otherwise, travel 50 km."
    • "Prepare truck 3. Load a 20kg package. Calculate the travel time for a 300 km journey and tell me the estimated arrival time based on the current time."
  4. Run the script (python trucking-execute.py). Ensure pytz is installed (pip install pytz).
  5. Observe the verbose output (if enabled in the script, or by adding verbose=True to run_conversation if needed). Does the LLM call the get_current_time or calculate_travel_time tool? Does the final output (DSL plan or natural language answer) incorporate the result from the tool?

Exercise 4.3 (Conceptual): Designing a Tea-Making DSL

Goal: Practice defining a Domain Specific Language for a simple, everyday process.

A Domain Specific Language (DSL) is a set of commands tailored for a specific task, allowing an agent (or human) to express complex instructions concisely. The trucking example uses a DSL for logistics. The diagram below shows how a DSL fits into the agent's process:

DSL Concept

  1. Imagine you want an agent to make a cup of tea. Define a set of simple commands (a DSL) that represent the necessary actions. * Think about the parameters each command needs.
    • Examples: boil_water(kettle_id), get_cup(cup_id), add_tea_bag(cup_id, tea_type), pour_water(kettle_id, cup_id), add_milk(cup_id, amount_ml), add_sugar(cup_id, spoons), wait(seconds), serve(cup_id).
  2. Write down your list of DSL commands and their parameters.
  3. Write a sample plan using your DSL commands to make a cup of black tea with milk and two sugars, letting it steep for 60 seconds.

Exercise 4.4 (Conceptual): Adding Summarization to Research Agent

Goal: Think about how to modify an existing agent task and add new capabilities (tools).

  1. Consider the do-research.py example (even if you couldn't run it due to dependencies). Its task is to research battery chemistry based on a taxonomy file and save insights to JSON using the save_insights action.
  2. Suppose you want the agent to summarize the key findings in a short paragraph in addition to saving the detailed insights.
  3. How could you modify the agent's overall task description given to the Agent class to include this summarization requirement?
  4. Would you need a new custom action (e.g., @controller.action("summarize_findings"))? If so, what would that action need to do? Could the summarization be handled by the LLM itself as part of its final response without a dedicated tool?