Adds an edge connecting the agent from another agent or list of agents in a given network.


add_edge_from(network, agent)

add_edge_from(network, agent-list)


If an edge doesn’t exist in the given network from a given agent ID to the current agent, then the edge is created. Otherwise, the action has no effect. If the second argument is a list expression, then edges are created from each agent in the list.

For undirected networks, because direction does not matter, both add_edge_from() and add_edge_to() have the same effect of adding an undirected edge between the current and other agents.



The name of the network to manipulate.


An expression that evaluates to the ID of an agent.


A list of agent ids.


Suppose we have a directed network NETWORK with three agents agent1, agent2, and agent3 with agent ids id1, id2, and id3 respectively. Presuming there are no current edge connections, an edge to agent1 from agent2 can be created with the following action rule:

if (id == id1) then add_edge_from(NETWORK, id2)

More simply, either of the following statements would assign an edge from agent2 to the current agent.

add_edge_from(NETWORK, id2)
add_edge_from(NETWORK, ask(agent2,id))

Alternately, edges to agent1 from agent2 and agent3 can be created with the action rule:

if (id == id1) then add_edge_from(NETWORK, list(id2, id3))

As another example, the following statement creates an edge from each member of the agent’s household to the agent itself.

add_edge_from(NETWORK, members(Household))


If an expression does not evaluate to an agent ID, then this action has no effect.

See Also

add_edge_from(), add_edge_to(), delete_edge_to(), is_connected_from(), is_connected_to()