We are excited to introduce our first agentic knowledge assistant - your 24/7 Salesforce analyst!
In this write-up, we share details of how we built this agent, along with our framework for extending it to other connectors such as JIRA, Zendesk, and Gmail. We are also introducing "Text to SQL" structured query language capabilities to our Salesforce connector.
Problem Statement
When we first built our Salesforce connector, we implemented advanced fuzzy keyword and semantic search capabilities. While powerful, we quickly discovered our customers needed more. They asked complex, parametric questions that our search couldn't handle effectively.
Our existing system handled basic Salesforce searches effectively, particularly those focused on finding specific opportunities using keywords within our indexed data (title, content, metadata). However, it struggled with more complex user queries that:
Involved relationships between Salesforce objects (Accounts, Opportunities, Contacts, and Tasks)
Examples:
"Show me all opportunities for the United Oil account."
"What tasks are associated with the United Oil account and are due this week?"
Required filtering on specific field values
Examples:
"Show me all opportunities closed won in the last week."
"What are my overdue tasks?"
Needed information not in our search index
Examples:
"What are the details on John Doe?" (Contact details)
"Who is the account owner for Acme Corp?"
Needed a broad search across multiple objects/fields, then filtering
Examples:
"Find all opportunities related to 'renewable energy' that are in 'Negotiation' stage."
"Show me opportunities related to companies or people matching 'cloud solutions'"
These limitations prevented users from asking natural, intuitive questions about their Salesforce data. Additionally, in some cases, as there was no keyword or semantic meaning to search for in the first place, the search would lead to irrelevant retrieval noise in our RAG pipeline.
Enter Text-to-SQL: Precision meets natural language
To solve this, we're introducing Text-to-SQL capabilities in our Salesforce connector. This feature allows our agent to translate natural language questions into precise SQL queries, giving you more control than ever on your search scope.
Instead of using our own SQL database, we picked Salesforce's powerful SOSL (Salesforce Object Search Language) and SOQL (Salesforce Object Query Language) APIs. This allows us to avoid crawling years' worth of Salesforce records & still provide powerful queries over all of the data in seconds.
We will now get into the details of these APIs and how to use them.
Why SOSL and SOQL?
Here's a short crash course on these powerful APIs from Salesforce.
SOSL (Salesforce Object Search Language)
Best for: Broad text searches. Imagine a Google search within Salesforce.
Use it when: You don't know exactly where the information is (which object or field) or you need to search across many objects at once.
Example:
FIND {renewable energy} IN ALL FIELDS (finds "renewable energy" anywhere).
SOQL (Salesforce Object Query Language)
Best for: Structured queries with precise filtering and relationships. Like a particular database query.
Use it when: You know exactly which object and fields you need, and you need to filter based on specific values or relationships.
Example:
SELECT Id, Name FROM Opportunity WHERE StageName = 'Closed Won' AND CloseDate = THIS_YEAR (finds opportunities that are closed won this year).
Sometimes you need both!
Broad Search + Narrowing Down: Use SOSL to find a set of possible records, then use SOQL to filter those records further based on criteria that SOSL can't handle.
Example:
Query: "Find all opportunities related to renewable energy in the negotiation stage."
SOSL: FIND {renewable energy} IN ALL FIELDS RETURNING Opportunity(Id, Name, StageName) (broad search).
SOQL: SELECT Id, Name, StageName FROM Opportunity WHERE StageName = 'Negotiation' AND Id IN (<ids from SOSL>) (filter by stage).
Thankfully, modern LLMs are trained on the language powering these APIs, allowing us to generatively create them on the fly based on user queries.
Enter 24/7 Agent for your Salesforce data
We now describe our agentic search framework, which allows users to speak to their business data. By implementing an AI agent as an intermediary between user queries and various search tools, we've created a system that intelligently determines the most efficient strategy to retrieve relevant information. The agent can also easily be extended to other CRMs and apps like Zendesk, Gmail, Calendar, etc.
Agent Architecture
The agent sits at the forefront of the architecture, acting as an intelligent & flexible middleware between user queries and the backend infrastructure. This design allows for efficient query routing and seamlessly extending the agent's capabilities in the future.
Core Tools
The framework consists of four primary tools available to the agent:
- Salesforce Object Search Language (SOSL) API from Salesforce
- Salesforce Object Query Language (SOQL) API from Salesforce
- Proprietary indexed and embedded vector data for workspace content
- Native text-search API for historical text search from Salesforce
We document these tools in detail so that the agent can understand when to use them and, if needed, how to use them effectively.
Agentic Workflow
We then give the Agent a high-level workflow to follow for every user query, but with flexibility driven by its reasoning on how to navigate the workflow. The sequence is:

1. User Intent Analysis
The agent initiates by decoding the user's intent through multi-layered analysis:
- Domain Classification: Determines whether the query relates to Salesforce objects (e.g., accounts, opportunities) or requires external tools.
- Tool Requirement Assessment: Evaluates which Salesforce search tool or mix of tools are necessary based on the user's intent and search scope.
This phase resolves ambiguities early, ensuring downstream processes align with the user's goals.
2. Tool Selection
Leveraging insights from intent analysis, the framework selects optimal tools and strategies:
- Requirement-Tool Matching: Maps query parameters (e.g., date filters, relationship mapping) to available tools.
- Strategy Optimization: Prioritizes execution order—for example, running parametric date filters before semantic keyword searches to narrow the dataset.
- Finalization: Confirms tool sequence and prepares for execution.
This phase eliminates redundant tool usage and ensures resource efficiency.
3. Tool Execution
Once the intent is translated into exact tool or mixture of tools to use, the agent moves towards orchestrating the execution of these tools. The agent has to command our backend code to do this via precise instructions. The agent does this by executing the following steps:
- Entity & relationship extraction: Based on the user query, the agent selects Salesforce objects (accounts, opportunities, tasks & contacts) & the relationships between them ("opportunities linked to Account X")
- Parametric search scope extraction: Likewise, the agent constructs the exact set of criteria the user has specified in terms of date-ranges, personnel, keywords, amounts or other fields.
- Query Construction & Submission: The agent then speaks the language of each of the tools it needs to use. It translates the above entities, relationships, and search filters into the exact parameters, configurations, and/or queries to send to the backend to execute these tools (Salesforce SOSL and SOQL API, Elasticsearch). We use a simple JSON-formatted payload to explain this to the backend.
- Response Handling: The agent then waits for the backend to respond. Once the responses start coming from the various tools, the agent collates responses, validates results, resolves errors & prepares an appropriate response for the user based on the combined response from the tools used.
The key innovation in any agentic framework is that the backend tools are decoupled from the workflow, and the agent is given some level of flexibility to use its reasoning in orchestrating the worfklow and responding to the user accordingly.
Key Benefits
There are several benefits from this release of our Salesforce connector.
- Text to SQL querying via SoSL and SoQL APIs enable extremely powerful analysis, but now possible conversationally
- Analytics become accessible - 24/7 across the sales and management organizations
- Unlimited access to historical data going back years
- Low cost and operational footprint
- Foundation for Agentic search, actions & workflows for various workplace apps
Conclusion
We are excited to introduce this next-generation Salesforce connector & hope this write-up helps explain the technical details behind how to create it in-house.
For more information about implementing this connector or to schedule a demonstration, please get in touch with our sales team via our website - www.ayraa.io