0
0
Prompt Engineering / GenAIml~10 mins

Why agents make autonomous decisions in Prompt Engineering / GenAI - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an agent that makes decisions without human input.

Prompt Engineering / GenAI
class Agent:
    def __init__(self):
        self.state = None

    def decide(self, environment):
        return [1]
Drag options to blanks, or click blank then click option'
Aprint('Hello World')
Benvironment.get_best_action()
Cself.state = None
Dreturn None
Attempts:
3 left
💡 Hint
Common Mistakes
Returning None instead of an action.
Using print statements instead of returning an action.
2fill in blank
medium

Complete the code to update the agent's state after taking an action.

Prompt Engineering / GenAI
class Agent:
    def __init__(self):
        self.state = None

    def update_state(self, action):
        self.state = [1]
Drag options to blanks, or click blank then click option'
Aself.state
BNone
Cprint(action)
Daction
Attempts:
3 left
💡 Hint
Common Mistakes
Setting state to None instead of the action.
Using print instead of assignment.
3fill in blank
hard

Fix the error in the agent's decision method to return an action string.

Prompt Engineering / GenAI
class Agent:
    def decide(self):
        action = 'move_forward'
        [1] action
Drag options to blanks, or click blank then click option'
Areturn
Bpass
Cyield
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of return.
Using pass which does nothing.
4fill in blank
hard

Fill both blanks to create a dictionary of actions and their rewards for autonomous decision making.

Prompt Engineering / GenAI
rewards = { 'move': [1], 'stop': [2] }
Drag options to blanks, or click blank then click option'
A10
B0
C-5
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning negative reward to 'move' which discourages action.
Using None instead of numeric rewards.
5fill in blank
hard

Fill all three blanks to create a function that selects the best action based on rewards.

Prompt Engineering / GenAI
def best_action(actions, rewards):
    best = None
    max_reward = [1]
    for action in actions:
        if rewards[action] [2] max_reward:
            best = action
            max_reward = rewards[action]
    return [3]
Drag options to blanks, or click blank then click option'
Afloat('inf')
B>
Cbest
Dfloat('-inf')
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing max_reward to positive infinity.
Using '<' instead of '>' in comparison.
Returning None instead of best action.