Spaces:
Build error
Build error
Commit Β·
05ecbdd
1
Parent(s): f844f16
updated app.py
Browse files3 unmodified lines4567891011121314155 unmodified lines212223242526272829303132333435363738195 unmodified lines23423523623723823915 unmodified lines2552562572582593 unmodified linesimport inspectimport pandas as pd# from agents import LlamaIndexAgentfrom new_langraph_agent import run_agent as _sync_run_agent # Updated: use the new multi-agent runnerimport asyncioimport aiohttpfrom langfuse.langchain import CallbackHandlerfrom langchain_core.messages import HumanMessageimport tempfile# Initialize Langfuse CallbackHandler for LangGraph/Langchain (tracing)langfuse_handler = CallbackHandler()5 unmodified lines# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent:"""Wrapper that executes the new multi-agent LangGraph system in a background thread."""def __init__(self):print("BasicAgent (multi-agent) initialized.")async def aquery(self, question: str) -> str:"""Run the synchronous `run_agent` helper inside the event-loop executor."""print(f"Agent received question (first 50 chars): {question[:50]}...")loop = asyncio.get_event_loop()try:# Off-load the blocking call to a thread so we don't block the Gradio event loopanswer = await loop.run_in_executor(None, _sync_run_agent, question)print(f"Agent returning answer: {answer}")return answerexcept Exception as e:195 unmodified linesapi_name="submit_answers",)if __name__ == "__main__":print("\n" + "-"*30 + " App Starting " + "-"*30)# Check for SPACE_HOST and SPACE_ID at startup for information15 unmodified linesprint("-"*(60 + len(" App Starting ")) + "\n")print("Launching Gradio Interface for Basic Agent Evaluation...")demo.launch(debug=True, share=False)3 unmodified lines45678910111213141516175 unmodified lines23242526272829303132333435363738394041424344454647195 unmodified lines24324424524624724824925025125225325425525625715 unmodified lines2732742752762772782792802812822832842852862872883 unmodified linesimport inspectimport pandas as pd# from agents import LlamaIndexAgentfrom langgraph_agent_system import run_agent_system # Updated: use the latest multi-agent systemfrom observability import flush_traces, shutdown_observability # Add cleanup functionsimport asyncioimport aiohttpfrom langfuse.langchain import CallbackHandlerfrom langchain_core.messages import HumanMessageimport tempfileimport uuid# Initialize Langfuse CallbackHandler for LangGraph/Langchain (tracing)langfuse_handler = CallbackHandler()5 unmodified lines# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent:"""Wrapper that executes the latest multi-agent LangGraph system."""def __init__(self):print("BasicAgent (latest multi-agent system) initialized.")async def aquery(self, question: str) -> str:"""Run the latest async multi-agent system directly."""print(f"Agent received question (first 50 chars): {question[:50]}...")try:# Generate unique session ID for this querysession_id = f"app_session_{uuid.uuid4().hex[:8]}"# Call the latest async agent system directlyanswer = await run_agent_system(query=question,user_id="gradio_app_user",session_id=session_id,max_iterations=3)print(f"Agent returning answer: {answer}")return answerexcept Exception as e:195 unmodified linesapi_name="submit_answers",)def cleanup_agent_system():"""Cleanup function for the agent system."""try:flush_traces(background=False)shutdown_observability()print("β Agent system cleanup completed")except Exception as e:print(f"β οΈ Cleanup warning: {e}")if __name__ == "__main__":print("\n" + "-"*30 + " App Starting " + "-"*30)# Check for SPACE_HOST and SPACE_ID at startup for information15 unmodified linesprint("-"*(60 + len(" App Starting ")) + "\n")print("Launching Gradio Interface with Latest Multi-Agent System...")print("π€ Using: LangGraph Multi-Agent System (Lead β Research β Code β Formatter)")print("π Features: Langfuse v3 observability, iterative workflows, GAIA compliance")try:demo.launch(debug=True, share=False)except KeyboardInterrupt:print("\nπ Shutting down gracefully...")cleanup_agent_system()except Exception as e:print(f"β Error during app execution: {e}")cleanup_agent_system()raise
app.py+38-9