Create nodes

This commit is contained in:
Luan Citta
2024-06-05 09:00:11 +01:00
parent 990e837eb0
commit 3235e9d502
6 changed files with 152 additions and 2 deletions
+10 -2
View File
@@ -1,8 +1,16 @@
import os
from .agent_node import AgentNode
from .task_node import TaskNode
from .crew_node import CrewNode
from .list_task_node import TaskList
from .list_agent_node import AgentList
NODE_CLASS_MAPPINGS = {
"CrewAI Agent Node": AgentNode,
"CrewAI Task Node": TaskNode,
"CrewAI Crew Node": CrewNode,
"CrewAI TaskList Node": TaskList,
"CrewAI AgentList Node": AgentList,
}
WEB_DIRECTORY = "./js"
+32
View File
@@ -0,0 +1,32 @@
from crewai import Agent
class AgentNode:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"role": ("STRING", {"default": ""}),
"goal": ("STRING", {"default": ""}),
"backstory": ("STRING", {"default": ""}),
"verbose": ("BOOL", {"default": False}),
"allow_delegation": ("BOOL", {"default": False}),
},
}
RETURN_TYPES = ("AGENT",)
FUNCTION = "create_agent"
CATEGORY = "📎CrewAi"
def create_agent(self, role, goal, backstory, verbose, allow_delegation):
agent = Agent(
role=role,
goal=goal,
backstory=backstory,
verbose=verbose,
allow_delegation=allow_delegation
)
return (agent,)
+33
View File
@@ -0,0 +1,33 @@
from crewai import Crew, Process
class CrewNode:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"agents": ("AGENT", {"default": []}),
"tasks": ("TASK", {"default": []}),
"process": ("STRING", {"default": "sequential", "choices": ["sequential", "hierarchical"]}),
"topic": ("STRING", {"default": ""}),
},
}
INPUT_IS_LIST = (True, True, False, False)
RETURN_TYPES = ("STRING",)
FUNCTION = "create_crew"
CATEGORY = "📎CrewAi"
def create_crew(self, agents, tasks, process, topic):
process_type = Process.sequential if process == "sequential" else Process.hierarchical
print("\n\n📎Crew AI - input", agents, tasks, process, topic)
crew = Crew(
agents=agents,
tasks=tasks,
process=process_type
)
result = crew.kickoff(inputs={'topic': topic})
print("\n\n📎Crew AI - result", result)
return (result,)
+24
View File
@@ -0,0 +1,24 @@
class AgentList:
@classmethod
def INPUT_TYPES(cls):
# Generate a dictionary for up to n agents dynamically
inputs = {"required": {"agent-1": ("AGENT",)}}
# for i in range(2, 101): # Adjust the range as needed
# inputs["optional"] = inputs.get("optional", {})
# inputs["optional"][f"agent{i}"] = ("AGENT",)
return inputs
OUTPUT_IS_LIST = (True,)
RETURN_TYPES = ("AGENT",)
FUNCTION = "create_list"
CATEGORY = "📎CrewAi"
def create_list(self, **kwargs):
agents = []
# Collect all agents from kwargs dynamically
for key, value in kwargs.items():
if value is not None:
agents.append(value)
return (agents,)
+25
View File
@@ -0,0 +1,25 @@
from crewai import Crew, Process
class TaskList:
@classmethod
def INPUT_TYPES(s):
# Generate a dictionary for up to n agents dynamically
inputs = {"required": {"task-1": ("TASK",)}}
# for i in range(2, 101): # Adjust the range as needed
# inputs["optional"] = inputs.get("optional", {})
# inputs["optional"][f"agent{i}"] = ("AGENT",)
return inputs
OUTPUT_IS_LIST = (True,)
RETURN_TYPES = ("TASK",)
FUNCTION = "create_list"
CATEGORY = "📎CrewAi"
def create_list(self, **kwargs):
task = []
for k, v in kwargs.items():
task.append(v)
return (task, )
+28
View File
@@ -0,0 +1,28 @@
from crewai import Task
class TaskNode:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"description": ("STRING", {"default": ""}),
"expected_output": ("STRING", {"default": ""}),
"agent": ("AGENT",),
},
}
RETURN_TYPES = ("TASK",)
FUNCTION = "create_task"
CATEGORY = "📎CrewAi"
def create_task(self, description, expected_output, agent):
task = Task(
description=description,
expected_output=expected_output,
agent=agent
)
return (task,)