Skip to content
29 changes: 26 additions & 3 deletions nodes/src/nodes/agent_crewai/IGlobal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@
import os
from typing import Any

from rocketlib import IGlobalBase, OPEN_MODE
from rocketlib import IGlobalBase, IJson, OPEN_MODE


class IGlobal(IGlobalBase):
process: Any = None
agent: Any = None
role: str = 'Assistant'
task_description: str = ''
goal: str = ''
backstory: str = ''
expected_output: str = ''

def beginGlobal(self) -> None:
if self.IEndpoint.endpoint.openMode == OPEN_MODE.CONFIG:
Expand All @@ -46,10 +51,28 @@ def beginGlobal(self) -> None:

self.process = Process.sequential

from .crewai import CrewDriver
conn_config = IJson.toDict(self.glb.connConfig) if self.glb.connConfig else {}

self.agent = CrewDriver(self, process=self.process)
self.goal = str(conn_config.get('goal') or '').strip()
self.backstory = str(conn_config.get('backstory') or '').strip()

if self.glb.logicalType == 'agent_crewai_manager':
from .crewai import ManagerDriver

self.agent = ManagerDriver(self)
else:
self.role = str(conn_config.get('role') or 'Assistant').strip() or 'Assistant'
self.task_description = str(conn_config.get('task_description') or '').strip()
self.expected_output = str(conn_config.get('expected_output') or '').strip()
from .crewai import CrewDriver

self.agent = CrewDriver(self, process=self.process, role=self.role, task_description=self.task_description, goal=self.goal, backstory=self.backstory, expected_output=self.expected_output)

def endGlobal(self) -> None:
self.agent = None
self.process = None
self.role = 'Assistant'
self.task_description = ''
self.goal = ''
self.backstory = ''
self.expected_output = ''
18 changes: 17 additions & 1 deletion nodes/src/nodes/agent_crewai/IInstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,24 @@ def writeQuestions(self, question: Question):
self.IGlobal.agent.run_agent(self, question, emit_answers_lane=True)

def invoke(self, param: Any) -> Any: # noqa: ANN401
# Only intercept tool.* control-plane operations; otherwise fall back.
op = param.get('op') if isinstance(param, dict) else getattr(param, 'op', None)

# crewai.describe fan-out: only sub-agents (CrewDriver) respond — guarded by hasattr.
# ManagerDriver has no describe() so it silently falls through.
if isinstance(op, str) and op == 'crewai.describe' and hasattr(self.IGlobal.agent, 'describe'):
descriptor = self.IGlobal.agent.describe(self)
existing = getattr(param, 'agents', None)
if isinstance(existing, list):
existing.append(descriptor)
try:
param.agents = existing
except Exception:
pass
Comment thread
dylan-savage marked this conversation as resolved.
return param
return [descriptor]
Comment thread
dylan-savage marked this conversation as resolved.

# tool.* control-plane operations for agent-as-tool.
if isinstance(op, str) and op.startswith('tool.'):
return self.IGlobal.agent.handle_invoke(self, param)

return super().invoke(param)
Loading
Loading