Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created November 9, 2025 13:06
Show Gist options
  • Select an option

  • Save samirsaci/014ceab0d969710e1a2c4666daa11ce1 to your computer and use it in GitHub Desktop.

Select an option

Save samirsaci/014ceab0d969710e1a2c4666daa11ce1 to your computer and use it in GitHub Desktop.
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"),
}
final_state = await _graph.ainvoke(initial_state)
return {
"params": final_state.get("params"),
"budget_results": final_state.get("budget_results"),
"html_summary": final_state.get("html_summary"),
"error": final_state.get("error"),
}
except Exception as e:
logger.exception("[BudAgent] Graph run failed")
raise HTTPException(status_code=500, detail=f"Graph run failed: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment