Introduction
Single agent and multi-agent systems help us understand how one or many decision-makers act to solve problems or complete tasks.
Jump into concepts and practice - no test required
class Agent: def act(self, state): # Decide action based on state pass # Single agent system agent = Agent() state = ... action = agent.act(state) # Multi-agent system n = 3 agents = [Agent() for _ in range(n)] states = [...] # states for each agent actions = [agent.act(s) for agent, s in zip(agents, states)]
class Agent: def act(self, state): return 'move forward' agent = Agent() action = agent.act('start') print(action)
class Agent: def act(self, state): return f"agent moves based on {state}" agents = [Agent() for _ in range(3)] states = ['north', 'east', 'south'] actions = [agent.act(s) for agent, s in zip(agents, states)] print(actions)
class Agent: def __init__(self, name): self.name = name def act(self, state): return f"{self.name} acts on {state}" # Single agent example single_agent = Agent('Agent1') single_action = single_agent.act('state1') print('Single agent action:', single_action) # Multi-agent example agents = [Agent(f'Agent{i}') for i in range(3)] states = ['stateA', 'stateB', 'stateC'] actions = [agent.act(state) for agent, state in zip(agents, states)] print('Multi-agent actions:', actions)
single agent system and a multi-agent system?class Agent:
def __init__(self, name):
self.name = name
def act(self):
return f"{self.name} acts alone"
agents = [Agent("A1"), Agent("A2")]
results = [agent.act() for agent in agents]
print(results)
What is the output?class Agent:
def __init__(self, name):
self.name = name
def act(self):
return f"{self.name} acts"
agents = [Agent("A1"), Agent("A2")]
actions = []
for agent in agents:
actions.append(agent.act)
print(actions)