Python SDK for creating, managing, and deploying AI agents in Salesforce
Project description
Salesforce AgentForce SDK
A Python SDK for creating, managing, and deploying AI agents and prompt templates in Salesforce.
Introduction
The Salesforce AgentForce SDK provides a programmatic interface to Salesforce's Agent infrastructure, allowing developers to define and interact with agents using Python code. It also includes tools for generating and managing prompt templates with Salesforce field mappings.
Installation
pip install agentforce-sdk
Dependencies
The SDK has several dependencies that will be installed automatically, including:
requests: For HTTP requests to Salesforce APIssimple-salesforce: For Salesforce authentication and API accessaiohttp: For asynchronous HTTP operations, especially in deployment toolsjsonschema: For validating agent and template configurationspython-dotenv: For environment variable managementopenai: For LLM API integration
If you encounter import errors when using deployment features, ensure that aiohttp is properly installed:
pip install aiohttp>=3.8.0
Features
- Create and manage AI agents in Salesforce
- Generate and manage prompt templates with Salesforce field mappings
- Support for various Salesforce field types and relationships
- Automatic Apex class generation for related data queries
- Template tuning for different LLM models
- Multiple formats for defining agents (JSON, nested directory, modular directory)
- MCP server for HTTP-based integration
Documentation
Comprehensive documentation for the SDK is available in the docs directory:
- API Documentation: Detailed documentation for all SDK components, classes, and methods.
- JSON Schemas: JSON schemas for validating agent definitions in various formats.
Examples
Prompt Template Examples
The SDK provides several examples demonstrating prompt template functionality:
- Basic Template Generation: Generate a prompt template with Salesforce field mappings
- Template with Apex Actions: Create a template that includes Apex invocable actions
- Template Tuning: Tune an existing template for different LLM models
- Template Deployment: Deploy a prompt template to Salesforce
Basic Template Generation
The examples/generate_prompt_template_example.py script demonstrates how to generate a prompt template with Salesforce field mappings:
python examples/generate_prompt_template_example.py \
--username your_username \
--password your_password \
--security-token your_security_token \
--output_dir templates \
--model gpt-4
This will:
- Connect to your Salesforce org
- Generate a prompt template with appropriate field mappings
- Save the template and any generated Apex classes to the specified output directory
Template with Apex Actions
The examples/generate_template_with_apex_example.py script shows how to create a template that includes Apex invocable actions:
python examples/generate_template_with_apex_example.py \
--username your_username \
--password your_password \
--security-token your_security_token \
--output_dir templates \
--model gpt-4
This example demonstrates:
- Creating a template for account opportunity analysis
- Including Apex invocable actions for data manipulation
- Generating necessary Apex classes for the actions
- Saving the complete template with action mappings
Template Tuning
The examples/tune_prompt_template_example.py script demonstrates how to tune an existing template for different LLM models:
python examples/tune_prompt_template_example.py \
--username your_username \
--password your_password \
--security-token your_security_token \
--template-path templates/my_template.json \
--output_dir tuned_templates \
--model gpt-4
This example shows how to:
- Load an existing template
- Optimize it for specific LLM models
- Add explicit instructions and validation rules
- Save the enhanced template
Template Deployment
The examples/deploy_prompt_template_example.py script shows how to deploy a template to Salesforce:
python examples/deploy_prompt_template_example.py \
--username your_username \
--password your_password \
--security-token your_security_token \
--template-path templates/my_template.json \
--validate-only
This example demonstrates:
- Loading a template from a JSON file
- Validating the template before deployment
- Deploying the template and associated components
- Monitoring deployment status and handling errors
Arguments
Common arguments across examples:
--username: Your Salesforce username (required)--password: Your Salesforce password (required)--security-token: Your Salesforce security token (optional)--output_dir: Directory to save generated files (default varies by example)--model: Model to use for generation/tuning (default: 'gpt-4')
Example-specific arguments:
--template-path: Path to an existing template JSON file (for tuning and deployment)--validate-only: Only validate the deployment without actually deploying (deployment example)--description: Additional context for template tuning (tuning example)
Output
The examples generate various outputs depending on their function:
- Template JSON files with field mappings
- Generated Apex classes for actions and queries
- Deployment status and validation results
- Detailed logs of operations performed
Agent Examples
The examples directory contains additional sample code for agent functionality:
- Creating an agent programmatically
- Creating an agent from a JSON file
- Creating an agent from a nested directory
- Creating an agent from a modular directory
- Creating an agent from a description
- Creating an agent with user-specified metadata
- Creating Apex classes
- Running an agent
- Exporting an agent
- Using the MCP server
Quick Start
from agent_sdk import Agentforce
from agent_sdk.core.auth import BasicAuth
from agent_sdk.utils.prompt_templates.prompt_template_utils import PromptTemplateUtils
# Initialize authentication
auth = BasicAuth(username="your_username", password="your_password")
# Initialize the client
client = Agentforce(auth=auth)
# Generate a prompt template
prompt_utils = PromptTemplateUtils(client.sf)
template = prompt_utils.generate_prompt_template(
name="Account Health Analysis",
description="Generate a health analysis for an account",
output_dir="templates",
model="gpt-4"
)
print(f"Template saved to: {template}")
Project Structure
agent-sdk/
├── agent_sdk/
│ ├── core/
│ │ ├── agentforce.py
│ │ ├── auth.py
│ │ ├── base.py
│ │ └── prompt_template_utils.py
│ └── models/
│ ├── agent.py
│ └── prompt_template.py
├── examples/
│ ├── generate_prompt_template_example.py
│ └── [other examples]
└── README.md
Development
You'll require poetry >= 2.0 for dependency management. To install it, follow the instructions on their website.
To contribute to the project:
- Clone the repository
- Create a virtual environment and install dependencies:
poetry install - Run tests:
pytest
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentforce_sdk-0.2.1.tar.gz.
File metadata
- Download URL: agentforce_sdk-0.2.1.tar.gz
- Upload date:
- Size: 78.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf358433a81c57084f8161059e6270f5916ff39e740999a255c23d5a1a0942ec
|
|
| MD5 |
727add875cd509ff1ab6f4fc02dbb034
|
|
| BLAKE2b-256 |
f845c14cdce1eedc724082561904e656f853eefc0bbeb22dc9e0011b715982c8
|
File details
Details for the file agentforce_sdk-0.2.1-py3-none-any.whl.
File metadata
- Download URL: agentforce_sdk-0.2.1-py3-none-any.whl
- Upload date:
- Size: 104.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e13314185b2d002d423d6550381bdd65eaeba809806b531f4895b64ccf3b9e5
|
|
| MD5 |
f8509c5cdbff704758ab5e626ea7448f
|
|
| BLAKE2b-256 |
1ae83f8ede24b83e05a7a091f0f9017d941c479b2326140f84f48939e25c5f26
|