This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "output_results": { | |
| "plant_opening": { | |
| "USA-LOW": 0, | |
| "GERMANY-LOW": 0, | |
| "JAPAN-LOW": 0, | |
| "BRAZIL-LOW": 0, | |
| "INDIA-LOW": 1, | |
| "USA-HIGH": 0, | |
| "GERMANY-HIGH": 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { "input_params": | |
| { "objective": "Production Cost", | |
| "max_energy": 780, | |
| "max_water": 3500, | |
| "max_waste": 0.78, | |
| "max_co2prod": 41, | |
| "unit_monetary": "1e6", | |
| "loc": [ "USA", "GERMANY", "JAPAN", "BRAZIL", "INDIA" ], | |
| "n_loc": 5, | |
| "plant_name": [ [ "USA", "LOW" ], [ "GERMANY", "LOW" ], [ "JAPAN", "LOW" ], [ "BRAZIL", "LOW" ], [ "INDIA", "LOW" ], [ "USA", "HIGH" ], [ "GERMANY", "HIGH" ], [ "JAPAN", "HIGH" ], [ "BRAZIL", "HIGH" ], [ "INDIA", "HIGH" ] ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @router.post("/launch_network") | |
| async def launch_network(request: Request, params: LaunchParamsNetwork): | |
| try: | |
| session_id = request.headers.get('session_id', 'session') | |
| directory = config['general']['folders']['directory'] | |
| folder_in = f'{directory}/{session_id}/network_analysis/input' | |
| folder_out = f'{directory}/{session_id}/network_analysis/output' | |
| network_analyzer = NetworkAnalysis(params, folder_in, folder_out) | |
| output = await network_analyzer.process() | |
| return output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pydantic import BaseModel | |
| from typing import Optional | |
| from app.utils.config_loader import load_config | |
| config = load_config() | |
| class LaunchParamsNetwork(BaseModel): | |
| objective: Optional[str] = 'Production Cost' | |
| max_energy: Optional[float] = config["network_analysis"]["params_mapping"]["max_energy"] | |
| max_water: Optional[float] = config["network_analysis"]["params_mapping"]["max_water"] | |
| max_waste: Optional[float] = config["network_analysis"]["params_mapping"]["max_waste"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Parsed params: { | |
| 'objective': 'Return On Investment', | |
| 'budget_year1': 1250000, | |
| 'budget_year2': 1500000, | |
| 'budget_year3': 1750000, | |
| 'set_min_budget': False, | |
| 'min_budget_objective': 'Sustainability', | |
| 'min_budget_perc': 20.0 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @router.post("/graph_parse_and_run") | |
| async def graph_parse_and_run(request: EmailRequest): | |
| """ | |
| Parse an email body, run Budget Planning, and return an HTML summary — orchestrated via a LangGraph StateGraph. | |
| """ | |
| try: | |
| initial_state = { | |
| "email_text": request.email_text, | |
| "session_id": config.get("budget_agent", {}).get("session_id", "test_agent"), | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def route_after_parse(state: AgentState) -> str: | |
| return "error" if "error" in state else "run" | |
| def route_after_run(state: AgentState) -> str: | |
| return "error" if "error" in state else "summarize" | |
| def build_budagent_graph(): | |
| graph_builder = StateGraph(AgentState) | |
| graph_builder.add_node("parse", parse_email) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async def summarize(state: AgentState) -> AgentState: | |
| if "error" in state: | |
| return {} | |
| try: | |
| interpreter = state.get("interpreter") or BudgetPlanInterpreter( | |
| model_name=config["budget_agent"]["model_name"], | |
| session_id=state.get("session_id", config["budget_agent"]["session_id"]), | |
| ) | |
| html = await interpreter.interpret(state["params"], state["budget_results"]) | |
| return {"html_summary": html} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async def run_budget(state: AgentState) -> AgentState: | |
| if "error" in state: | |
| return {} | |
| try: | |
| interpreter = BudgetPlanInterpreter( | |
| model_name=config["budget_agent"]["model_name"], | |
| session_id=state.get("session_id", | |
| config["budget_agent"]["session_id"])) | |
| results = await interpreter.run_plan(state["params"]) | |
| if "error" in results: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async def parse_email(state: AgentState) -> AgentState: | |
| try: | |
| parser = EmailParser(model_name=config["budget_agent"]["model_name"]) | |
| params = parser.parse(state["email_text"]) | |
| if not params or ("error" in params and params["error"]): | |
| return {"error": f"Parse failed: {params.get('error', 'unknown')}"} | |
| return {"params": params} | |
| except Exception as e: | |
| logger.exception("[BudgetGraph] parse_email crashed") | |
| return {"error": f"Parse exception: {e}"} |