"""Ejemplo de CrewAI Flow: estado explícito y routing entre crews."""from dataclasses import dataclass, fieldfrom crewai import Crew, Task, Processfrom crewai.flow.flow import Flow, listen, start, routerfrom common import agent, make_llm, print_header, save, text @dataclassclass CaseState: request: str = "" category: str = "" result: str = "" events: list[str] = field(default_factory=list) class CaseFlow(Flow[CaseState]): @start() def intake(self): self.state.category = "technical" if any( x in self.state.request.lower() for x in ("api", "error", "código", "codigo") ) else "business" @router(intake) def route(self): return self.state.category
from __future__ import annotations import osfrom pathlib import Pathfrom dotenv import load_dotenvfrom crewai import Agent, LLM load_dotenv()ROOT = Path(__file__).resolve().parents[1]OUTPUTS = ROOT / "outputs" / "orquestacion" def make_llm(temperature: float = 0.3) -> LLM: """Construye el LLM usando OpenAI o el endpoint OpenCode ya usado por el proyecto.""" api_key = os.getenv("OPENAI_API_KEY") or os.getenv("OPENCODE_API_KEY") if not api_key: raise RuntimeError("Configura OPENAI_API_KEY u OPENCODE_API_KEY en .env") model = os.getenv("CREWAI_MODEL") or os.getenv("OPENCODE_MODEL") or "gpt-4o-mini" base_url = os.getenv("OPENCODE_BASE_URL") kwargs = {"model": model, "temperature": temperature, "api_key": api_key} return LLM(**kwargs)
import streamlit as stfrom crewai import Agent, Task, Crew, LLMfrom crewai_tools import FirecrawlSearchTool st.set_page_config( page_title="Estudio Contable - Asistente Financiero", layout="wide",)st.title("Estudio Contable - Asistente de Analisis Fiscal y Financiero") client_data_analyst = Agent( role="Client Data Analyst", goal="Analyze and structure the client financial data into a clear diagnostic baseline", backstory="You are a meticulous financial analyst who excels at organizing raw financial data into meaningful summaries, identifying trends, and flagging anomalies.", verbose=True, allow_delegation=False, llm=llm,)
import streamlit as stfrom crewai import Agent, Task, Crew, LLMfrom crewai_tools import FirecrawlSearchTool st.set_page_config( page_title="Estudio Jurídico - Asistente Legal", layout="wide",)st.warning( "Aviso: Esta herramienta es un asistente de analisis preliminar. " "No reemplaza el asesoramiento profesional de un abogado matriculado.") legal_researcher = Agent( role="Legal Researcher", goal="Research applicable laws, regulations, and relevant jurisprudence for the case", tools=[search_tool], llm=llm,)
import streamlit as stfrom crewai import Agent, Task, Crew, LLM business_problem = st.text_area( "Problema de negocio o caso de uso a resolver con IA:", height=120,)ai_objective = st.selectbox( "Objetivo de IA:", ["NLP / Chatbots", "Computer Vision", "Predictive Analytics", "Recommender Systems", "Automatizacion con IA", "Otro"],) ml_solution_architect = Agent( role="ML Solution Architect", goal="Design the ML solution architecture including model selection, data pipeline, and integration approach that balances accuracy, scalability, and maintainability", backstory="You are a principal ML engineer with deep experience in designing end-to-end ML systems, from data preprocessing and feature engineering to model training, evaluation, and serving, ensuring solutions are production-ready and scalable.", llm=llm,)