File size: 2,587 Bytes
20ecf7a
 
 
8340d0e
 
 
 
 
 
 
 
 
20ecf7a
 
 
 
 
 
8340d0e
 
 
 
20ecf7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86da1e2
20ecf7a
 
86da1e2
20ecf7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86da1e2
 
20ecf7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import json
import uuid

class CustomAgent:
    def __init__(self, name, role, backstory, goal, allow_delegation, verbose):
        self.name = name
        self.role = role
        self.backstory = backstory
        self.goal = goal
        self.allow_delegation = allow_delegation
        self.verbose = verbose

def load_json(file_path):
    with open(file_path, 'r') as f:
        return json.load(f)
    return None

### UI UTILS ###
def fill_example_data(session_data, file_path):
    research_agents = load_json(file_path)["agents"]
    research_tasks = load_json(file_path)["tasks"]
    research_variables = load_json(file_path)["variables"]
    if research_agents and isinstance(research_agents, list) and len(research_agents) > 0:
        session_data.agents = research_agents
        session_data.warnings['no_agents'] = False
    if research_tasks and isinstance(research_tasks, list) and len(research_tasks) > 0:
        session_data.tasks = research_tasks
        session_data.warnings['no_tasks'] = False
    if research_variables and isinstance(research_variables, list) and len(research_variables) > 0:
        session_data.variables = research_variables
## AGENT UTILS ##

def add_agent(index, agents, warnings):
    agents.append({
        'id': str(uuid.uuid4()), # Add a unique id to each agent
        'name': f'Agent {index + 1}',
        'role': '',
        'backstory': '',
        'goal': '',
        'allow_delegation': True,
        'verbose': True
    })
    warnings['no_agents'] = False

def remove_agent(index, agents):
    agents.pop(index)

def attach_agents(agents, crew, warnings):
    if not agents or list(agents) == []:
        warnings['no_agents'] = True
        return
    crew['agents'].append(agents[0]['name'])

def deattach_agent(index, crew):
    crew['agents'].pop(index)

## TASK UTILS ##

def add_tasks(index, tasks, warnings):
    tasks.append({
        'id': str(uuid.uuid4()),
        'name': f'Task {index + 1}',
        'description': '',
        'expected_output': '',
        'agent_id': '',
        'tools': []
    })
    warnings['no_tasks'] = False

def remove_task(index, tasks):
    tasks.pop(index)  

def attach_tasks(tasks, crew, warnings):
    if not tasks or list(tasks) == []:
        warnings['no_tasks'] = True
        return
    crew['tasks'].append(tasks[0]['name'])


def deattach_task(index, crew):
    crew['tasks'].pop(index)

## VARIABLE UTILS ##
def add_variable(variables):
    variables.append({
        'name': '',
        'value': ''
    })

def remove_variable(index, variables):
    variables.pop(index)