Create a Function Call tool
Create Function Call tools for LLMs by importing an OpenAPI specification, manually entering APIs, or uploading a code package.
Prerequisites
-
AgentRun is activated and you have access to the AgentRun console.
-
To import an OpenAPI specification, you need an API service URL or document that conforms to the OpenAPI 3.0 specification.
-
To create a tool with a code package, you need the code package in ZIP format.
Creation methods
On the create tool or skill page, select Function Call as the type, then choose one of the following creation methods:
|
Method |
Description |
Use case |
|
Import OpenAPI spec |
Generates tool definitions automatically from an OpenAPI 3.0 specification. |
Best for existing API services with an OpenAPI specification. |
|
Manually enter API |
Manually configures the base URL and API endpoints. |
Best when you need to define API endpoints individually. |
|
Create with code/code package |
Uploads a code package to create a custom tool. |
Best when you need to implement custom tool logic. |
The Import Tools from Other Platforms feature is not yet available.
Steps
-
Log on to the AgentRun console.
-
In the left-side navigation pane, choose Tools & Skills.
-
Click Create Tool.
-
In the Creation Type section, select Function Call.
-
In the Creation Method section, select a method and complete the configuration as described in the following sections.
Import OpenAPI spec
If your API service has an OpenAPI 3.0 specification, import it to create a Function Call tool. The platform generates the tool definition from the specification automatically.
-
Configure the basic information.
Parameter
Required
Description
Tool Name
Yes
A unique name for the tool.
Description
No
A brief description of what the tool does, up to 256 characters long.
-
In the OpenAPI Specification editor, import the OpenAPI specification in one of the following ways:
-
Import via URL: Click Import via URL, enter the URL of the OpenAPI 3.0 document, and then click Import.
-
Paste directly: Paste the complete OpenAPI JSON or YAML content directly into the editor.
-
View example: Click Example to view a sample of the supported OpenAPI format.
-
-
In the workspace section, select a workspace from the drop-down list, or click the Create New button to create a new one. The default is "Default Workspace".
Manually enter API
To configure API endpoints individually, manually enter the API details to create a Function Call tool.
-
Configure the basic information.
Parameter
Required
Description
Tool Name
Yes
A unique name for the tool.
Description
No
A brief description of what the tool does, up to 256 characters long.
Base URL
Yes
The base URL of the API service, for example,
https://api.example.com/v1. -
In the API Endpoints section, click Add Endpoint to configure the API endpoint information. You must add at least one API endpoint.
Each endpoint has the following settings:
Parameter
Type
Description
Method
Drop-down list
The HTTP request method. Supported methods include GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS.
Path
Text input
The API path, for example,
/users.Endpoint description
Text area
A description of what the endpoint does, up to 1,000 characters long. This helps the agent understand the endpoint's purpose.
Query parameters
Parameter table
URL query parameters. Each row contains the parameter name, type, default value, and description.
Path parameters
Parameter table
URL path parameters. Each row contains the parameter name, type, default value, and description.
Headers
Parameter table
Custom request headers. Each row contains the header name, default value, and description.
-
(Optional) Configure the workspace. In the workspace section, select a workspace from the drop-down list, or click the Create New button to create a new one. The default is "Default Workspace".
Create with code package
To implement custom logic for a Function Call tool, upload a code package. The tool runs as a Function Compute HTTP function.
-
Configure the basic information.
Parameter
Required
Description
Tool Name
Yes
A unique name for the tool.
Description
No
A brief description of what the tool does, up to 256 characters long.
-
Select an execution environment.
Execution environment
Description
Python 3.13
Suitable for tools written in Python.
Node.js 22
Suitable for tools written in Node.js.
Container image
Suitable for tools with complex dependencies or custom runtime environments.
-
Configure the code source. Drag and drop your code package into the upload area. The file must be in ZIP format and no larger than 500 MB (or 100 MB in some regions).
-
Configure the startup parameters.
Parameter
Required
Description
Startup command
Yes
The command to execute when the tool starts, for example,
python3 main.py.Service port
Yes
The port number (1-65535) that the service listens on, with a default of 8080. This must match the port your application listens on.
-
Configure resources.
Parameter
Description
CPU (Cores)
The CPU specification for the tool instance. The default is 0.25 cores.
Memory (GB)
The memory specification for the tool instance. The default is 0.5 GB.
Timeout (seconds)
The maximum execution duration for a single request. The default is 300 seconds.
NoteThe vCPU-to-memory ratio must be between 1:1 and 1:4. For example, 0.25 cores corresponds to 256 MB to 1 GB of memory, and 1 core corresponds to 1 GB to 4 GB of memory.
-
(Optional) Configure OpenAPI.
In the OpenAPI configuration (optional) section, add an OpenAPI specification for the code-based tool. This helps the agent better understand the tool's parameters and responses.
Configuration method
Description
OpenAPI spec configuration
Paste or import an OpenAPI specification document.
Manual entry
Manually configure the API endpoint information.
-
(Optional) Configure environment variables.
In the Environment variables section, add environment variables in form or JSON mode. These variables are injected when the tool runs and can be used to:
-
Specify downstream service addresses or database connection strings.
-
Configure parameters such as log levels or run modes.
-
-
(Optional) Configure network.
If your tool needs to access resources within a Virtual Private Cloud (VPC), such as databases or application services, configure the network settings.
Parameter
Description
VPC ID
Select the VPC you want to access.
Subnet ID (vSwitch)
Select the corresponding vSwitch.
Security group
Controls inbound and outbound network access rules.
-
(Optional) Configure an OSS storage mount.
In the OSS storage mount section, configure the mount information to allow the tool to directly read and write files in Object Storage Service (OSS).
NoteBefore using an OSS storage mount, you must grant OSS access permission to the execution role, for example, by attaching the
AliyunOSSFullAccesspermission policy. -
(Optional) Configure a NAS storage mount.
You must configure the VPC network before you can use the Network Attached Storage (NAS) storage mount feature.
-
(Optional) Configure logging.
In the Log configuration section, enable log collection. When enabled, Log Service collects all log information from the tool, including request logs, error logs, and performance logs. You can use this data for troubleshooting, performance analysis, and monitoring alerts.
-
(Optional) Configure the execution role.
The execution role allows the Function Compute service (fc.aliyuncs.com) to access other Alibaba Cloud services. Select an existing role from the execution role drop-down list, or click the Create New button to create a new role in Resource Access Management (RAM).
Grant the appropriate permission policies to the execution role based on your tool's requirements. For example:
-
AliyunOSSFullAccess: To access OSS resources. -
AliyunVPCFullAccess: To access resources within a VPC.
-
-
(Optional) Configure access credentials.
In the Access credentials section, select a method for configuring credentials:
-
Use Existing Credentials: Select existing credentials from credential management.
-
Anonymous Access (Default): Does not carry any authentication information.
ImportantIn Anonymous Access mode, requests do not include authentication information. For production environments, configure credentials to ensure data security.
-
-
(Optional) Configure the workspace. In the workspace section, select a workspace from the drop-down list, or click the Create New button to create a new one. The default is "Default Workspace".
-
Click Create Now.
OpenAPI example
The following sample document conforms to the OpenAPI 3.0 specification. Use it as a reference when importing an OpenAPI specification:
{
"openapi": "3.0.0",
"info": {
"title": "Sample API",
"version": "1.0.0"
},
"servers": [
{
"url": "https://api.example.com/v1"
}
],
"paths": {
"/users": {
"get": {
"summary": "Get user list",
"operationId": "getUsers",
"responses": {
"200": {
"description": "Successfully returns a list of users"
}
}
}
}
}
}
Sample code
The following example shows a weather query Function Call tool implemented in Python:
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/get_weather', methods=['POST'])
def get_weather():
"""Queries the weather information for a specified city. In a real-world scenario, replace this with a call to an actual weather API."""
data = request.get_json()
city = data.get('city', 'unknown')
# This example only shows the framework. Replace the sample business logic with a call to an actual weather API.
# For example: resp = requests.get(f'https://api.weather.example.com/v1?city={city}', headers={'Authorization': f'Bearer {os.environ["WEATHER_API_KEY"]}'})
# weather_data = resp.json()
return jsonify({
'city': city,
'temperature': '-- Integrate with a real weather API --',
'weather': '-- Integrate with a real weather API --'
})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
FAQ
Choosing a creation method
|
Scenario |
Recommended method |
|
You have an existing API service with an OpenAPI specification. |
Import OpenAPI spec |
|
You need to configure a small number of API endpoints one by one. |
Manually enter API |
|
You need to implement custom tool logic. |
Create with code/code package |
OpenAPI spec import failures
-
Make sure the OpenAPI document conforms to the 3.0 specification.
-
Check whether required fields such as
pathsandcomponents.schemasare clearly defined. -
If you are importing from a URL, make sure the URL is accessible.
Tool startup failures
-
Confirm that the service in your code listens on
0.0.0.0instead of127.0.0.1. -
Ensure the port your application listens on matches the service port specified in the startup configuration.
-
If you are using a container image, make sure the port exposed in the Dockerfile matches the console configuration.
Code package upload failures
-
Make sure the code package is in ZIP format and does not exceed 500 MB (or 100 MB in some regions).
-
If the code package is large, remove unnecessary dependencies or files and upload again.
Runtime permission errors
-
Ensure the execution role has the required permission policies, such as
AliyunOSSFullAccessandAliyunVPCFullAccess. -
If you are using an OSS storage mount, make sure the mount configuration is correct and the execution role includes OSS access permissions.