Skip to content

Commit 1a8c6ff

Browse files
committed
refactor agent activation flow
1 parent c9799d9 commit 1a8c6ff

File tree

5 files changed

+539
-556
lines changed

5 files changed

+539
-556
lines changed

AgentCrew/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.6.6-1"
1+
__version__ = "0.6.6-2"

AgentCrew/modules/agents/local_agent.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,16 @@ def activate(self):
213213
if self.is_active:
214214
return True # Already active
215215

216+
self.is_active = True
217+
216218
self.register_tools()
219+
from AgentCrew.modules.mcpclient.manager import MCPSessionManager
220+
221+
# Reinitialize MCP session manager for the current agent
222+
mcp_manager = MCPSessionManager.get_instance()
223+
if mcp_manager.initialized:
224+
mcp_manager.initialize_for_agent(self.name)
225+
217226
self._register_tools_with_llm()
218227
system_prompt = self.get_system_prompt()
219228
if self.custom_system_prompt:
@@ -223,7 +232,6 @@ def activate(self):
223232

224233
self.llm.set_system_prompt(system_prompt)
225234
self.llm.temperature = self.temperature if self.temperature is not None else 0.4
226-
self.is_active = True
227235
return True
228236

229237
def deactivate(self):

AgentCrew/modules/agents/manager.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ def select_agent(self, agent_name: str) -> bool:
117117
)
118118
# Activate the new agent
119119
if self.current_agent:
120-
if isinstance(self.current_agent, LocalAgent):
121-
from AgentCrew.modules.mcpclient.manager import MCPSessionManager
122-
123-
mcp_manager = MCPSessionManager.get_instance()
124-
if mcp_manager.initialized:
125-
mcp_manager.initialize_for_agent(self.current_agent.name)
126-
127120
self.current_agent.activate()
128121

129122
return True
@@ -306,29 +299,11 @@ def update_llm_service(self, llm_service):
306299
Args:
307300
llm_service: The new LLM service to use
308301
"""
309-
if self.current_agent:
310-
# Deactivate the current agent
311-
self.current_agent.deactivate()
312-
313-
if isinstance(self.current_agent, LocalAgent):
314-
# Update the LLM service for the current agent
315-
self.current_agent.update_llm_service(llm_service)
316-
317-
from AgentCrew.modules.mcpclient.manager import MCPSessionManager
318302

319-
# Reinitialize MCP session manager for the current agent
320-
mcp_manager = MCPSessionManager.get_instance()
321-
if mcp_manager.initialized:
322-
mcp_manager.initialize_for_agent(self.current_agent.name)
323-
324-
# Reactivate the agent with the new LLM service
325-
self.current_agent.activate()
326-
327-
# Update all other agents' LLM service but keep them deactivated
328-
for _, agent in self.agents.items():
329-
if agent != self.current_agent:
330-
if isinstance(agent, LocalAgent):
331-
agent.update_llm_service(llm_service)
303+
# Update all other agents' LLM service but keep them deactivated
304+
for _, agent in self.agents.items():
305+
if isinstance(agent, LocalAgent):
306+
agent.update_llm_service(llm_service)
332307

333308
def get_remote_system_prompt(self):
334309
return """

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "agentcrew-ai"
3-
version = "0.6.6-1"
3+
version = "0.6.6-2"
44
requires-python = ">=3.12"
55
classifiers = [
66
"Programming Language :: Python :: 3",

0 commit comments

Comments
 (0)