Spaces:
Build error
Build error
Commit Β·
05ecbdd
1
Parent(s): f844f16
updated app.py
Browse files3 unmodified lines456778910111213141516175 unmodified lines23242524262728272930313032333234343535363738394041424344454647195 unmodified lines24324424524624724824925025125225325425525625715 unmodified lines2732742752582592762772782792802812822832842852862872883 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 runnerfrom 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 new multi-agent LangGraph system in a background thread.""" """Wrapper that executes the latest multi-agent LangGraph system."""
def __init__(self): print("BasicAgent (multi-agent) initialized.") print("BasicAgent (latest multi-agent system) initialized.")
async def aquery(self, question: str) -> str: """Run the synchronous `run_agent` helper inside the event-loop executor.""" """Run the latest async multi-agent system directly.""" 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 loop answer = await loop.run_in_executor(None, _sync_run_agent, question) # Generate unique session ID for this query session_id = f"app_session_{uuid.uuid4().hex[:8]}" # Call the latest async agent system directly answer = 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 answer except Exception as e:195 unmodified lines api_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 lines
print("-"*(60 + len(" App Starting ")) + "\n")
print("Launching Gradio Interface for Basic Agent Evaluation...") demo.launch(debug=True, share=False) 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() raiseapp.py+38-9