Working memory helps an AI keep track of what it is doing right now. It stores important details so the AI can make good decisions step-by-step.
Working memory for current task state in Agentic AI
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Agentic AI
working_memory = {}
# Store info
working_memory['current_step'] = 'fetch_data'
# Update info
working_memory['current_step'] = 'process_data'
# Access info
current = working_memory.get('current_step')Working memory is often a simple dictionary or key-value store.
It holds temporary data that changes as the task progresses.
Examples
Agentic AI
working_memory = {}
working_memory['task'] = 'cleaning'
print(working_memory['task'])Agentic AI
working_memory = {'step': 1}
working_memory['step'] += 1
print(working_memory['step'])Agentic AI
working_memory = {}
if 'result' not in working_memory:
working_memory['result'] = None
print(working_memory['result'])Sample Model
This simple agent uses working memory to track its current step and data. It prints each step and the data it handles.
Agentic AI
class SimpleAgent: def __init__(self): self.working_memory = {} def perform_task(self): self.working_memory['step'] = 'start' print(f"Step: {self.working_memory['step']}") self.working_memory['step'] = 'fetch_data' print(f"Step: {self.working_memory['step']}") self.working_memory['data'] = [1, 2, 3] print(f"Data fetched: {self.working_memory['data']}") self.working_memory['step'] = 'process_data' processed = [x * 2 for x in self.working_memory['data']] self.working_memory['processed_data'] = processed print(f"Processed data: {processed}") self.working_memory['step'] = 'finish' print(f"Step: {self.working_memory['step']}") agent = SimpleAgent() agent.perform_task()
Important Notes
Working memory is temporary and resets after the task ends.
It helps the AI remember what happened recently without storing everything forever.
Good working memory design makes AI more flexible and easier to debug.
Summary
Working memory stores temporary task details for AI.
It updates as the task moves forward step-by-step.
This helps AI make decisions based on recent context.
Practice
1. What is the main role of working memory in an agentic AI system during a task?
easy
Solution
Step 1: Understand working memory function
Working memory holds temporary information needed right now for the task.Step 2: Compare options to definition
Only To temporarily store current task details for decision making correctly describes temporary storage for current task decisions.Final Answer:
To temporarily store current task details for decision making -> Option AQuick 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
Solution
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.Step 2: Analyze code options
working_memory = current_step assigns the current step directly, which matches replacing the current task state.Final Answer:
working_memory = current_step -> Option BQuick 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
Solution
Step 1: Trace the loop updating working memory
Loop sets working_memory to 'start', then 'process', then 'finish' in order.Step 2: Identify final value after loop
After the last iteration, working_memory holds 'finish'.Final Answer:
'finish' -> Option AQuick 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
Solution
Step 1: Check working_memory type
It is None, which is not a list and has no append method.Step 2: Understand append usage
append works only on list objects, so calling it on None causes an error.Final Answer:
working_memory is None and has no append method -> Option CQuick 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
Solution
Step 1: Identify need to store last two steps in order
We need a structure that keeps order and can hold multiple items.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.Final Answer:
Use a list and append new steps, removing oldest when length > 2 -> Option DQuick 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
