Session 1

Session 1#

This session will provide an introduction to the course and, specifically, topic of agents, broadly covering different perspectives from cognitive science and AI on what constitutes an agent. The course topic is put into perspective of recent developments in AI, and, in particular, the development of recent large language models (LLMs).

Slides from the first lecture can be found here.

The discussion of the day will be on the paper by Chu, Tenenbaum & Schulz (2024). In praise of folly: flexible goals and human cognition.

Exercises#

Below are some questions to recap and apply central concepts of the first session. Please try answer them for yourself. Further, exercises to familiarize yourself with using the university compute and recap using LLMs.

Your solutions and questions about the exercises will be discussed at the end of the session.

Exercise 1.1.: What are agents?

  1. What properties (supplied by different definitions) does a thermostat have that could be considered properties of an agent?

  2. Consider a travel planning agent that has access to a traveling database and interacts with users via natural language. Provide a description of the agent using the BDI framework.

  3. Which of the following entities do you think should be described with intentional terms? Why? Swarm of bees, a vacuuming robot, a three-year-old child

  4. Assign the reasoning type that might be predominantly employed to solve each of the following problems. Briefly explain your choices. Solving a legal case, choosing which car to buy, reading a tweet, choosing which chocolate to buy, parking a car, replying to a friend when they sneezed

  5. Why is knowledge required for taking goal-directed actions? Explain in 2-3 sentences.

  6. What are some differences between human goals and the goals of a vacuuming robot? Name two.

Click below to see suggested solutions. Note that these and all other solutions are by no means exhaustive or the only right answer.

  1. What properties (supplied by different definitions) does a thermostat have that could be considered properties of an agent?

    1. reactivity (to changes in environment, output respectively)

    2. autonomy within the task of keeping temperature constant

    3. arguably, has intention / goal of keeping the temperature constant

    4. representation of the state of the world (i.e., current temperature)

  2. Consider a travel planning agent that has access to a traveling database and interacts with users via natural language. Provide a description of the agent using the BDI framework.

    1. beliefs: database of travel information, text query provided by the user

    2. world knowledge needed; DB has to be uptodate and complete

    3. desire: finding satisfactory answer that will elicit some done-signal from user, or e.g. booking a trip

    4. intention: e.g. refine user query, search the database to satisfy request, loop over communicating to user when no further steps can be taken and search databse again

    5. NLU / NLG module might be seen as a mechanism that leads to belief updating

  3. Which of the following entities do you think should be described with intentional terms? Why? Swarm of bees, a vacuuming robot, a three-year-old child

    1. three year old child → yes, has creative goals and play, goal-directed actions

    2. vacuuming robot → can be, but maybe not necessary b/c mechanistic description suffices (narrow task)

    3. swarm of bees → maybe not necessary, but nonetheless one could use intentional terms as they are considered intelligent entities under different views of intelligence (collective intelligence view: goal-directed behavior, reactive, rationality, some knowledge representation (e.g., where flowers are), swarm decides where to go and build things; individual view: focused on survival, but no individual complex decision making / reasoning)

  4. Assign the reasoning type that might be predominantly employed to solve each of the following problems. Briefly explain your choices.

    • Solving a legal case (S2)

    • choosing which car to buy (S2)

    • reading a tweet (S1)

    • choosing which chocolate to buy (S1, but could also be S2)

    • parking a car (S1 if proficient or easy situation, S2 otherwise)

    • replying to a friend when they sneezed (S1, maybe S2 if foreign language)

  5. Why is knowledge required for taking goal-directed actions? Explain in 2-3 sentences.

    1. knowledge as basis for reasoning in various forms; even S1-based actions are formed on the basis of some for of experiences, learned

  6. What are some differences between human goals and the goals of a vacuuming robot? Name two.

    1. robot: specified by developers, humans: self-imposed

    2. robot: strictly utility maximizing, no distinction b/w short and long term, humans: might pursue goals that are useful in the sense of abstraction and intrinsic reward, or expected reward for long-term goals

Using bwJupyter#

If you signed up for accessing compute provided through the KIT university, the following steps should guide you through accessing their Jupyter server. If you did not sign up for access, you can launch this notebook in Google Colab by clicking the rocket icon > Colab at the top of this page.

Accessing bwJupyter:

  1. Navigate to https://jupyter-test.scc.kit.edu

  2. Sign in using your university SSO.

  3. If you intend running LMs, select “GPU Jupyter”

  4. Once you are on the landing page of the Jupyter server, you can either clone this repo to access the notebook from there, or just download this notebook (via button on top of the page) and upload it to the server.

  5. Use the Jupyter notebook functionality as usual! The GPU should be available by default.

  6. Some packages like torch are already pre-installed. Additional packages can be installed, e.g., by running !pip install <package> in a cell.

  7. Each user should have 8GB RAM and 20 GB hard drive space, so please be mindful of the resources!

Using Google Colab:

Colab is a platform provided by Google for free, and it also provides limited access to GPU computation (which will be useful for working with language models). Using it only requires a Google account.

For using a GPU on Colab, before executing your code, navigate to Runtime > Change runtime type > GPU > Save. Please note that the provided Colab computational resources are free, so please be mindful when using them. Further, Colab monitors GPU usage, so if it is used a lot very frequently, the user might not be able to access GPU run times for a while.

Colab already provides Python as well as a number of basic packages. If you choose to use it, you will only need to install the more specific packages. Note that you will have to so every time you open a new Colab runtime.

The following basic exercises are to recap the use of pretrained LLMs via the transformers library and get a feeling for LLMs’ capabilities when it comes to properties of agents. Please make sure to read through the following code and tasks carefully and make sure you understand all the terms and what the code does.

Exercise 1.2.: Testing properties of LLMs

  1. Comment the code below.

  2. Generate responses to a few prompts of your choice. Play around with the decoding temperature.

  3. Try to constructs prompts describing a) System 1 and b) System 2 style reasoning c) a BDI style model (i.e., come up with some beliefs, desire and intention to prompt the model with). Prompt the model to solve the following tasks:

  • solve a mathematical equation

  • request to make a coffee

  • check a sentence with grammatical mistakes

Do you see any differences? How robust is the model across variations of the prompt? Try your best to construct prompts that will lead to interesting differences.

  1. Previous work has shown that LLMs exhibit content effects in reasoning, like humans. Look at Figure 1 in this paper and test the LLM we are working with on the consistent and inconsistent versions of the NLI and syllogism tasks. Are there content effects? Can you modify the prompt (e.g., add (made-up) facts about the world) so as to change the results?

  2. Construct a prompt with a description of a small physical environment (e.g., describe a room in your home). Prompt the LM to describe the solution for navigating the environment with a particular goal (e.g., get an item). How does the model do? Does it help to deconstruct the task into simpler tasks for the model?

# uncomment the following lines to install the required packages (installing in one command seems to lead to some dependency errors)
# !pip install transformers
# !pip install accelerate bitsandbytes
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "Qwen/Qwen2.5-7B-Instruct"

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto",
    load_in_4bit=True
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "Albert, please."
messages = [
    {"role": "system", "content": "You are a helpful assistant named Albert."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]

print(response)