Merge branch 'main' of github.com:Berack96/upo-appAI into 21-team-monitoring
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import logging
|
||||
from agno.run.agent import RunEvent
|
||||
from app.agents.prompts import *
|
||||
from app.agents.team import AppTeam
|
||||
from app.configs import AppConfig
|
||||
|
||||
logging = logging.getLogger("pipeline")
|
||||
|
||||
|
||||
class Pipeline:
|
||||
"""
|
||||
@@ -15,23 +18,30 @@ class Pipeline:
|
||||
self.configs = configs
|
||||
|
||||
# Stato iniziale
|
||||
self.choose_strategy(0)
|
||||
self.choose_predictor(0)
|
||||
self.leader_model = self.configs.get_model_by_name(self.configs.agents.team_leader_model)
|
||||
self.team_model = self.configs.get_model_by_name(self.configs.agents.team_model)
|
||||
self.strategy = self.configs.get_strategy_by_name(self.configs.agents.strategy)
|
||||
|
||||
# ======================
|
||||
# Dropdown handlers
|
||||
# ======================
|
||||
def choose_predictor(self, index: int):
|
||||
def choose_leader(self, index: int):
|
||||
"""
|
||||
Sceglie il modello LLM da usare per il Predictor.
|
||||
Sceglie il modello LLM da usare per il Team.
|
||||
"""
|
||||
self.predictor = self.configs.models.all_models[index]
|
||||
self.leader_model = self.configs.models.all_models[index]
|
||||
|
||||
def choose_team(self, index: int):
|
||||
"""
|
||||
Sceglie il modello LLM da usare per il Team.
|
||||
"""
|
||||
self.team_model = self.configs.models.all_models[index]
|
||||
|
||||
def choose_strategy(self, index: int):
|
||||
"""
|
||||
Sceglie la strategia da usare per il Predictor.
|
||||
"""
|
||||
self.strat = self.configs.strategies[index].description
|
||||
self.strategy = self.configs.strategies[index]
|
||||
|
||||
# ======================
|
||||
# Helpers
|
||||
@@ -53,14 +63,30 @@ class Pipeline:
|
||||
# ======================
|
||||
def interact(self, query: str) -> str:
|
||||
"""
|
||||
1. Raccoglie output dai membri del Team
|
||||
2. Aggrega output strutturati
|
||||
3. Invoca Predictor
|
||||
4. Restituisce la strategia finale
|
||||
Esegue la pipeline di agenti per rispondere alla query dell'utente.
|
||||
1. Crea il Team di agenti.
|
||||
2. Aggiunge listener per eventi di logging.
|
||||
3. Esegue il Team con la query dell'utente.
|
||||
4. Recupera e restituisce l'output generato dagli agenti.
|
||||
Args:
|
||||
query (str): La query dell'utente.
|
||||
Returns:
|
||||
str: La risposta generata dagli agenti.
|
||||
"""
|
||||
# Step 1: raccolta output dai membri del Team
|
||||
team = AppTeam(configs=self.configs, team_models=self.predictor)
|
||||
|
||||
# Step 1: Creazione Team
|
||||
team = AppTeam(self.configs, self.team_model, self.leader_model)
|
||||
|
||||
# Step 2: Aggiunti listener per eventi
|
||||
team.add_listener(RunEvent.tool_call_started, lambda e: print(f"Team tool call started: {e.agent_name}")) # type: ignore
|
||||
team.add_listener(RunEvent.tool_call_completed, lambda e: print(f"Team tool call completed: {e.agent_name}")) # type: ignore
|
||||
|
||||
# Step 3: Esecuzione Team
|
||||
logging.info(f"Pipeline received query: {query}")
|
||||
# TODO migliorare prompt (?)
|
||||
query = f"The user query is: {query}\n\n They requested a {self.strategy.label} investment strategy."
|
||||
result = team.run_team(query)
|
||||
|
||||
# Step 4: Recupero output
|
||||
logging.info(f"Team finished")
|
||||
return result
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Callable
|
||||
from agno.run.agent import RunOutputEvent
|
||||
from agno.team import Team, TeamRunEvent, TeamRunOutputEvent
|
||||
@@ -8,8 +7,6 @@ from app.agents.prompts import *
|
||||
from app.configs import AppConfig, AppModel
|
||||
from app.api.tools import *
|
||||
|
||||
logging = logging.getLogger("AppTeam")
|
||||
|
||||
|
||||
class AppTeam:
|
||||
def __init__(self, configs: AppConfig, team_models: AppModel, team_leader: AppModel | None = None):
|
||||
@@ -25,7 +22,6 @@ class AppTeam:
|
||||
return asyncio.run(self.run_team_async(query))
|
||||
|
||||
async def run_team_async(self, query: str) -> str:
|
||||
logging.info(f"Running team q='{query}'")
|
||||
team = AppTeam.create_team_with(self.configs, self.team_models, self.team_leader)
|
||||
result = "No output from team"
|
||||
|
||||
@@ -38,7 +34,6 @@ class AppTeam:
|
||||
thinking = result.rfind("</think>")
|
||||
if thinking != -1: result = result[thinking:]
|
||||
|
||||
logging.info(f"Team finished")
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user