File size: 1,394 Bytes
d32c69c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

def parse_agents(agent_string):
    """

    Parse a string containing agent names separated by ->, (, ), or commas

    and return a list of agent names.

    """
    if not agent_string or not agent_string.strip():
        return []
    
    # Replace parentheses with spaces to handle cases with parentheses
    import re
    cleaned_string = re.sub(r'\(.*?\)', '', agent_string)
    
    # Split by -> to get individual agent segments
    agent_segments = cleaned_string.split('->')
    
    # Process each segment to extract agent names
    agents = []
    for segment in agent_segments:
        # Split by comma and strip whitespace
        segment_agents = [agent.strip() for agent in segment.split(',') if agent.strip()]
        agents.extend(segment_agents)
    
    return agents

sample = "preprocessing_agent -> statistical_analytics_agent"
agents = parse_agents(sample)
print(agents)

# Test with different formats
test_samples = [
    "preprocessing_agent -> data_viz_agent",
    "preprocessing_agent(dataset, goal)",
    "preprocessing_agent -> statistical_analytics_agent, data_viz_agent",
    "preprocessing_agent, statistical_analytics_agent -> data_viz_agent",
    "",
    "preprocessing_agent(dataset, goal) -> data_viz_agent(dataset)"
]

for test in test_samples:
    print(f"Input: {test}")
    print(f"Output: {parse_agents(test)}")