Spaces:
Runtime error
Runtime error
Commit ·
2610f53
1
Parent(s): ff40840
solved chatllm problems
Browse files- services/agents/base_agent.py +16 -23
- services/agents/master_orchestrator.py +11 -18
services/agents/base_agent.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# services/agents/base_agent.py
|
| 2 |
"""
|
| 3 |
-
Base class for all utility agents with logging
|
| 4 |
"""
|
| 5 |
import os
|
| 6 |
import hashlib
|
|
@@ -11,7 +11,6 @@ from typing import Dict, Any, Callable, Optional
|
|
| 11 |
from abc import ABC, abstractmethod
|
| 12 |
|
| 13 |
from crewai import Agent, Task, Crew
|
| 14 |
-
from litellm import completion
|
| 15 |
|
| 16 |
# Configure logging
|
| 17 |
logging.basicConfig(
|
|
@@ -67,28 +66,22 @@ class BaseUtilityAgent(ABC):
|
|
| 67 |
)
|
| 68 |
|
| 69 |
def _create_llm(self):
|
| 70 |
-
"""Create
|
| 71 |
-
#
|
| 72 |
-
#
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
"""Call LiteLLM completion."""
|
| 83 |
-
response = completion(
|
| 84 |
-
model=self.model,
|
| 85 |
-
messages=messages,
|
| 86 |
-
api_key=self.api_key,
|
| 87 |
-
**kwargs
|
| 88 |
-
)
|
| 89 |
-
return response.choices[0].message.content
|
| 90 |
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
|
| 93 |
def _hash_data(self, data: Any) -> str:
|
| 94 |
"""Create SHA256 hash of data for logging."""
|
|
|
|
| 1 |
# services/agents/base_agent.py
|
| 2 |
"""
|
| 3 |
+
Base class for all utility agents with logging and CrewAI integration.
|
| 4 |
"""
|
| 5 |
import os
|
| 6 |
import hashlib
|
|
|
|
| 11 |
from abc import ABC, abstractmethod
|
| 12 |
|
| 13 |
from crewai import Agent, Task, Crew
|
|
|
|
| 14 |
|
| 15 |
# Configure logging
|
| 16 |
logging.basicConfig(
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
def _create_llm(self):
|
| 69 |
+
"""Create LLM instance compatible with CrewAI ≥0.80.0"""
|
| 70 |
+
# CrewAI ≥0.80.0 has native Gemini support via google-generativeai
|
| 71 |
+
# We use the model string directly instead of a wrapper
|
| 72 |
+
# CrewAI will handle the LLM initialization internally
|
| 73 |
+
|
| 74 |
+
# For CrewAI with Gemini, we can pass the model string directly
|
| 75 |
+
# The format is "gemini/<model-name>"
|
| 76 |
+
# CrewAI will use the GEMINI_API_KEY or GOOGLE_API_KEY from environment
|
| 77 |
+
|
| 78 |
+
# Ensure API key is set
|
| 79 |
+
if not os.getenv("GEMINI_API_KEY") and not os.getenv("GOOGLE_API_KEY"):
|
| 80 |
+
raise ValueError("GEMINI_API_KEY or GOOGLE_API_KEY not found in environment")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
# Return the model string - CrewAI will handle it
|
| 83 |
+
# CrewAI ≥0.80.0 accepts model strings directly
|
| 84 |
+
return self.model
|
| 85 |
|
| 86 |
def _hash_data(self, data: Any) -> str:
|
| 87 |
"""Create SHA256 hash of data for logging."""
|
services/agents/master_orchestrator.py
CHANGED
|
@@ -12,7 +12,6 @@ from typing import Dict, Any, List, Optional
|
|
| 12 |
from datetime import datetime, timezone
|
| 13 |
|
| 14 |
from crewai import Agent, Task, Crew
|
| 15 |
-
from litellm import completion
|
| 16 |
|
| 17 |
from services.agents.message_dispatcher import MessageDispatcher, AgentMessage
|
| 18 |
|
|
@@ -63,24 +62,18 @@ class MasterOrchestratorAgent:
|
|
| 63 |
logger.info(f"MasterLLM Orchestrator initialized (delegation: ENABLED)")
|
| 64 |
|
| 65 |
def _create_llm(self):
|
| 66 |
-
"""Create
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
def __call__(self, messages, **kwargs):
|
| 75 |
-
response = completion(
|
| 76 |
-
model=self.model,
|
| 77 |
-
messages=messages,
|
| 78 |
-
api_key=self.api_key,
|
| 79 |
-
**kwargs
|
| 80 |
-
)
|
| 81 |
-
return response.choices[0].message.content
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
|
| 85 |
def create_plan(self, description: str, context: Dict[str, Any]) -> Dict[str, Any]:
|
| 86 |
"""
|
|
|
|
| 12 |
from datetime import datetime, timezone
|
| 13 |
|
| 14 |
from crewai import Agent, Task, Crew
|
|
|
|
| 15 |
|
| 16 |
from services.agents.message_dispatcher import MessageDispatcher, AgentMessage
|
| 17 |
|
|
|
|
| 62 |
logger.info(f"MasterLLM Orchestrator initialized (delegation: ENABLED)")
|
| 63 |
|
| 64 |
def _create_llm(self):
|
| 65 |
+
"""Create LLM instance compatible with CrewAI ≥0.80.0"""
|
| 66 |
+
# CrewAI ≥0.80.0 has native Gemini support via google-generativeai
|
| 67 |
+
# We use the model string directly instead of a wrapper
|
| 68 |
+
# CrewAI will handle the LLM initialization internally
|
| 69 |
+
|
| 70 |
+
# Ensure API key is set
|
| 71 |
+
if not os.getenv("GEMINI_API_KEY") and not os.getenv("GOOGLE_API_KEY"):
|
| 72 |
+
raise ValueError("GEMINI_API_KEY or GOOGLE_API_KEY not found in environment")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
# Return the model string - CrewAI will handle it
|
| 75 |
+
# CrewAI ≥0.80.0 accepts model strings directly
|
| 76 |
+
return self.model
|
| 77 |
|
| 78 |
def create_plan(self, description: str, context: Dict[str, Any]) -> Dict[str, Any]:
|
| 79 |
"""
|