<｜begin▁of▁sentence｜>### Instruction:
Given the condensed matter collaborations graph of 2005 which you can read from a gml file named 'cond-mat-2005.gml', can you use the AGDL function in cdlib to perform community detection with a specified number of communities and a neighbor set size for each cluster? Then, can you convert the detected communities into a JSON format?
### Response:
import networkx as nx
from cdlib import algorithms

# Load the graph
G = nx.read_gml('cond-mat-2005.gml')

# Perform community detection using AGDL algorithm
communities = algorithms.agdl(G, number_communities=3, kc=4)

# Convert the communities to a JSON object
communities_json = communities.to_json()

print(communities_json)
<|EOT|>
