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.
- Open the
src/04-complex-problems/trucking-plan.py
script. - Locate the
user
message content: - 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."
- Run the script (
python trucking-plan.py
). - 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.
- Open the
src/04-complex-problems/trucking-execute.py
script. - Locate the
user_query
variable: - 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."
- Run the script (
python trucking-execute.py
). Ensurepytz
is installed (pip install pytz
). - Observe the verbose output (if enabled in the script, or by adding
verbose=True
torun_conversation
if needed). Does the LLM call theget_current_time
orcalculate_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:
- 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)
.
- Examples:
- Write down your list of DSL commands and their parameters.
- 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).
- 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 thesave_insights
action. - Suppose you want the agent to summarize the key findings in a short paragraph in addition to saving the detailed insights.
- How could you modify the agent's overall
task
description given to theAgent
class to include this summarization requirement? - 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?