Spaces:
Paused
Paused
Download agents/tools/langchain_tools.py from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 4.72 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/agents/tools/langchain_tools.py
- Command line
-
hf download hf://spaces/TeamError404/nexus/agents/tools/langchain_tools.py
-
curl -L -o langchain_tools.py https://huggingface.co/spaces/TeamError404/nexus/resolve/main/agents/tools/langchain_tools.py
4.72 kB
| """ | |
| 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. | |
| 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 | |
| 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 | |
| async def analytics(**kwargs) -> str: | |
| """Fetch workspace metrics: volume trends, SLA compliance, category heatmaps. USE FOR: visualize, trends, charts, graphs, distribution, analysis.""" | |
| pass | |
| 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 | |
| async def project_pulse(project_name: str, **kwargs) -> str: | |
| """A birds-eye view of a specific project's health and ticket distribution.""" | |
| pass | |
| async def sentiment_check(ticket_id: str, **kwargs) -> str: | |
| """Retrieve message history for sentiment and pulse analysis on a ticket.""" | |
| pass | |
| async def assign_ticket(ticket_id: str, target_user_id: str, **kwargs) -> str: | |
| """Assign a ticket to a specific agent. Requires human approval.""" | |
| pass | |
| 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 | |
| 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 | |
| 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 | |
| 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 | |
| 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 | |
| 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, | |
| } | |