Spaces:
Sleeping
Sleeping
| 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}") |