Introduction
Real-world agents help computers do tasks by themselves, like a helpful robot or assistant. They make life easier by acting on their own using information they get.
Jump into concepts and practice - no test required
Real-world agents help computers do tasks by themselves, like a helpful robot or assistant. They make life easier by acting on their own using information they get.
agent = Agent(environment, goals) agent.observe() action = agent.decide() agent.act(action)
Agent: The smart program that senses and acts.
Environment: The real world or system the agent works in.
agent = Agent(weather_station, ['collect temperature', 'send report']) agent.observe() action = agent.decide() agent.act(action)
agent = Agent(stock_market, ['buy low', 'sell high']) agent.observe() action = agent.decide() agent.act(action)
This simple agent checks the temperature from a weather station and prints a report.
class Agent: def __init__(self, environment, goals): self.environment = environment self.goals = goals self.state = None def observe(self): self.state = self.environment.get_state() def decide(self): if 'collect temperature' in self.goals: return f"Report: Temperature is {self.state['temperature']}°C" return "No action" def act(self, action): print(action) class WeatherStation: def get_state(self): return {'temperature': 22} # Create environment and agent weather_station = WeatherStation() agent = Agent(weather_station, ['collect temperature', 'send report']) # Agent cycle agent.observe() action = agent.decide() agent.act(action)
Agents work best when they can sense their environment clearly.
Goals guide what actions the agent takes.
Real-world agents often repeat observe-decide-act many times.
Real-world agents sense their environment and act to reach goals.
They help automate tasks like weather reporting or trading.
Agents work in a loop: observe, decide, then act.
def observe():
return 'rainy'
def decide(weather):
return 'take umbrella' if weather == 'rainy' else 'no umbrella'
def act(action):
print(f'Action: {action}')
weather = observe()
action = decide(weather)
act(action)while True:
action = decide(observe)
act(action)