ams-core-api / services /agent.py
Amssou's picture
Update services/agent.py
af8152c verified
Raw
History Blame Contribute Delete
5.68 kB
import logging
from services.memory_manager import MemoryManager
from services.knowledge_engine import KnowledgeEngine
from engines.content_engine import ContentEngine
from engines.scene_engine import SceneEngine
from engines.image_prompt_engine import ImagePromptEngine
from engines.pipeline_engine import PipelineEngine
from engines.image_generation_engine import ImageGenerationEngine
from engines.task_planner import TaskPlanner
from engines.task_executor import TaskExecutor
from engines.trend_engine import TrendEngine
from core.agent_runtime import AgentRuntime
from core.strategy_engine import StrategyEngine
from utils.message_parser import MessageParser
logger = logging.getLogger("ONYX")
class OnyxAgent:
def __init__(self):
self.memory = MemoryManager()
self.knowledge_engine = KnowledgeEngine()
self.content_engine = ContentEngine()
self.scene_engine = SceneEngine()
self.image_prompt_engine = ImagePromptEngine()
self.trend_engine = TrendEngine()
self.image_engine = ImageGenerationEngine()
self.pipeline_engine = PipelineEngine(
self.content_engine,
None,
self.scene_engine,
self.image_prompt_engine,
None,
None,
None,
None,
None,
self.image_engine,
None,
None,
None,
None,
None
)
self.planner = TaskPlanner()
self.strategy_engine = StrategyEngine()
self.message_parser = MessageParser()
self.executor = TaskExecutor({}, self.pipeline_engine)
self.runtime = AgentRuntime(
planner=self.planner,
strategy_engine=self.strategy_engine,
message_parser=self.message_parser,
trend_engine=self.trend_engine,
executor=self.executor,
memory=self.memory,
knowledge_engine=self.knowledge_engine
)
def detect_mode(self, message: str) -> str:
msg = message.lower()
if any(x in msg for x in ["manga", "anime", "naruto", "one piece"]):
return "anime"
if any(x in msg for x in ["bd", "comic", "cartoon", "dessin animé"]):
return "cartoon"
if any(x in msg for x in ["cyberpunk", "hacker", "néon", "futur"]):
return "cyberpunk"
if any(x in msg for x in ["fantasy", "dragon", "magie", "roi"]):
return "fantasy"
return "cinematic"
def build_character(self, message: str) -> str:
msg = message.lower()
if "hacker" in msg:
return "a cyberpunk hacker, hooded jacket, neon reflections, augmented eyes"
if "robot" in msg:
return "a futuristic robot, metallic body, glowing sensors"
if "enfant" in msg or "child" in msg:
return "a young child, curious eyes, soft expression"
if "dragon" in msg:
return "a massive ancient dragon, glowing scales, powerful wings"
if "guerrier" in msg or "warrior" in msg:
return "a battle-hardened warrior, armor, scars, intense gaze"
return f"a character inspired by: {message}"
def get_style(self, mode: str) -> str:
styles = {
"cinematic": "cinematic, ultra realistic lighting",
"anime": "anime style, vibrant colors, detailed illustration",
"cartoon": "cartoon style, stylized, expressive",
"cyberpunk": "cyberpunk style, neon lights, futuristic city",
"fantasy": "epic fantasy, dramatic lighting, magical atmosphere"
}
return styles.get(mode, "cinematic")
def generate_clean_script(self, message: str, mode: str):
style = self.get_style(mode)
character = self.build_character(message)
base = message.strip()
scene_1 = f"""
{base}.
Establishing environment, world building, atmosphere,
epic scale, detailed background, {style},
wide shot, no character focus
""".strip()
scene_2 = f"""
{character} appears in the scene.
Action begins, movement, interaction with environment,
tension rising, dynamic angle, {style}
""".strip()
scene_3 = f"""
Close emotional moment.
{character}, breathing slowly, intense atmosphere,
dramatic lighting, close-up, {style}
""".strip()
return f"""
[SCENE 1]
{scene_1}
[SCENE 2]
{scene_2}
[SCENE 3]
{scene_3}
""".strip()
def chat(self, message: str, mode: str = None):
try:
logger.info(f"🎯 MESSAGE: {message}")
if not mode or mode == "auto":
mode = self.detect_mode(message)
logger.info(f"🧠 MODE: {mode}")
script = self.generate_clean_script(message, mode)
# 🔥 IMAGE FIX
image = None
try:
image = self.image_engine.generate(message)
except Exception as e:
logger.warning(f"Image engine error: {e}")
return {
"status": "ok",
"agent": "ONYX",
"mode": mode,
"response": "clean_generated",
"script": script,
"image": image
}
except Exception as e:
logger.error(f"🔥 Agent error: {e}")
fallback_script = self.generate_clean_script(message, "cinematic")
return {
"status": "ok",
"agent": "ONYX",
"mode": "cinematic",
"response": "error_fallback",
"script": fallback_script,
"image": None
}