The Agentforce Python 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.

This SDK empowers developers to leverage prompt templates, automate Apex class generation, build integrations with MCP servers, and experiment with different LLM models. In this post, we’ll walk you through the fundamentals of the Agentforce Python SDK and show you how to use it to build an agent.

Key features of the Agentforce Python SDK

The Agentforce Python SDK offers many features and benefits. Here are a few top reasons to use it:

  • Prompt templates: Generate and manage prompt templates with Salesforce field mappings
  • Apex class generation: Automate the creation and utilization of Apex classes 
  • MCP server Integrations: Integrate with MCP servers to enhance the functionality of AI agents
  • LLM model experimentation: Test various LLM models to optimize AI agent performance

Creating AI agents with the Agentforce Python SDK

The process of creating an AI agent using the Agentforce Python SDK involves several straightforward steps, including:

  1. Installation: Begin by installing the Agentforce Python SDK.
  2. Dependency import and credential setup: Import necessary dependencies and connect your Salesforce Developer Edition account by passing your credentials securely.
  3. Agent creation: Create an AI agent either programmatically or by using a JSON file. The SDK also supports creating agents from a directory structure.
  4. Deployment: Deploy the agent and monitor its status through logs.

Let’s now explore how to create your first agent using the SDK in Google Colab.

Building your first agent

For this walkthrough, we’re using a cloud-based Google Colab notebook, but you can run the examples using any editor or environment of your choice.

Here’s how to get started:

  1. Clone the example notebook:
  1. Install the SDK:

This command installs the SDK and sets up the development environment.

  1. Connect your Salesforce Developer account:
  • Use environment variables or Google Colab secrets to securely pass your Salesforce credentials
  • The SDK handles authentication behind the scenes
  1. Create your first agent (programmatically!):

While Agentforce supports multiple ways to create agents (via JSON files, directory structure, or programmatically), in this walkthrough, we’re using the programmatic approach for its simplicity.

Here’s a sneak peek:

Once deployed, you can confirm your agent in the UI, open it in Agent Builder, and view the topic and actions created.

The Agentforce Python SDK is a flexible and powerful toolkit for any developer looking to infuse Agentforce into their existing workflows.

You can also refer to the comprehensive documentation and leverage the examples to build and integrate agents into your workflows.

Conclusion

The Agentforce Python SDK represents a significant advancement in AI agent development within Salesforce. Its user-friendly interface, coupled with powerful features, makes it an indispensable tool for developers seeking to harness the full potential of AI in their Salesforce applications. The SDK is open-source, so you can give it a try and contribute towards the project.

Check out Agentforce Decoded to learn more about the Agentforce Python SDK. 

Resources

About the author

Akshata Sawant is a Senior Developer Advocate at Salesforce , and co-author of a book titled “MuleSoft for Salesforce Developers.” She’s a global speaker, and her notable speaking engagements include Dreamforce, London’s Calling, Salesforce TDX, Devoxx Belgium, DevopsDays Geneva, APIDays, and more. For a more in-depth look at Akshata’s accomplishments, visit her LinkedIn profile.