Configure API Connections to Third-Party Software as Skill Agents
Step 1: Defining the Programmed Skill Agent
1.1. Creating the API Integration Skill Agent
import requests
from composabl import SkillController
# Define the programmed skill
class ThirdPartyAPISkill(SkillController):
def __init__(self, *args, **kwargs):
self.api_url = "https://api.example.com/machine-status"
async def compute_action(self, obs, action):
# Send sensor data to the third-party API
response = self._call_api(obs)
# Process the response and return an action
action = self._process_response(response)
return action
def _call_api(self, observation):
try:
response = requests.post(
self.api_url,
json=observation,
headers={'Content-Type': 'application/json'}
)
response.raise_for_status()
return response.json()
except requests.RequestException as e:
print(f"API call failed: {e}")
return None
def _process_response(self, response):
if not response:
# Default action
return 0.0
action = float(response.get("action"))
reason = response.get("reason", "No reason provided")
print(f"Action: {action} - Reason: {reason}")
return action
async def transform_sensors(self, obs):
return obs
async def filtered_sensor_space(self):
return ['sensor1', 'sensor2', 'sensor3']
async def compute_success_criteria(self, transformed_obs, action):
return False
async def compute_termination(self, transformed_obs, action):
return FalseStep 2: Adding the Programmed Skill Agent to the Agent System
2.1. Adding the Skill Agent to AMESA UI
2.2. Adding the Skill Agent to AMESA SDK
Conclusion
Last updated