We are thrilled to announce the General Availability (GA) release of the OpenAPI package for Semantic Kernel, available for both .NET and Python! With this significant milestone, developers can easily integrate existing APIs as plugins, enhancing the capabilities of their AI agents while making them more versatile in real-world applications.
Why OpenAPI Plugins Matter
In many enterprises, a robust set of APIs already exists, facilitating critical functions for automation services and front-end applications. Semantic Kernel now allows you to harness these APIs—transforming them into plugins that your agents can utilize. This not only streamlines processes but also empowers developers to leverage existing functionalities within their AI solutions.
Example Use Case
Imagine an API that allows users to manage the states of light bulbs in a smart home environment. The corresponding OpenAPI specification will provide comprehensive details, including endpoints for retrieving all lights and modifying the state of specific lights. This structured information enables the AI agent to interpret and interact with the API seamlessly.
{
"openapi": "3.0.1",
"info": {
"title": "Light API",
"version": "v1"
},
"paths": {
"/Light": {
"get": {
"tags": [
"Light"
],
"summary": "Retrieves all lights in the system.",
"operationId": "get_all_lights",
"responses": {
"200": {
"description": "Returns a list of lights with their current state",
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LightStateModel"
}
}
}
}
}
}
}
}
}
This straightforward OpenAPI specification highlights semantic descriptions, parameter types, and expected responses, making it accessible for AI interpretation.
Adding the OpenAPI Plugin
Integrating an OpenAPI plugin into your agent requires only a few lines of code. As an example, here’s how you can add the light management plugin described above:
C# code
await this._kernel.ImportPluginFromOpenApiAsync(
pluginName: "lights",
uri: new Uri("https://example.com/v1/swagger.json"),
executionParameters: new OpenApiFunctionExecutionParameters()
{
EnablePayloadNamespacing = true
}
);
Python code
kernel.add_plugin_from_openapi(
plugin_name="lights",
openapi_document_path="https://example.com/v1/swagger.json",
execution_parameters=OpenAPIFunctionExecutionParameters(
enable_payload_namespacing=True
)
)
Once added, you can use this plugin as if it were a native feature of your agent, enhancing its functionality without significant overhead.
Tips for Crafting AI-Friendly OpenAPI Specifications
To make your OpenAPI specifications more compatible with AI agents, consider the following tips:
- Version control:Â Keep your API specifications versioned to allow testing without impacting live services.
- Simplify:Â Limit the number of endpoints and consolidate similar functionalities to reduce complexity.
- Descriptive names:Â Utilize clear, descriptive names for endpoints and parameters to enhance understanding.
- Avoid string parameters: Favor specific types like integers and Booleans to facilitate better AI interpretation.
- Provide examples:Â Include example requests and responses in the descriptions to guide the AI.
You can refer to our Tips and Tricks for Adding OpenAPI Plugins for more detailed guidance on crafting effective specifications.
Next Steps
Now that you understand how to create and integrate OpenAPI plugins for your agents, you can explore various function patterns according to the functionalities you’ve implemented. Whether you’re utilizing retrieval functions or task automation functions, the possibilities for enhanced AI engagement are boundless.
We are excited to witness how you leverage the GA release of the OpenAPI plugin to amplify the capabilities of your Semantic Kernel agents. Together, let’s push the boundaries of what AI can achieve in practical applications!
0 comments
Be the first to start the discussion.