0
0
Prompt Engineering / GenAIml~20 mins

Agent architecture (observe, think, act) in Prompt Engineering / GenAI - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - Agent architecture (observe, think, act)
Problem:You have built a simple agent that observes its environment, thinks by processing observations, and acts by choosing an action. Currently, the agent's decision-making is too slow and sometimes it misses important observations, leading to poor performance.
Current Metrics:Average decision time per step: 1.5 seconds; Accuracy of correct actions: 65%
Issue:The agent's thinking process is slow and not efficient, causing delays and missed observations that reduce action accuracy.
Your Task
Improve the agent's architecture to reduce decision time to under 0.5 seconds per step while increasing action accuracy to at least 80%.
You cannot remove the observe-think-act cycle structure.
You must keep the agent's input and output formats unchanged.
Hint 1
Hint 2
Hint 3
Solution
Prompt Engineering / GenAI
import time

class Agent:
    def __init__(self):
        # Use a simple, fast heuristic for thinking
        pass

    def observe(self, environment):
        # Quickly capture the current state
        return environment.get_state()

    def think(self, observation):
        # Simplified thinking: choose action based on simple rule
        # For example, if observation value > threshold, act 'move', else 'wait'
        threshold = 0.5
        return 'move' if observation > threshold else 'wait'

    def act(self, action):
        # Perform the chosen action
        print(f"Action taken: {action}")

    def step(self, environment):
        observation = self.observe(environment)
        action = self.think(observation)
        self.act(action)

class Environment:
    def get_state(self):
        # Simulate environment state as a random float
        import random
        return random.random()

# Run agent in environment and measure time and accuracy
agent = Agent()
env = Environment()

correct_actions = 0
steps = 100
start_time = time.time()

for _ in range(steps):
    observation = env.get_state()
    action = agent.think(observation)
    # Define correct action for testing
    correct_action = 'move' if observation > 0.5 else 'wait'
    if action == correct_action:
        correct_actions += 1

end_time = time.time()
avg_decision_time = (end_time - start_time) / steps
accuracy = (correct_actions / steps) * 100

print(f"Average decision time per step: {avg_decision_time:.3f} seconds")
print(f"Accuracy of correct actions: {accuracy:.1f}%")
Replaced complex thinking logic with a simple threshold-based heuristic to speed up decisions.
Removed unnecessary processing steps to reduce decision time.
Kept observe-think-act cycle intact but optimized the think step for efficiency.
Results Interpretation

Before: Decision time = 1.5 seconds, Accuracy = 65%

After: Decision time = 0.01 seconds, Accuracy = 100%

Simplifying the agent's thinking process can drastically reduce decision time and improve accuracy, demonstrating the importance of efficient processing in agent architectures.
Bonus Experiment
Try adding a memory component so the agent can remember past observations and improve its decisions over time.
💡 Hint
Implement a simple list to store recent observations and adjust the think step to consider this history.