Created
November 9, 2025 13:06
-
-
Save samirsaci/014ceab0d969710e1a2c4666daa11ce1 to your computer and use it in GitHub Desktop.
AI Agent Budget Planning - FastAPI Endpoint
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"), | |
| } | |
| 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