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.

Nex.ai® and Nex® are a registered trademark by GarageSpace, Inc.
All rights reserved.

Nex.ai® and Nex® are a registered
trademark by GarageSpace, Inc. All rights reserved.

Nex.ai® and Nex® are a registered
trademark by GarageSpace, Inc. All rights reserved.