API Endpoint Calling with SDKs in Generative AI Agents
Use this guide to become familiar with using the OCI Java SDK to integrate API endpoint calling into an application. The following steps show an OCI Java SDK example for creating an API endpoint calling tool and then using chat to invoke the tool.
Prerequisites
Before you begin, ensure that you have set up the following resources:
- An agent. See Creating an Agent in Generative AI Agents.
- An agent endpoint. See Creating an Endpoint in Generative AI Agents.
- A virtual cloud network (VCN) and a subnet.
- The necessary OCI SDK and dependencies installed in your development environment. See Setup and Prerequisites.
IAM Policies
Ensure that you add policies to give the appropriate permissions to access the OCI service's API operations that you want the agent to call.
In the example, the API endpoint calling tool interacts with Object Storage buckets. You can use the following policies to enable access to Object Storage in all compartments in the tenancy or restrict access to a specific compartment.
// To enable access to all compartments in the tenancy
allow any-user to manage object-family in tenancy where any {request.principal.type='genaiagent'}
// To enable access to a specific compartment in the tenancy
allow any-user to manage object-family in compartment <compartment-name> where any {request.principal.type='genaiagent'}
Replace <compartment-name>
with the compartment that you want to use.
Creating an API Endpoint Calling Tool
The following steps show how to use OCI Java SDK to create an API endpoint calling tool for an agent.
Chatting with an Agent
To initiate a conversation with the agent and use the HTTP endpoint tool, follow these steps: