Spaces:
Sleeping
Sleeping
File size: 3,134 Bytes
be5f49d f91f761 be5f49d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 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}") |