""" LangChain @tool wrappers for Nexus Master Agent. These wrappers adapt the underlying business logic from nexus_tools.py into formalized LangChain tools that can be passed to llm.bind_tools() and executed via ToolNode or custom executors. """ from typing import Any, Dict, Optional from langchain_core.tools import tool from agents.tools import nexus_tools from agents.tools.tool_registry import ( KBSearchInput, TicketQueryInput, AnalyticsInput, SimilarIncidentsInput, ProjectPulseInput, SentimentCheckInput, AssignTicketInput, UpdateStatusInput, RemediateInput, MemoryRecallInput, PlatformRefreshInput, CreateTicketInput, UpdateTicketInput ) from pydantic import Field from uuid import UUID # We define each tool mapping directly to the Pydantic schemas from the registry. # However, Pydantic schemas defined in tool_registry often omit `workspace_id` and `role` # because those are injected by the executor from the graph state. # Since LangChain tools directly expose their schemas to the LLM, the schemas here # match exactly what the LLM should provide. @tool(args_schema=KBSearchInput) async def kb_search(query: str, **kwargs) -> str: """Search the Knowledge Base for relevant articles, technical documentation, and 'how-to' guides. USE THIS for any technical or process-related questions.""" # Execution logic is handled in the graph executor pass @tool(args_schema=TicketQueryInput) async def tickets(ticket_id: Optional[str] = None, status_filter: Optional[str] = None, **kwargs) -> str: """Retrieve ticket status, AI summaries, and recent activity. USE THIS to check on active issues or historical ticket data.""" pass @tool(args_schema=AnalyticsInput) async def analytics(**kwargs) -> str: """Fetch workspace metrics: volume trends, SLA compliance, category heatmaps. USE FOR: visualize, trends, charts, graphs, distribution, analysis.""" pass @tool(args_schema=SimilarIncidentsInput) async def similar_incidents(query: str, **kwargs) -> str: """Find top 3 similar resolved tickets for troubleshooting. USE ONLY for matching current errors against past known resolutions.""" pass @tool(args_schema=ProjectPulseInput) async def project_pulse(project_name: str, **kwargs) -> str: """A birds-eye view of a specific project's health and ticket distribution.""" pass @tool(args_schema=SentimentCheckInput) async def sentiment_check(ticket_id: str, **kwargs) -> str: """Retrieve message history for sentiment and pulse analysis on a ticket.""" pass @tool(args_schema=AssignTicketInput) async def assign_ticket(ticket_id: str, target_user_id: str, **kwargs) -> str: """Assign a ticket to a specific agent. Requires human approval.""" pass @tool(args_schema=UpdateStatusInput) async def update_status(ticket_id: str, new_status: str, **kwargs) -> str: """Update a ticket's status (e.g. to RESOLVED, CLOSED). Requires human approval.""" pass @tool(args_schema=RemediateInput) async def remediate(action: str, user_email: Optional[str] = None, service_name: Optional[str] = None, region: Optional[str] = None, **kwargs) -> str: """Execute automated fix (RESET_VPN, RESTART_SERVICE, FLUSH_CACHE). Requires human approval.""" pass @tool(args_schema=MemoryRecallInput) async def memory_recall(query: str, **kwargs) -> str: """Search deep user history and crystallized facts. USE ONLY for recurring problems, historical fixes, or 'have we done this before?'.""" pass @tool(args_schema=PlatformRefreshInput) async def platform_refresh(**kwargs) -> str: """Trigger platform-wide forensic diagnostic cycle. USE ONLY if Super-Admin asks for a platform update or strategic report refresh.""" pass @tool(args_schema=CreateTicketInput) async def create_ticket(title: str, description: str, priority: str = "MEDIUM", **kwargs) -> str: """Create a new support ticket when a user describes a new problem.""" pass @tool(args_schema=UpdateTicketInput) async def update_ticket(ticket_id: str, comment: str, status: Optional[str] = None, **kwargs) -> str: """Add a comment or update the status of an existing ticket.""" pass # We also need to map the "tool names" string from tool_registry to these actual @tool objects LANGCHAIN_TOOLS = { "KB_SEARCH": kb_search, "TICKETS": tickets, "ANALYTICS": analytics, "SIMILAR_INCIDENTS": similar_incidents, "PROJECT_PULSE": project_pulse, "SENTIMENT_CHECK": sentiment_check, "ASSIGN_TICKET": assign_ticket, "UPDATE_STATUS": update_status, "REMEDIATE": remediate, "MEMORY_RECALL": memory_recall, "PLATFORM_REFRESH": platform_refresh, "CREATE_TICKET": create_ticket, "UPDATE_TICKET": update_ticket, }