with open('monitor_activation.py', 'r') as f:
    content = f.read()

# Replace count_active_agents to check running flag instead
old_count = '''    def count_active_agents(self, swarm):
        """Count how many agents are currently active"""
        active = 0
        for agent in swarm.agents:
            if agent.state.get('active', False):
                active += 1
        return active'''

new_count = '''    def count_active_agents(self, swarm):
        """Count how many agents are currently active"""
        active = 0
        for agent in swarm.agents:
            # Check if agent is running (not state['active'] which doesn't exist)
            if hasattr(agent, 'running') and agent.running:
                active += 1
        return active'''

content = content.replace(old_count, new_count)

with open('monitor_activation.py', 'w') as f:
    f.write(content)

print("✅ Fixed agent detection")
