mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-01 02:43:37 +00:00
docs: enhance Salesforce Toolkit documentation (#31387)
## PR Title ``` docs: enhance Salesforce Toolkit documentation ``` ## PR Description **Description:** Enhanced the Salesforce Toolkit documentation to provide a more comprehensive overview of the `langchain-salesforce` package. The updates include improved descriptions of the toolkit's capabilities, detailed setup instructions for authentication using environment variables, updated code snippets with consistent parameter naming and improved readability, and additional resources with API references for better user guidance. **Issue:** N/A (documentation improvement) **Dependencies:** None **Twitter handle:** @colesmcintosh --- ### Changes Made: - Improved description of the Salesforce Toolkit's capabilities and features - Added detailed setup instructions for authentication using environment variables - Updated code snippets to use consistent parameter naming and improved readability - Included additional resources and API references for better user guidance - Enhanced overall documentation structure and clarity ### Files Modified: - `docs/docs/integrations/tools/salesforce.ipynb` (83 insertions, 36 deletions) This is a documentation-only change that improves the user experience for developers working with the Salesforce Toolkit. The changes are backwards compatible and follow LangChain's documentation standards. --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
17f34baa88
commit
ffa32a1802
@ -7,41 +7,59 @@
|
||||
"source": [
|
||||
"# Salesforce\n",
|
||||
"\n",
|
||||
"Tools for interacting with Salesforce.\n",
|
||||
"A tool for interacting with Salesforce CRM using LangChain.\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook provides examples of interacting with Salesforce using LangChain.\n"
|
||||
"The `langchain-salesforce` package integrates LangChain with Salesforce CRM,\n",
|
||||
"allowing you to query data, manage records, and explore object schemas\n",
|
||||
"from LangChain applications.\n",
|
||||
"\n",
|
||||
"### Key Features\n",
|
||||
"\n",
|
||||
"- **SOQL Queries**: Execute Salesforce Object Query Language (SOQL) queries\n",
|
||||
"- **Object Management**: Create, read, update, and delete (CRUD) operations on Salesforce objects \n",
|
||||
"- **Schema Exploration**: Describe object schemas and list available objects\n",
|
||||
"- **Async Support**: Asynchronous operation support\n",
|
||||
"- **Error Handling**: Detailed error messages\n",
|
||||
"- **Environment Variable Support**: Load credentials from environment variables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7fb27b941602401d91542211134fc71a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Setup\n",
|
||||
"\n",
|
||||
"1. Install the required dependencies:\n",
|
||||
"Install the required dependencies:\n",
|
||||
" \n",
|
||||
"```bash\n",
|
||||
" pip install langchain-salesforce\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"2. Set up your Salesforce credentials as environment variables:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
" export SALESFORCE_USERNAME=\"your-username\"\n",
|
||||
" export SALESFORCE_PASSWORD=\"your-password\" \n",
|
||||
" export SALESFORCE_SECURITY_TOKEN=\"your-security-token\"\n",
|
||||
" export SALESFORCE_DOMAIN=\"test\" # Use 'test' for sandbox, remove for production\n",
|
||||
"```\n",
|
||||
" pip install langchain-salesforce\n",
|
||||
" ```\n",
|
||||
" \n",
|
||||
"## Authentication Setup\n",
|
||||
"\n",
|
||||
"These environment variables will be automatically picked up by the integration.\n",
|
||||
"\n",
|
||||
" \n",
|
||||
"## Getting Your Security Token\n",
|
||||
" \n",
|
||||
"If you need a security token:\n",
|
||||
"1. Log into Salesforce\n",
|
||||
"2. Go to Settings\n",
|
||||
"3. Click on \"Reset My Security Token\" under \"My Personal Information\"\n",
|
||||
"4. Check your email for the new token"
|
||||
" 1. Log into Salesforce\n",
|
||||
" 2. Go to Settings\n",
|
||||
" 3. Click on \"Reset My Security Token\" under \"My Personal Information\"\n",
|
||||
" 4. Check your email for the new token\n",
|
||||
" \n",
|
||||
"### Environment Variables (Recommended)\n",
|
||||
" \n",
|
||||
" Set up your Salesforce credentials as environment variables:\n",
|
||||
" \n",
|
||||
" ```bash\n",
|
||||
" export SALESFORCE_USERNAME=\"your-username@company.com\"\n",
|
||||
" export SALESFORCE_PASSWORD=\"your-password\"\n",
|
||||
" export SALESFORCE_SECURITY_TOKEN=\"your-security-token\"\n",
|
||||
" export SALESFORCE_DOMAIN=\"login\" # Use \"test\" for sandbox environments\n",
|
||||
" ```"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -101,7 +119,7 @@
|
||||
" request[\"record_data\"] = record_data\n",
|
||||
" if record_id:\n",
|
||||
" request[\"record_id\"] = record_id\n",
|
||||
" result = tool.run(request)\n",
|
||||
" result = tool.invoke(request)\n",
|
||||
" return result"
|
||||
]
|
||||
},
|
||||
@ -122,7 +140,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"query_result = execute_salesforce_operation(\n",
|
||||
" \"query\", query=\"SELECT Id, Name, Email FROM Contact LIMIT 5\"\n",
|
||||
" operation=\"query\", query=\"SELECT Id, Name, Email FROM Contact LIMIT 5\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@ -142,7 +160,9 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"describe_result = execute_salesforce_operation(\"describe\", object_name=\"Account\")"
|
||||
"describe_result = execute_salesforce_operation(\n",
|
||||
" operation=\"describe\", object_name=\"Account\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -161,7 +181,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"list_objects_result = execute_salesforce_operation(\"list_objects\")"
|
||||
"list_objects_result = execute_salesforce_operation(operation=\"list_objects\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -181,7 +201,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"create_result = execute_salesforce_operation(\n",
|
||||
" \"create\",\n",
|
||||
" operation=\"create\",\n",
|
||||
" object_name=\"Contact\",\n",
|
||||
" record_data={\"LastName\": \"Doe\", \"Email\": \"doe@example.com\"},\n",
|
||||
")"
|
||||
@ -204,7 +224,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"update_result = execute_salesforce_operation(\n",
|
||||
" \"update\",\n",
|
||||
" operation=\"update\",\n",
|
||||
" object_name=\"Contact\",\n",
|
||||
" record_id=\"003XXXXXXXXXXXXXXX\",\n",
|
||||
" record_data={\"Email\": \"updated@example.com\"},\n",
|
||||
@ -228,7 +248,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"delete_result = execute_salesforce_operation(\n",
|
||||
" \"delete\", object_name=\"Contact\", record_id=\"003XXXXXXXXXXXXXXX\"\n",
|
||||
" operation=\"delete\", object_name=\"Contact\", record_id=\"003XXXXXXXXXXXXXXX\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@ -247,23 +267,47 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain.prompts import PromptTemplate\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"from langchain_anthropic import ChatAnthropic\n",
|
||||
"from langchain_core.messages import HumanMessage\n",
|
||||
"from langchain_salesforce import SalesforceTool\n",
|
||||
"\n",
|
||||
"# Initialize the Salesforce tool\n",
|
||||
"tool = SalesforceTool(\n",
|
||||
" username=username, password=password, security_token=security_token, domain=domain\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"llm = ChatOpenAI(model=\"gpt-4o-mini\")\n",
|
||||
"# Initialize Anthropic LLM\n",
|
||||
"llm = ChatAnthropic(model=\"claude-sonnet-4-20250514\")\n",
|
||||
"\n",
|
||||
"prompt = PromptTemplate.from_template(\n",
|
||||
" \"What is the name of the contact with the id {contact_id}?\"\n",
|
||||
")\n",
|
||||
"# First, let's query some contacts to get real data\n",
|
||||
"contacts_query = {\n",
|
||||
" \"operation\": \"query\",\n",
|
||||
" \"query\": \"SELECT Id, Name, Email, Phone FROM Contact LIMIT 3\",\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"chain = prompt | tool.invoke | llm\n",
|
||||
"contacts_result = tool.invoke(contacts_query)\n",
|
||||
"\n",
|
||||
"result = chain.invoke({\"contact_id\": \"003XXXXXXXXXXXXXXX\"})"
|
||||
"# Now let's use the LLM to analyze and summarize the contact data\n",
|
||||
"if contacts_result and \"records\" in contacts_result:\n",
|
||||
" contact_data = contacts_result[\"records\"]\n",
|
||||
"\n",
|
||||
" # Create a message asking the LLM to analyze the contact data\n",
|
||||
" analysis_prompt = f\"\"\"\n",
|
||||
" Please analyze the following Salesforce contact data and provide insights:\n",
|
||||
" \n",
|
||||
" Contact Data: {contact_data}\n",
|
||||
" \n",
|
||||
" Please provide:\n",
|
||||
" 1. A summary of the contacts\n",
|
||||
" 2. Any patterns you notice\n",
|
||||
" 3. Suggestions for data quality improvements\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" message = HumanMessage(content=analysis_prompt)\n",
|
||||
" analysis_result = llm.invoke([message])\n",
|
||||
"\n",
|
||||
" print(\"\\nLLM Analysis:\")\n",
|
||||
" print(analysis_result.content)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -271,8 +315,17 @@
|
||||
"id": "b8467ae7",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## API reference\n",
|
||||
"[langchain-salesforce README](https://github.com/colesmcintosh/langchain-salesforce/blob/main/README.md)"
|
||||
"## API Reference\n",
|
||||
"\n",
|
||||
"For comprehensive documentation and API reference, see:\n",
|
||||
"\n",
|
||||
"- [langchain-salesforce README](https://github.com/colesmcintosh/langchain-salesforce/blob/main/README.md)\n",
|
||||
"- [Simple Salesforce Documentation](https://simple-salesforce.readthedocs.io/en/latest/)\n",
|
||||
"\n",
|
||||
"## Additional Resources\n",
|
||||
"\n",
|
||||
"- [Salesforce SOQL Reference](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/)\n",
|
||||
"- [Salesforce REST API Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/)"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user