Agents
Criar uma ferramenta de função reutilizável
POST
/
api
/
v1
/
agents
/
function-tools
Go (SDK)
package main
import(
"context"
mka1 "github.com/MeetKai/mka1-sdks/go"
"github.com/MeetKai/mka1-sdks/go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := mka1.New(
mka1.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Agents.CreateFunctionTool(ctx, components.AgentsFunctionToolDefinition{
Type: components.AgentsFunctionToolDefinitionTypeFunction,
Name: "lookup_order",
Description: mka1.Pointer("Look up an order"),
Parameters: map[string]any{
"type": "object",
"properties": map[string]any{
"order_id": map[string]any{
"type": "string",
},
},
"required": []any{
"order_id",
},
"additionalProperties": false,
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.FunctionTool != nil {
// handle response
}
}using MeetKai.MKA1;
using MeetKai.MKA1.Types.Components;
using System.Collections.Generic;
var sdk = new SDK(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.Agents.CreateFunctionToolAsync(body: new AgentsFunctionToolDefinition() {
Type = AgentsFunctionToolDefinitionType.Function,
Name = "lookup_order",
Description = "Look up an order",
Parameters = new Dictionary<string, object>() {
{ "type", "object" },
{ "properties", new Dictionary<string, object>() {
{ "order_id", new Dictionary<string, object>() {
{ "type", "string" },
} },
} },
{ "required", new List<object>() {
"order_id",
} },
{ "additionalProperties", false },
},
});
// handle responsefrom meetkai_mka1 import SDK
with SDK(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as sdk:
res = sdk.agents.create_function_tool(type_="function", name="lookup_order", parameters={
"type": "object",
"properties": {
"order_id": {
"type": "string",
},
},
"required": [
"order_id",
],
"additionalProperties": False,
}, description="Look up an order", strict=True)
# Handle response
print(res)import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.agents.createFunctionTool({
agentsFunctionToolDefinition: {
type: "function",
name: "lookup_order",
description: "Look up an order",
parameters: {
"type": "object",
"properties": {
"order_id": {
"type": "string",
},
},
"required": [
"order_id",
],
"additionalProperties": false,
},
},
});
console.log(result);
}
run();curl --request POST \
--url https://apigw.mka1.com/api/v1/agents/function-tools \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"type": "function",
"name": "lookup_order",
"description": "Consultar um pedido",
"parameters": {
"type": "object",
"properties": {
"order_id": {
"type": "string"
}
},
"required": [
"order_id"
],
"additionalProperties": false
},
"strict": true
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
type: 'function',
name: 'lookup_order',
description: 'Consultar um pedido',
parameters: {
type: 'object',
properties: {order_id: {type: 'string'}},
required: ['order_id'],
additionalProperties: false
},
strict: true
})
};
fetch('https://apigw.mka1.com/api/v1/agents/function-tools', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://apigw.mka1.com/api/v1/agents/function-tools",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'type' => 'function',
'name' => 'lookup_order',
'description' => 'Consultar um pedido',
'parameters' => [
'type' => 'object',
'properties' => [
'order_id' => [
'type' => 'string'
]
],
'required' => [
'order_id'
],
'additionalProperties' => false
],
'strict' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://apigw.mka1.com/api/v1/agents/function-tools")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"function\",\n \"name\": \"lookup_order\",\n \"description\": \"Consultar um pedido\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"order_id\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"order_id\"\n ],\n \"additionalProperties\": false\n },\n \"strict\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apigw.mka1.com/api/v1/agents/function-tools")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"type\": \"function\",\n \"name\": \"lookup_order\",\n \"description\": \"Consultar um pedido\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"order_id\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"order_id\"\n ],\n \"additionalProperties\": false\n },\n \"strict\": true\n}"
response = http.request(request)
puts response.read_body{
"object": "agent.function_tool",
"id": "<string>",
"definition": {
"type": "function",
"name": "<string>",
"parameters": {},
"description": "<string>",
"strict": true,
"defer_loading": true
},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}Autorizações
Send Authorization: Bearer , using an MKA1 API key for automation or an OAuth API access token for a signed-in application. Use a dynamic security callback to refresh OAuth access tokens. Browser session-only operations still require their declared cookie.
Cabeçalhos
Optional external end-user identifier forwarded by the API gateway.
Corpo
application/json
Esta página foi útil?
⌘I
Go (SDK)
package main
import(
"context"
mka1 "github.com/MeetKai/mka1-sdks/go"
"github.com/MeetKai/mka1-sdks/go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := mka1.New(
mka1.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Agents.CreateFunctionTool(ctx, components.AgentsFunctionToolDefinition{
Type: components.AgentsFunctionToolDefinitionTypeFunction,
Name: "lookup_order",
Description: mka1.Pointer("Look up an order"),
Parameters: map[string]any{
"type": "object",
"properties": map[string]any{
"order_id": map[string]any{
"type": "string",
},
},
"required": []any{
"order_id",
},
"additionalProperties": false,
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.FunctionTool != nil {
// handle response
}
}using MeetKai.MKA1;
using MeetKai.MKA1.Types.Components;
using System.Collections.Generic;
var sdk = new SDK(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");
var res = await sdk.Agents.CreateFunctionToolAsync(body: new AgentsFunctionToolDefinition() {
Type = AgentsFunctionToolDefinitionType.Function,
Name = "lookup_order",
Description = "Look up an order",
Parameters = new Dictionary<string, object>() {
{ "type", "object" },
{ "properties", new Dictionary<string, object>() {
{ "order_id", new Dictionary<string, object>() {
{ "type", "string" },
} },
} },
{ "required", new List<object>() {
"order_id",
} },
{ "additionalProperties", false },
},
});
// handle responsefrom meetkai_mka1 import SDK
with SDK(
bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
) as sdk:
res = sdk.agents.create_function_tool(type_="function", name="lookup_order", parameters={
"type": "object",
"properties": {
"order_id": {
"type": "string",
},
},
"required": [
"order_id",
],
"additionalProperties": False,
}, description="Look up an order", strict=True)
# Handle response
print(res)import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.agents.createFunctionTool({
agentsFunctionToolDefinition: {
type: "function",
name: "lookup_order",
description: "Look up an order",
parameters: {
"type": "object",
"properties": {
"order_id": {
"type": "string",
},
},
"required": [
"order_id",
],
"additionalProperties": false,
},
},
});
console.log(result);
}
run();curl --request POST \
--url https://apigw.mka1.com/api/v1/agents/function-tools \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"type": "function",
"name": "lookup_order",
"description": "Consultar um pedido",
"parameters": {
"type": "object",
"properties": {
"order_id": {
"type": "string"
}
},
"required": [
"order_id"
],
"additionalProperties": false
},
"strict": true
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
type: 'function',
name: 'lookup_order',
description: 'Consultar um pedido',
parameters: {
type: 'object',
properties: {order_id: {type: 'string'}},
required: ['order_id'],
additionalProperties: false
},
strict: true
})
};
fetch('https://apigw.mka1.com/api/v1/agents/function-tools', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://apigw.mka1.com/api/v1/agents/function-tools",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'type' => 'function',
'name' => 'lookup_order',
'description' => 'Consultar um pedido',
'parameters' => [
'type' => 'object',
'properties' => [
'order_id' => [
'type' => 'string'
]
],
'required' => [
'order_id'
],
'additionalProperties' => false
],
'strict' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://apigw.mka1.com/api/v1/agents/function-tools")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"function\",\n \"name\": \"lookup_order\",\n \"description\": \"Consultar um pedido\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"order_id\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"order_id\"\n ],\n \"additionalProperties\": false\n },\n \"strict\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apigw.mka1.com/api/v1/agents/function-tools")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"type\": \"function\",\n \"name\": \"lookup_order\",\n \"description\": \"Consultar um pedido\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"order_id\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"order_id\"\n ],\n \"additionalProperties\": false\n },\n \"strict\": true\n}"
response = http.request(request)
puts response.read_body{
"object": "agent.function_tool",
"id": "<string>",
"definition": {
"type": "function",
"name": "<string>",
"parameters": {},
"description": "<string>",
"strict": true,
"defer_loading": true
},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}