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}")