
Adding Enterprise Context to Any Custom AI Agent
Any AI agent — whether built on LangChain, LlamaIndex, a custom Python stack, or calling LLM APIs directly — can access live organizational context from Nex via a single API call. This guide shows the core pattern and specific implementations for common agent frameworks.
The Universal Pattern
The agent receives a task requiring customer or organizational knowledge. It calls Nex /v1/context/ask with a natural language query. Nex returns structured, permissioned context from CRM, email, Slack, and warehouse data. The agent includes context in its LLM prompt. The LLM generates a grounded, accurate response.
Prerequisites
You need a Nex account at app.nex.ai with data sources connected, a Nex API key from Settings → API Keys, and Python 3.8+ or Node.js 18+.
Core Client Implementation
Create a minimal NexClient class in Python that wraps the Nex API. The client initializes with your API key (from environment or passed directly) and provides three core methods. The ask() method sends a natural language query to /v1/context/ask and returns structured context. The search() method performs full-text search across all records via /v1/search. The get_record() method retrieves a specific record with all attributes by ID. Initialize the client once and reuse it across your agent — all methods use Bearer token authentication and return JSON responses.
Framework-Specific Integrations
LangChain: Nex as a custom tool
Create a NexContextTool class extending LangChain's BaseTool. Define it with name "nex_organizational_context" and a description explaining it queries live organizational context from CRM, email, Slack, and business data. Use Pydantic's BaseModel for the input schema with a single query string field. The _run method calls nex.ask(query) and returns the answer. Wire this tool into a create_sales_agent() function that creates a ChatAnthropic LLM, builds a tool-calling agent with a sales intelligence system prompt, and returns an AgentExecutor. The agent will automatically call Nex when it needs customer data to answer questions.
Direct API agent (no framework)
For a framework-free approach, build a simple agent loop using the Anthropic SDK directly. Define a query_organizational_context tool in the tools array with an input schema accepting a natural language query string. In the agent loop, send the user's task to Claude with the tool definition. When Claude returns a tool_use block, extract the query, call nex.ask(), and feed the result back as a tool_result message. Continue looping until Claude produces a final text response. This pattern gives you full control over the agent loop while still leveraging Nex for live context retrieval.
Common Use Cases
AI Slack bot for sales intelligence
Deploy a Slack bot that any team member can query for instant account intelligence. When someone asks about a customer, the bot fetches Nex context for that account — deal stage, recent emails, open tickets — and returns a structured summary with source attribution. Scope the Nex API key to record.read and note.read permissions only for security.
Outbound email agent
Build an agent that drafts personalized outbound emails using real CRM and communication history. Query Nex for company details, past interactions, deal history, and personalization opportunities, then generate a tailored email grounded in actual relationship data.
Support ticket routing and enrichment
When a new support ticket arrives, enrich it with customer history before routing. Query Nex for account tier, open issues, past support history, and any escalation flags. Automatically set priority based on context — a ticket from an enterprise customer with an open renewal should route differently than a standard inquiry.
Custom agent with memory write-back
Agents can also write new context back to Nex after completing tasks. After a customer call, the agent writes call notes to Nex so future queries by any agent or team member reflect the latest interaction. This creates a feedback loop where agent actions enrich the context available for future agent tasks.
FAQ
Q: Does Nex work with any LLM provider?
Yes. The Nex API is provider-agnostic — it returns structured text context that you include in any LLM's prompt. The same pattern works with Claude, OpenAI, Gemini, Mistral, and any model that accepts system prompts or function calling.
Q: How do I control which data the agent can access?
Create separate Nex API keys for each agent role and configure permissions in the Nex dashboard. A sales agent key might have record.read access to deals and contacts; a support agent key might have access to tickets and notes but not deals. Permissions are enforced server-side.
Q: What's the latency of a Nex context query?
Typical /v1/context/ask response times are under 500ms for most queries. For latency-sensitive use cases, consider pre-fetching context when you know a customer interaction is about to begin.
Q: Can agents built on frameworks like LangChain or CrewAI use Nex?
Yes. Any agent that can call external APIs as part of its execution can use Nex. The Nex API is a standard REST API that any HTTP-capable agent can call — no SDK required.
Q: How do I handle Nex API errors in production agents?
Implement graceful degradation — if the Nex context call fails, the agent should proceed without context rather than failing entirely. Add retry logic with exponential backoff for transient errors. Log failures for monitoring.