Research_Agent / agent_plan_solve_app.py
Ashmit003's picture
Uploading modified local folder struture
f91f761
import streamlit as st
import asyncio
import os
import sys
# βœ… Must be first Streamlit call
st.set_page_config(page_title="Strategic Planner", layout="centered")
# ─────────────────────────────────────────────
# πŸ“¦ Environment & Path Setup
# ─────────────────────────────────────────────
project_root = os.path.join(os.getcwd(), "agent_plan_solve")
if project_root not in sys.path:
sys.path.insert(0, project_root)
from config import set_environment
set_environment()
# ─────────────────────────────────────────────
# 🧠 LangGraph Agent Import
# ─────────────────────────────────────────────
from agent_plan_solve.graph.build_graph import graph
# ─────────────────────────────────────────────
# πŸŽ›οΈ Streamlit UI
# ─────────────────────────────────────────────
st.title("🧠Planner & Research Analyst with GPT-5 Nano")
st.markdown("Enter a task below and let the agent plan and execute it step-by-step.")
task_input = st.text_area("Task:", placeholder="e.g. Write a strategic one-pager for building an AI startup")
# ─────────────────────────────────────────────
# πŸ”„ Async Agent Execution
# ─────────────────────────────────────────────
async def run_agent(task: str):
return await graph.ainvoke({"task": task})
def display_response(response):
st.markdown("### βœ… Final Output")
if hasattr(response, "content"):
st.markdown(response.content)
elif isinstance(response, str):
st.markdown(response)
elif isinstance(response, dict) and "content" in response:
st.markdown(response["content"])
else:
st.error("No response generated.")
# ─────────────────────────────────────────────
# πŸš€ Trigger Agent
# ─────────────────────────────────────────────
if st.button("Run Agent"):
if not task_input.strip():
st.warning("Please enter a task.")
else:
with st.spinner("Running LangGraph agent..."):
try:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
result = loop.run_until_complete(run_agent(task_input))
display_response(result.get("final_response"))
except Exception as e:
st.error(f"❌ Agent execution failed: {e}")