Bird
Raised Fist0
Agentic AIml~10 mins

Working memory for current task state in Agentic AI - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the working memory as an empty dictionary.

Agentic AI
working_memory = [1]
Drag options to blanks, or click blank then click option'
A0
B[]
CNone
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list [] instead of a dictionary {}
Setting working memory to None or 0 which cannot store state
2fill in blank
medium

Complete the code to add a key 'current_step' with value 1 to the working memory.

Agentic AI
working_memory[[1]] = 1
Drag options to blanks, or click blank then click option'
A'step'
B'current_step'
C'state'
D'task'
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic keys like 'step' or 'state' that are less clear
Forgetting to use quotes around the key string
3fill in blank
hard

Fix the error in updating the working memory to increment 'current_step' by 1.

Agentic AI
working_memory['current_step'] = working_memory['current_step'] [1] 1
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition
Using division which changes the value incorrectly
4fill in blank
hard

Fill both blanks to check if the 'task_complete' flag in working memory is True and print a message.

Agentic AI
if working_memory.get([1], False) [2] True:
    print('Task is complete')
Drag options to blanks, or click blank then click option'
A'task_complete'
B==
C!=
D'complete'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which checks for inequality
Using wrong key names like 'complete'
5fill in blank
hard

Fill all three blanks to create a function that resets the working memory keys 'current_step' to 0, 'task_complete' to False, and 'error_count' to 0.

Agentic AI
def reset_memory(memory):
    memory[[1]] = 0
    memory[[2]] = False
    memory[[3]] = 0
Drag options to blanks, or click blank then click option'
A'current_step'
B'task_complete'
C'error_count'
D'status'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong key names like 'status'
Assigning wrong values like True instead of False

Practice

(1/5)
1. What is the main role of working memory in an agentic AI system during a task?
easy
A. To temporarily store current task details for decision making
B. To permanently save all past tasks for future use
C. To delete irrelevant data immediately
D. To generate random outputs without context

Solution

  1. Step 1: Understand working memory function

    Working memory holds temporary information needed right now for the task.
  2. Step 2: Compare options to definition

    Only To temporarily store current task details for decision making correctly describes temporary storage for current task decisions.
  3. Final Answer:

    To temporarily store current task details for decision making -> Option A
  4. Quick Check:

    Working memory = temporary task info [OK]
Hint: Working memory = short-term task info storage [OK]
Common Mistakes:
  • Confusing working memory with long-term memory
  • Thinking it stores all past tasks permanently
  • Assuming it deletes data immediately
2. Which of the following code snippets correctly updates an AI agent's working memory with the latest task step stored in a variable current_step?
easy
A. working_memory.append(current_step)
B. working_memory = current_step
C. working_memory.update(current_step)
D. working_memory.add(current_step)

Solution

  1. Step 1: Identify working memory type

    Working memory holds the current task state, so it should be replaced, not appended or updated as a collection.
  2. Step 2: Analyze code options

    working_memory = current_step assigns the current step directly, which matches replacing the current task state.
  3. Final Answer:

    working_memory = current_step -> Option B
  4. Quick Check:

    Assign current step to working memory [OK]
Hint: Assign current step directly to working memory [OK]
Common Mistakes:
  • Using append on a non-list working memory
  • Calling update without a dict type
  • Using add which is not a list method
3. Given this Python code simulating working memory updates, what is the final value of working_memory after execution?
working_memory = None
steps = ['start', 'process', 'finish']
for step in steps:
    working_memory = step
print(working_memory)
medium
A. 'finish'
B. 'process'
C. 'start'
D. None

Solution

  1. Step 1: Trace the loop updating working memory

    Loop sets working_memory to 'start', then 'process', then 'finish' in order.
  2. Step 2: Identify final value after loop

    After the last iteration, working_memory holds 'finish'.
  3. Final Answer:

    'finish' -> Option A
  4. Quick Check:

    Last step assigned = 'finish' [OK]
Hint: Last loop assignment is final working memory value [OK]
Common Mistakes:
  • Thinking working_memory accumulates all steps
  • Confusing initial None with final value
  • Assuming print shows first step
4. This code tries to update working memory with the current task state but causes an error. What is the problem?
working_memory = None
current_step = 'step1'
working_memory.append(current_step)
medium
A. append requires two arguments
B. current_step is not defined
C. working_memory is None and has no append method
D. working_memory should be a string

Solution

  1. Step 1: Check working_memory type

    It is None, which is not a list and has no append method.
  2. Step 2: Understand append usage

    append works only on list objects, so calling it on None causes an error.
  3. Final Answer:

    working_memory is None and has no append method -> Option C
  4. Quick Check:

    NoneType has no append method [OK]
Hint: Check object type before using append [OK]
Common Mistakes:
  • Assuming append works on None
  • Thinking current_step is undefined
  • Believing append needs two arguments
5. An agentic AI uses working memory to track task progress. If the AI must remember the last two steps instead of just one, which data structure and update method best fit this need?
hard
A. Use a set to store steps, adding new steps without order
B. Use a string and overwrite with the latest step only
C. Use a dictionary with step names as keys and overwrite all keys each time
D. Use a list and append new steps, removing oldest when length > 2

Solution

  1. Step 1: Identify need to store last two steps in order

    We need a structure that keeps order and can hold multiple items.
  2. Step 2: Evaluate data structures

    List supports order and appending; removing oldest keeps size 2. String or set do not keep order or multiple recent steps properly.
  3. Final Answer:

    Use a list and append new steps, removing oldest when length > 2 -> Option D
  4. Quick Check:

    List + append + remove oldest = last two steps [OK]
Hint: Use list as queue to keep last two steps [OK]
Common Mistakes:
  • Using string which holds only one step
  • Using set which loses order
  • Using dict which overwrites keys