创建触发器
创建一个处于活跃状态的触发器,为智能体启动会话。
- cron 策略接受分钟粒度的五字段表达式和一个 IANA
timezone。实际触发会加入少量抖动。 - 智能体、环境、凭据库与记忆库引用在创建时校验。一个项目最多持有 200 个未归档的触发器。
- 每次触发向本次运行的会话投递
initial_events和一条平台上下文消息。
POST
/
v1
/
triggers
创建触发器
curl --request POST \
--url https://api.moonshot.cn/v1/triggers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Daily summary",
"agent_id": "agent_01h455vb4pex5vsknk084sn02q",
"environment_id": "env_01h455vb4pex5vsknk084sn02q",
"policy": {
"type": "cron",
"expression": "0 9 * * *",
"timezone": "UTC"
}
}
'import requests
url = "https://api.moonshot.cn/v1/triggers"
payload = {
"name": "Daily summary",
"agent_id": "agent_01h455vb4pex5vsknk084sn02q",
"environment_id": "env_01h455vb4pex5vsknk084sn02q",
"policy": {
"type": "cron",
"expression": "0 9 * * *",
"timezone": "UTC"
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Daily summary',
agent_id: 'agent_01h455vb4pex5vsknk084sn02q',
environment_id: 'env_01h455vb4pex5vsknk084sn02q',
policy: {type: 'cron', expression: '0 9 * * *', timezone: 'UTC'}
})
};
fetch('https://api.moonshot.cn/v1/triggers', 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://api.moonshot.cn/v1/triggers",
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([
'name' => 'Daily summary',
'agent_id' => 'agent_01h455vb4pex5vsknk084sn02q',
'environment_id' => 'env_01h455vb4pex5vsknk084sn02q',
'policy' => [
'type' => 'cron',
'expression' => '0 9 * * *',
'timezone' => 'UTC'
]
]),
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;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/triggers"
payload := strings.NewReader("{\n \"name\": \"Daily summary\",\n \"agent_id\": \"agent_01h455vb4pex5vsknk084sn02q\",\n \"environment_id\": \"env_01h455vb4pex5vsknk084sn02q\",\n \"policy\": {\n \"type\": \"cron\",\n \"expression\": \"0 9 * * *\",\n \"timezone\": \"UTC\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/triggers")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Daily summary\",\n \"agent_id\": \"agent_01h455vb4pex5vsknk084sn02q\",\n \"environment_id\": \"env_01h455vb4pex5vsknk084sn02q\",\n \"policy\": {\n \"type\": \"cron\",\n \"expression\": \"0 9 * * *\",\n \"timezone\": \"UTC\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/triggers")
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 \"name\": \"Daily summary\",\n \"agent_id\": \"agent_01h455vb4pex5vsknk084sn02q\",\n \"environment_id\": \"env_01h455vb4pex5vsknk084sn02q\",\n \"policy\": {\n \"type\": \"cron\",\n \"expression\": \"0 9 * * *\",\n \"timezone\": \"UTC\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "trig_01h455vb4pex5vsknk084sn02q",
"name": "Daily summary",
"status": "active",
"agent_id": "agent_01h455vb4pex5vsknk084sn02q",
"session_mode": "new_session",
"policy": {
"type": "cron",
"expression": "0 9 * * *",
"timezone": "UTC"
},
"scope": "project",
"created_by": "user_example",
"created_at": "2026-08-01T09:00:00Z",
"updated_at": "2026-08-01T09:00:00Z"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}请求头
请求体
application/json
创建触发器的请求体。
响应
已创建的触发器(活跃状态)。
保存的规则,按计划或按需启动智能体。
此页面对您有帮助吗?
⌘I
创建触发器
curl --request POST \
--url https://api.moonshot.cn/v1/triggers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Daily summary",
"agent_id": "agent_01h455vb4pex5vsknk084sn02q",
"environment_id": "env_01h455vb4pex5vsknk084sn02q",
"policy": {
"type": "cron",
"expression": "0 9 * * *",
"timezone": "UTC"
}
}
'import requests
url = "https://api.moonshot.cn/v1/triggers"
payload = {
"name": "Daily summary",
"agent_id": "agent_01h455vb4pex5vsknk084sn02q",
"environment_id": "env_01h455vb4pex5vsknk084sn02q",
"policy": {
"type": "cron",
"expression": "0 9 * * *",
"timezone": "UTC"
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Daily summary',
agent_id: 'agent_01h455vb4pex5vsknk084sn02q',
environment_id: 'env_01h455vb4pex5vsknk084sn02q',
policy: {type: 'cron', expression: '0 9 * * *', timezone: 'UTC'}
})
};
fetch('https://api.moonshot.cn/v1/triggers', 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://api.moonshot.cn/v1/triggers",
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([
'name' => 'Daily summary',
'agent_id' => 'agent_01h455vb4pex5vsknk084sn02q',
'environment_id' => 'env_01h455vb4pex5vsknk084sn02q',
'policy' => [
'type' => 'cron',
'expression' => '0 9 * * *',
'timezone' => 'UTC'
]
]),
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;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/triggers"
payload := strings.NewReader("{\n \"name\": \"Daily summary\",\n \"agent_id\": \"agent_01h455vb4pex5vsknk084sn02q\",\n \"environment_id\": \"env_01h455vb4pex5vsknk084sn02q\",\n \"policy\": {\n \"type\": \"cron\",\n \"expression\": \"0 9 * * *\",\n \"timezone\": \"UTC\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/triggers")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Daily summary\",\n \"agent_id\": \"agent_01h455vb4pex5vsknk084sn02q\",\n \"environment_id\": \"env_01h455vb4pex5vsknk084sn02q\",\n \"policy\": {\n \"type\": \"cron\",\n \"expression\": \"0 9 * * *\",\n \"timezone\": \"UTC\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/triggers")
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 \"name\": \"Daily summary\",\n \"agent_id\": \"agent_01h455vb4pex5vsknk084sn02q\",\n \"environment_id\": \"env_01h455vb4pex5vsknk084sn02q\",\n \"policy\": {\n \"type\": \"cron\",\n \"expression\": \"0 9 * * *\",\n \"timezone\": \"UTC\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "trig_01h455vb4pex5vsknk084sn02q",
"name": "Daily summary",
"status": "active",
"agent_id": "agent_01h455vb4pex5vsknk084sn02q",
"session_mode": "new_session",
"policy": {
"type": "cron",
"expression": "0 9 * * *",
"timezone": "UTC"
},
"scope": "project",
"created_by": "user_example",
"created_at": "2026-08-01T09:00:00Z",
"updated_at": "2026-08-01T09:00:00Z"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}