Spaces:
Running
Running
create separate models for managed agents
Browse files
LLM/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .llm_models import orchestrator_model, supabase_model, websearch_model
|
| 2 |
+
from .llm_provider import LLMProvider
|
| 3 |
+
from .models import LLMProviderType, LLMModelType
|
| 4 |
+
|
| 5 |
+
__all__ = [
|
| 6 |
+
"orchestrator_model",
|
| 7 |
+
"supabase_model",
|
| 8 |
+
"websearch_model",
|
| 9 |
+
"LLMProvider",
|
| 10 |
+
"LLMProviderType",
|
| 11 |
+
"LLMModelType",
|
| 12 |
+
]
|
LLM/llm_models.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from .models import LLMProviderType, LLMModelType
|
| 3 |
+
from .llm_provider import LLMProvider
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
orchestrator_model = LLMProvider(LLMProviderType.OPENAI, LLMModelType.openai.gpt_5_1).get_model()
|
| 7 |
+
|
| 8 |
+
supabase_model = LLMProvider(LLMProviderType.OPENAI, LLMModelType.openai.gpt_4o).get_model()
|
| 9 |
+
websearch_model = LLMProvider(LLMProviderType.OPENAI, LLMModelType.openai.gpt_4o).get_model()
|
llm_provider.py → LLM/llm_provider.py
RENAMED
|
@@ -2,52 +2,7 @@ import os
|
|
| 2 |
from typing import Any
|
| 3 |
from enum import Enum
|
| 4 |
from smolagents import InferenceClientModel, OpenAIServerModel # type: ignore
|
| 5 |
-
|
| 6 |
-
class OpenAIModel(str, Enum):
|
| 7 |
-
gpt_5_1 = "gpt-5.1"
|
| 8 |
-
gpt_4o = "gpt-4o"
|
| 9 |
-
gpt_4o_mini = "gpt-4o-mini"
|
| 10 |
-
gpt_4_1 = "gpt-4.1"
|
| 11 |
-
gpt_4_1_mini = "gpt-4.1-mini"
|
| 12 |
-
gpt_4_turbo = "gpt-4-turbo"
|
| 13 |
-
gpt_3_5_turbo = "gpt-3.5-turbo-0125"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
class AnthropicModel(str, Enum):
|
| 17 |
-
claude_3_5_sonnet = "claude-3-5-sonnet-20240620"
|
| 18 |
-
claude_3_5_haiku = "claude-3-5-haiku-20241022"
|
| 19 |
-
claude_3_opus = "claude-3-opus-20240229"
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
class GeminiModel(str, Enum):
|
| 23 |
-
gemini_2_5_flash = "gemini-2.5-flash"
|
| 24 |
-
gemini_2_5_pro = "gemini-2.5-pro"
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
class OSSModel(str, Enum):
|
| 28 |
-
llama3_70b_instruct = "meta-llama/Meta-Llama-3-70B-Instruct"
|
| 29 |
-
llama3_8b_instruct = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 30 |
-
mixtral_8x7b = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 31 |
-
mistral_small_instruct = "mistralai/Mistral-Small-Instruct-2409"
|
| 32 |
-
qwen2_72b_instruct = "Qwen/Qwen2-72B-Instruct"
|
| 33 |
-
deepseek_v2 = "deepseek-ai/DeepSeek-V2"
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
class LLMModelType:
|
| 37 |
-
"""Namespaced access to curated model enums, e.g. LLMModelType.openai.gpt_5_1."""
|
| 38 |
-
|
| 39 |
-
openai = OpenAIModel
|
| 40 |
-
claude = AnthropicModel
|
| 41 |
-
gemini = GeminiModel
|
| 42 |
-
open_source = OSSModel
|
| 43 |
-
|
| 44 |
-
class LLMProviderType(str, Enum):
|
| 45 |
-
OPENAI = "openai"
|
| 46 |
-
GEMINI = "gemini"
|
| 47 |
-
CLAUDE = "claude"
|
| 48 |
-
HF = "hf"
|
| 49 |
-
OPENROUTER = "openrouter"
|
| 50 |
-
|
| 51 |
|
| 52 |
ENV_KEY_MAP = {
|
| 53 |
LLMProviderType.OPENAI: "OPENAI_API_KEY",
|
|
@@ -106,7 +61,6 @@ class LLMProvider:
|
|
| 106 |
api_base = BASE_URL_MAP.get(self.provider)
|
| 107 |
if not api_base:
|
| 108 |
raise ValueError(f"Base URL not configured for provider: {self.provider}")
|
| 109 |
-
print(api_base, self.api_key, self.model_id)
|
| 110 |
return OpenAIServerModel(
|
| 111 |
model_id=self.model_id,
|
| 112 |
api_key=self.api_key,
|
|
|
|
| 2 |
from typing import Any
|
| 3 |
from enum import Enum
|
| 4 |
from smolagents import InferenceClientModel, OpenAIServerModel # type: ignore
|
| 5 |
+
from .models import LLMProviderType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
ENV_KEY_MAP = {
|
| 8 |
LLMProviderType.OPENAI: "OPENAI_API_KEY",
|
|
|
|
| 61 |
api_base = BASE_URL_MAP.get(self.provider)
|
| 62 |
if not api_base:
|
| 63 |
raise ValueError(f"Base URL not configured for provider: {self.provider}")
|
|
|
|
| 64 |
return OpenAIServerModel(
|
| 65 |
model_id=self.model_id,
|
| 66 |
api_key=self.api_key,
|
LLM/models.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from enum import Enum
|
| 2 |
+
|
| 3 |
+
class OpenAIModel(str, Enum):
|
| 4 |
+
gpt_5_1 = "gpt-5.1"
|
| 5 |
+
gpt_4o = "gpt-4o"
|
| 6 |
+
gpt_4o_mini = "gpt-4o-mini"
|
| 7 |
+
gpt_4_1 = "gpt-4.1"
|
| 8 |
+
gpt_4_1_mini = "gpt-4.1-mini"
|
| 9 |
+
gpt_4_turbo = "gpt-4-turbo"
|
| 10 |
+
gpt_3_5_turbo = "gpt-3.5-turbo-0125"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class AnthropicModel(str, Enum):
|
| 14 |
+
claude_3_5_sonnet = "claude-3-5-sonnet-20240620"
|
| 15 |
+
claude_3_5_haiku = "claude-3-5-haiku-20241022"
|
| 16 |
+
claude_3_opus = "claude-3-opus-20240229"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class GeminiModel(str, Enum):
|
| 20 |
+
gemini_2_5_flash = "gemini-2.5-flash"
|
| 21 |
+
gemini_2_5_pro = "gemini-2.5-pro"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class OSSModel(str, Enum):
|
| 25 |
+
llama3_70b_instruct = "meta-llama/Meta-Llama-3-70B-Instruct"
|
| 26 |
+
llama3_8b_instruct = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 27 |
+
mixtral_8x7b = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 28 |
+
mistral_small_instruct = "mistralai/Mistral-Small-Instruct-2409"
|
| 29 |
+
qwen2_72b_instruct = "Qwen/Qwen2-72B-Instruct"
|
| 30 |
+
deepseek_v2 = "deepseek-ai/DeepSeek-V2"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class LLMModelType:
|
| 34 |
+
"""Namespaced access to curated model enums, e.g. LLMModelType.openai.gpt_5_1."""
|
| 35 |
+
|
| 36 |
+
openai = OpenAIModel
|
| 37 |
+
claude = AnthropicModel
|
| 38 |
+
gemini = GeminiModel
|
| 39 |
+
open_source = OSSModel
|
| 40 |
+
|
| 41 |
+
class LLMProviderType(str, Enum):
|
| 42 |
+
OPENAI = "openai"
|
| 43 |
+
GEMINI = "gemini"
|
| 44 |
+
CLAUDE = "claude"
|
| 45 |
+
HF = "hf"
|
| 46 |
+
OPENROUTER = "openrouter"
|
| 47 |
+
|
agents/orchestrator_agent/managed_agents/supabase_agent.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
-
from smolagents import CodeAgent, MCPClient
|
| 2 |
import os
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
mcp_client = MCPClient(
|
| 5 |
{
|
| 6 |
"url": "https://mcp.supabase.com/mcp?project_ref=kzrdiydhjgsaxomkuijq",
|
|
@@ -10,15 +13,15 @@ mcp_client = MCPClient(
|
|
| 10 |
, structured_output=True)
|
| 11 |
|
| 12 |
|
| 13 |
-
_supabase_agent = None
|
| 14 |
|
| 15 |
|
|
|
|
| 16 |
|
| 17 |
-
def get_supabase_agent(
|
| 18 |
global _supabase_agent
|
| 19 |
if _supabase_agent is None:
|
| 20 |
_supabase_agent = CodeAgent(
|
| 21 |
-
model=
|
| 22 |
tools=mcp_client.get_tools(),
|
| 23 |
name="supabase_agent",
|
| 24 |
description="An agent that queries the database for project details, team members, and employee skills."
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
from smolagents import CodeAgent, MCPClient
|
| 4 |
+
from LLM.llm_models import supabase_model
|
| 5 |
+
|
| 6 |
+
|
| 7 |
mcp_client = MCPClient(
|
| 8 |
{
|
| 9 |
"url": "https://mcp.supabase.com/mcp?project_ref=kzrdiydhjgsaxomkuijq",
|
|
|
|
| 13 |
, structured_output=True)
|
| 14 |
|
| 15 |
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
+
_supabase_agent = None
|
| 19 |
|
| 20 |
+
def get_supabase_agent():
|
| 21 |
global _supabase_agent
|
| 22 |
if _supabase_agent is None:
|
| 23 |
_supabase_agent = CodeAgent(
|
| 24 |
+
model=supabase_model,
|
| 25 |
tools=mcp_client.get_tools(),
|
| 26 |
name="supabase_agent",
|
| 27 |
description="An agent that queries the database for project details, team members, and employee skills."
|
agents/orchestrator_agent/managed_agents/web_search_agent.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
| 1 |
-
from typing import List, Optional
|
| 2 |
|
| 3 |
from smolagents import CodeAgent, WebSearchTool
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
_web_search_agent = None
|
| 8 |
|
| 9 |
-
def get_web_search_agent(
|
| 10 |
global _web_search_agent
|
| 11 |
if _web_search_agent is None:
|
| 12 |
_web_search_agent = CodeAgent(
|
| 13 |
-
model=
|
| 14 |
tools=[WebSearchTool()],
|
| 15 |
name="web_search_agent",
|
| 16 |
description="An agent that searches for relevant online courses, certifications, and learning paths."
|
|
|
|
|
|
|
| 1 |
|
| 2 |
from smolagents import CodeAgent, WebSearchTool
|
| 3 |
|
| 4 |
+
from LLM.llm_models import websearch_model
|
| 5 |
+
|
| 6 |
|
| 7 |
|
| 8 |
_web_search_agent = None
|
| 9 |
|
| 10 |
+
def get_web_search_agent():
|
| 11 |
global _web_search_agent
|
| 12 |
if _web_search_agent is None:
|
| 13 |
_web_search_agent = CodeAgent(
|
| 14 |
+
model=websearch_model,
|
| 15 |
tools=[WebSearchTool()],
|
| 16 |
name="web_search_agent",
|
| 17 |
description="An agent that searches for relevant online courses, certifications, and learning paths."
|
agents/orchestrator_agent/orchestrator_agent.py
CHANGED
|
@@ -1,16 +1,12 @@
|
|
| 1 |
from typing import List, Optional
|
| 2 |
from smolagents import CodeAgent, tool
|
| 3 |
|
|
|
|
| 4 |
from models import AnalysisResult, EmployeeTrainingPlan
|
| 5 |
-
from llm_provider import LLMModelType, LLMProvider, LLMProviderType
|
| 6 |
-
|
| 7 |
|
| 8 |
from .get_orchestrator_prompt import get_orchestrator_prompt
|
| 9 |
from .managed_agents import get_web_search_agent, get_supabase_agent
|
| 10 |
|
| 11 |
-
llm_provider = LLMProviderType.OPENAI
|
| 12 |
-
llm_model = LLMModelType.openai.gpt_5_1
|
| 13 |
-
|
| 14 |
@tool
|
| 15 |
def final_answer_callback(project_id: str, project_name: str, team: List[EmployeeTrainingPlan]) -> AnalysisResult:
|
| 16 |
"""
|
|
@@ -47,15 +43,14 @@ class OrchestratorAgent:
|
|
| 47 |
# Initialize the agent as a singleton
|
| 48 |
self._initialized = True
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
self._agent = CodeAgent(
|
| 53 |
-
model=
|
| 54 |
tools=[final_answer_callback],
|
| 55 |
-
managed_agents=[get_web_search_agent(
|
| 56 |
name="orchestrator_agent",
|
| 57 |
description="An agent that orchestrates the training-plan analysis process.",
|
| 58 |
-
stream_outputs=True
|
| 59 |
)
|
| 60 |
|
| 61 |
def analyze_and_plan(self, user_prompt: str):
|
|
|
|
| 1 |
from typing import List, Optional
|
| 2 |
from smolagents import CodeAgent, tool
|
| 3 |
|
| 4 |
+
from LLM.llm_models import orchestrator_model
|
| 5 |
from models import AnalysisResult, EmployeeTrainingPlan
|
|
|
|
|
|
|
| 6 |
|
| 7 |
from .get_orchestrator_prompt import get_orchestrator_prompt
|
| 8 |
from .managed_agents import get_web_search_agent, get_supabase_agent
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
@tool
|
| 11 |
def final_answer_callback(project_id: str, project_name: str, team: List[EmployeeTrainingPlan]) -> AnalysisResult:
|
| 12 |
"""
|
|
|
|
| 43 |
# Initialize the agent as a singleton
|
| 44 |
self._initialized = True
|
| 45 |
|
| 46 |
+
|
| 47 |
|
| 48 |
self._agent = CodeAgent(
|
| 49 |
+
model=orchestrator_model,
|
| 50 |
tools=[final_answer_callback],
|
| 51 |
+
managed_agents=[get_web_search_agent(), get_supabase_agent()],
|
| 52 |
name="orchestrator_agent",
|
| 53 |
description="An agent that orchestrates the training-plan analysis process.",
|
|
|
|
| 54 |
)
|
| 55 |
|
| 56 |
def analyze_and_plan(self, user_prompt: str):
|