from modules.db.arcadedb_utils import run_arcade_cypher from modules.db.cypher_templates import CypherTemplates from modules.db.logger_utils import log_tool_entry import logging logger = logging.getLogger(__name__) @log_tool_entry def get_graph_context(query_string: str) -> str: """ Retrieves relevant graph nodes (characters/topics) based on the user query. Extracts entities and queries ArcadeDB for descriptions/relationships. """ try: tokens = query_string.split() if not tokens: return "" results = run_arcade_cypher(CypherTemplates.GET_GRAPH_CONTEXT, {"tokens": tokens}) if not results: return "No graph context found for the mentioned entities." context = "Graph Context (Characters/Topics):\n" for r in results: context += f"- {r.get('name', 'Unknown')} ({r.get('type', 'Entity')}): {r.get('description', 'No description available')}\n" return context except Exception as e: logger.error(f"Error retrieving graph context: {e}") return "Error retrieving graph context."