Skip to content

Instantly share code, notes, and snippets.

View samirsaci's full-sized avatar

Samir Saci samirsaci

View GitHub Profile
@samirsaci
samirsaci / output_params.py
Created November 9, 2025 13:28
MCP Server Supply Chain Optimisation - Output Params
{
"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,
@samirsaci
samirsaci / input_params.py
Created November 9, 2025 13:27
MCP Server Supply Chain Optimisation - Input params
{ "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" ] ],
@samirsaci
samirsaci / launch_endpoint.py
Created November 9, 2025 13:23
MCP Server Supply Chain Optimization - Endpoint Launch
@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
@samirsaci
samirsaci / models.py
Created November 9, 2025 13:23
MCP Server Supply Chain Optimization - Models
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"]
@samirsaci
samirsaci / parsed_params.py
Created November 9, 2025 13:07
AI Agent Budget Planning - Parsed Params
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
}
@samirsaci
samirsaci / end_point.py
Created November 9, 2025 13:06
AI Agent Budget Planning - FastAPI Endpoint
@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"),
}
@samirsaci
samirsaci / graph_builder.py
Created November 9, 2025 13:05
AI Agent Budget Planning - Graph Builder
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)
@samirsaci
samirsaci / summarizer_function.py
Created November 9, 2025 13:04
AI Agent Budget Planning - Summarize Function
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}
@samirsaci
samirsaci / run_budget.py
Created November 9, 2025 13:03
AI Agent Budget Planning - Run Budget
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:
@samirsaci
samirsaci / email_parser.py
Created November 9, 2025 13:03
AI Agent Budget Planning - Parse Email Function
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}"}