Configure API Connections to Third-Party Software as Skills
In this tutorial, we will walk through how to set up a skill in Composabl that integrates with a third-party API. This type of integration allows your agent to communicate with external systems, such as machine performance APIs, and use the data to make informed decisions.
We will create a programmed skill that connects to a mock third-party API, process its response, and return an action based on the data received. This tutorial will also touch on orchestrating this skill within your agent.
Step 1: Defining the Programmed Skill
A programmed skill in Composabl is created by specifying the logic for interacting with the external API and processing the response. In this case, we will create a simple API connection to a fake endpoint that returns data about machine performance. The agent will act based on the information received.
1.1. Creating the API Integration Skill
We’ll define a programmed skill for making the API request. Here's an example of how to define the skill using a controller function that calls the API and processes the response.
In this example:
The
compute_action()
method sends observation data (e.g., from sensors) to a third-party API.The
_call_api()
function makes the API call and handles any errors that might occur.The
_process_response()
function processes the response from the third-party API and determines the appropriate action for the agent to take based on the data.
Step 2: Adding the Programmed Skill to the Agent
2.1. Adding the Skill to Composabl UI
Once the skill is defined, you can add it to your agent in the UI using the methods below:
Create a new Skill using the Composabl CLI with a given name and description and implementation type, that in this case will be a
controller
. The name will be "third_party_api_skill"
Change the
controller.py
code to use the class that you created:ThirdPartyAPISkill()
. Change thepyproject.toml
file to include your classThirdPartyAPISkill
in the entrypoint and its name:
Publish the Skill to the UI
Select your organization and project that you want to publish it to.
Reference: https://docs.composabl.io/changelog/0-8-0.html
2.2. Adding the Skill to Composabl SDK
Once the skill is defined, you can add it to your agent using the add_skill()
SDK method. This allows the agent to execute the API connection skill when necessary.
Here’s how to add the ThirdPartyAPISkill
to the agent:
By importing and creating the class with SkillController
, you are indicating that this skill is programmed and does not require training. It will use predefined logic to interact with the third-party API and make decisions based on the data returned.
Conclusion
By following these steps, you’ve successfully defined and integrated a programmed skill that communicates with a third-party API into your Composabl agent. The agent can now take actions based on external data and dynamically respond to scenarios.
This approach allows agents to interface with a wide range of external systems, from monitoring equipment to adjusting machine settings, all through programmable skills.
Orchestration of skills through selectors ensures the agent executes the correct skills at the right time, whether the skills are learned or programmed.
Last updated