import networkx as nx

# Create an agent class
class Agent:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __repr__(self):
        return f"Agent({self.name}, age={self.age})"

# Create agent instances
agent1 = Agent("Alice", 30)
agent2 = Agent("Bob", 25)
agent3 = Agent("Charlie", 35)

# Create graph and add agents as nodes
G = nx.Graph()
G.add_node(agent1)
G.add_nodes_from([agent2, agent3])

# Add edges between agents
G.add_edge(agent1, agent2)
G.add_edges_from([(agent1, agent3), (agent2, agent3)])

# Now you can access agent properties through the network
print("All nodes:")
print(list(G.nodes))

print("\nAlice's neighbors:")
print(list(G.neighbors(agent1)))

print("\nAlice's connections with details:")
for neighbor in G.neighbors(agent1):
    print(f"{agent1.name} is connected to {neighbor.name} (age {neighbor.age})")

print(f"\nAlice's degree (number of connections): {G.degree[agent1]}")

# You can also add attributes to edges
G[agent1][agent2]['relationship'] = 'friends'
G[agent1][agent3]['relationship'] = 'colleagues'

print("\nEdge relationships:")
for agent_a, agent_b, data in G.edges(data=True):
    print(f"{agent_a.name} <-> {agent_b.name}: {data.get('relationship', 'unknown')}")