オートメーションを使うと、cron スケジュールに従ってエージェントのセッションを開始できます。エージェントの automations ツールを有効にすると、エージェント自身が作業中に次のタスクをスケジュールすることもできます。
cron スケジュールによるセッションの自動実行
cron 式とタイムゾーンを指定して、新しいセッションを開始したり、既存のセッションを継続したりできます。
エージェントによるオートメーションの作成
automations ツールを追加すると、エージェントが現在のセッションでフォローアップをスケジュールできます。
オートメーションの呼び出し状況の確認
呼び出しごとに、セッションへのタスク送信を試みた記録が残ります。そのステータスとセッション ID を確認できます。
cron スケジュール エージェントによるオートメーション 呼び出し 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import OpenAI from "openai" ;
const client = new OpenAI ();
const automation = await client.beta.agents.automations. create ({
type: "periodic" ,
name: "Daily session" ,
expression: "0 10 * * *" ,
timezone: "America/New_York" ,
target: {
type: "new_session" ,
agent_id: "agt_123" ,
environment: { type: "openai_hosted" },
input: [
{
role: "user" ,
content: [
{
type: "input_text" ,
text: "Summarize the current status and next steps." ,
},
],
},
],
},
});
console. log (automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 from openai import OpenAI
client = OpenAI()
automation = client.beta.agents.automations.create(
type="periodic",
name="Daily session",
expression="0 10 * * *",
timezone="America/New_York",
target={
"type": "new_session",
"agent_id": "agt_123",
"environment": {"type": "openai_hosted"},
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Summarize the current status and next steps.",
}
],
}
],
},
)
print(automation.to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
automation, err := client.Beta.Agents.Automations.New(ctx,
openai.BetaAgentAutomationNewParams{
CreateAutomationParams: openai.AutomationScheduleParamUnion{
OfParamPeriodic: &openai.AutomationScheduleParamPeriodic{
Name: "Daily session",
Expression: "0 10 * * *",
Timezone: "America/New_York",
Target: openai.AutomationTargetParamUnion{
OfParamNewSession: &openai.AutomationTargetParamNewSession{
AgentID: openai.String("agt_123"),
Environment: openai.EnvironmentParamUnion{
OfParamOpenAIHosted: &openai.EnvironmentParamOpenAIHosted{},
},
Input: []openai.AgentSessionInputMessageParam{
{
Content: []openai.InputContentParamUnion{
{
OfParamInputText: &openai.InputContentParamInputText{
Text: "Summarize the current status and next steps.",
},
},
},
},
},
},
},
},
},
})
if err != nil {
panic(err)
}
fmt.Println(automation.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.AgentSessionInputMessageParam;
import com.openai.models.beta.agents.EnvironmentParam;
import com.openai.models.beta.agents.automations.AutomationCreateParams;
import com.openai.models.beta.agents.automations.AutomationScheduleParam;
import com.openai.models.beta.agents.automations.AutomationTargetParam;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var automation =
client
.beta()
.agents()
.automations()
.create(
AutomationCreateParams.builder()
.automationScheduleParam(
AutomationScheduleParam.Periodic.builder()
.name("Daily session")
.expression("0 10 * * *")
.timezone("America/New_York")
.target(
AutomationTargetParam.NewSession.builder()
.agentId("agt_123")
.environment(EnvironmentParam.OpenAIHosted.builder().build())
.addInput(
AgentSessionInputMessageParam.builder()
.addInputTextContent(
"Summarize the current status and next steps.")
.build())
.build())
.build())
.build());
System.out.println(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentAutomation automation = await client.CreateAutomationAsync(
new AgentAutomationCreationOptions
{
Type = AgentAutomationType.Periodic,
Name = "Daily session",
Expression = "0 10 * * *",
Timezone = "America/New_York",
Target = new NewSessionAutomationTarget
{
AgentId = "agt_123",
Environment = new EnvironmentParamOpenaiHosted(),
Input =
[
new InputMessageParam(
[new InputContentParamInputText("Summarize the current status and next steps.")]
),
],
},
}
);
Console.WriteLine(automation.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 require "openai"
client = OpenAI::Client.new
automation = client.beta.agents.automations.create(
body: {
type: "periodic",
name: "Daily session",
expression: "0 10 * * *",
timezone: "America/New_York",
target: {
type: "new_session",
agent_id: "agt_123",
environment: { type: "openai_hosted" },
input: [
{
role: "user",
content: [
{
type: "input_text",
text: "Summarize the current status and next steps."
}
]
}
]
}
}
)
puts automation 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 curl https://api.openai.com/v1/agents/automations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "periodic",
"name": "Daily session",
"expression": "0 10 * * *",
"timezone": "America/New_York",
"target": {
"type": "new_session",
"agent_id": "agt_123",
"environment": {
"type": "openai_hosted"
},
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Summarize the current status and next steps."
}
]
}
]
}
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import OpenAI from "openai" ;
const client = new OpenAI ();
const session = await client.beta.agents.sessions. create ({
agent: {
model: "gpt-6-astra" ,
instructions:
"Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks." ,
tools: [{ type: "automations" }],
multi_agent: { enabled: true },
},
environment: { type: "openai_hosted" },
input:
"Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take." ,
});
console. log (session.id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 from openai import OpenAI
client = OpenAI()
session = client.beta.agents.sessions.create(
agent={
"model": "gpt-6-astra",
"instructions": (
"Use automations to schedule tasks requested by the user. "
"Delegate each scheduled task to a subagent and ask for a concise result. "
"Keep the goal, schedule, and useful summaries in the main session. "
"Adjust or stop schedules when the user asks."
),
"multi_agent": {"enabled": True},
"tools": [{"type": "automations"}],
},
environment={"type": "openai_hosted"},
input=(
"Every day at 10 AM in America/New_York, review the goals we discuss here "
"and suggest the next actions I could take."
),
)
print(session.id) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
session, err := client.Beta.Agents.Sessions.New(ctx,
openai.BetaAgentSessionNewParams{
Agent: openai.BetaAgentSessionNewParamsAgent{
Model: openai.String("gpt-6-astra"),
Instructions: openai.String("Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks."),
MultiAgent: openai.MultiAgentConfigParam{
Enabled: true,
},
Tools: []openai.AgentToolParamUnion{
{OfParamAutomations: &openai.AgentToolParamAutomations{}},
},
},
Environment: openai.EnvironmentParamUnion{
OfParamOpenAIHosted: &openai.EnvironmentParamOpenAIHosted{},
},
Input: openai.BetaAgentSessionNewParamsInputUnion{
OfString: openai.String("Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take."),
},
})
if err != nil {
panic(err)
}
fmt.Println(session.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.EnvironmentParam;
import com.openai.models.beta.agents.MultiAgentConfigParam;
import com.openai.models.beta.agents.sessions.SessionCreateParams;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var session =
client
.beta()
.agents()
.sessions()
.create(
SessionCreateParams.builder()
.agent(
SessionCreateParams.Agent.builder()
.model("gpt-6-astra")
.instructions(
"Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.")
.multiAgent(MultiAgentConfigParam.builder().enabled(true).build())
.addToolAutomations()
.build())
.environment(EnvironmentParam.OpenAIHosted.builder().build())
.input(
"Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take.")
.build());
System.out.println(session.id()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentSession session = await client.CreateAgentSessionAsync(
new AgentSessionCreationOptions
{
Agent = new SessionAgentConfigParam
{
Model = "gpt-6-astra",
Instructions = "Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.",
MultiAgent = new MultiAgentConfigParam { Enabled = true },
Tools = [new AgentToolConfigParamAutomations()],
},
Environment = new EnvironmentParamOpenaiHosted(),
Input =
[
new InputMessageParam(
[new InputContentParamInputText("Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take.")]
),
],
}
);
Console.WriteLine(session.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14 require "openai"
client = OpenAI::Client.new
session = client.beta.agents.sessions.create(
agent: {
model: "gpt-6-astra",
instructions: "Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.",
multi_agent: { enabled: true },
tools: [{ type: "automations" }]
},
environment: { type: "openai_hosted" },
input: "Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take."
)
puts session.id 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 curl https://api.openai.com/v1/agents/sessions \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent": {
"model": "gpt-6-astra",
"instructions": "Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.",
"tools": [{ "type": "automations" }],
"multi_agent": { "enabled": true }
},
"environment": {
"type": "openai_hosted"
},
"input": "Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take."
}' 1
2
3
4
5
6
7
8 import OpenAI from "openai" ;
const client = new OpenAI ();
for await ( const invocation of client.beta.agents.automations.invocations. list (
"auto_123"
)) {
console. log (invocation.id, invocation.status, invocation.session_id);
} 1
2
3
4
5
6 from openai import OpenAI
client = OpenAI()
invocations = client.beta.agents.automations.invocations.list(automation_id="auto_123")
for invocation in invocations:
print(invocation.id, invocation.status, invocation.session_id) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
invocations := client.Beta.Agents.Automations.Invocations.ListAutoPaging(ctx, "auto_123",
openai.BetaAgentAutomationInvocationListParams{})
for invocations.Next() {
invocation := invocations.Current()
fmt.Println(invocation.ID, invocation.Status, invocation.SessionID)
}
if err := invocations.Err(); err != nil {
panic(err)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.automations.invocations.InvocationListParams;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var invocations =
client
.beta()
.agents()
.automations()
.invocations()
.list(InvocationListParams.builder().automationId("auto_123").build());
for (var invocation : invocations.autoPager()) {
System.out.println(
invocation.id() + " " + invocation.status() + " " + invocation.sessionId());
} 1
2
3
4
5
6
7
8
9
10 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
await foreach (AgentAutomationInvocation invocation in client.GetAutomationInvocationsAsync("auto_123"))
{
Console.WriteLine($"{invocation.Id} {invocation.Status} {invocation.SessionId}");
} 1
2
3
4
5
6
7 require "openai"
client = OpenAI::Client.new
invocations = client.beta.agents.automations.invocations.list("auto_123")
invocations.auto_paging_each do |invocation|
puts "#{invocation.id} #{invocation.status} #{invocation.session_id}"
end 1
2
3 curl https://api.openai.com/v1/agents/automations/auto_123/invocations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY"
実行するタイミングと対象のセッションを保存します。
呼び出し
/v1/agents/automations/{automation_id}/invocations
タスクの送信時刻と、タスクを受け取ったセッションを確認します。
セッションイベント
/v1/agents/sessions/{session_id}/events
レストランの空席確認 毎月の支出の見直し その日の行動提案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import OpenAI from "openai" ;
const client = new OpenAI ();
const automation = await client.beta.agents.automations. create ({
type: "periodic" ,
name: "Check restaurant reservations" ,
expression: "0 */2 * * *" ,
timezone: "America/New_York" ,
target: {
type: "existing_session" ,
session_id: "sess_123" ,
instructions:
"Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables." ,
},
});
console. log (automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from openai import OpenAI
client = OpenAI()
automation = client.beta.agents.automations.create(
type="periodic",
name="Check restaurant reservations",
expression="0 */2 * * *",
timezone="America/New_York",
target={
"type": "existing_session",
"session_id": "sess_123",
"instructions": (
"Check restaurant availability for our dinner plans. "
"Compare with earlier checks and report newly available tables."
),
},
)
print(automation.to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
automation, err := client.Beta.Agents.Automations.New(ctx,
openai.BetaAgentAutomationNewParams{
CreateAutomationParams: openai.AutomationScheduleParamUnion{
OfParamPeriodic: &openai.AutomationScheduleParamPeriodic{
Name: "Check restaurant reservations",
Expression: "0 */2 * * *",
Timezone: "America/New_York",
Target: openai.AutomationTargetParamUnion{
OfParamExistingSession: &openai.AutomationTargetParamExistingSession{
SessionID: "sess_123",
Instructions: "Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables.",
},
},
},
},
})
if err != nil {
panic(err)
}
fmt.Println(automation.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.automations.AutomationCreateParams;
import com.openai.models.beta.agents.automations.AutomationScheduleParam;
import com.openai.models.beta.agents.automations.AutomationTargetParam;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var automation =
client
.beta()
.agents()
.automations()
.create(
AutomationCreateParams.builder()
.automationScheduleParam(
AutomationScheduleParam.Periodic.builder()
.name("Check restaurant reservations")
.expression("0 */2 * * *")
.timezone("America/New_York")
.target(
AutomationTargetParam.ExistingSession.builder()
.sessionId("sess_123")
.instructions(
"Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables.")
.build())
.build())
.build());
System.out.println(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentAutomation automation = await client.CreateAutomationAsync(
new AgentAutomationCreationOptions
{
Type = AgentAutomationType.Periodic,
Name = "Check restaurant reservations",
Expression = "0 */2 * * *",
Timezone = "America/New_York",
Target = new ExistingSessionAutomationTarget
{
SessionId = "sess_123",
Instructions = "Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables.",
},
}
);
Console.WriteLine(automation.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 require "openai"
client = OpenAI::Client.new
automation = client.beta.agents.automations.create(
body: {
type: "periodic",
name: "Check restaurant reservations",
expression: "0 */2 * * *",
timezone: "America/New_York",
target: {
type: "existing_session",
session_id: "sess_123",
instructions: "Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables."
}
}
)
puts automation 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 curl https://api.openai.com/v1/agents/automations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "periodic",
"name": "Check restaurant reservations",
"expression": "0 */2 * * *",
"timezone": "America/New_York",
"target": {
"type": "existing_session",
"session_id": "sess_123",
"instructions": "Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables."
}
}'
オートメーションは、エージェントのタスクをいつ実行するかを定めたスケジュールです。Agents API はスケジュールを保存し、対象のセッションに各タスクを送信します。
タスクを定義します。 実行するタイミングと、実行のたびに新しいセッションを開始するか、既存のセッションを継続するかを選びます。
タスクを送信します。 実行のたびに呼び出し が作成され、対象のセッションへのタスク送信を試みたことが記録されます。セッションが処理中の場合、タスクは待機します。
結果を確認します。 エージェントはセッションのツールとコンテキストを使って作業します。セッションイベントを追跡して進捗を確認し、結果を取得します。セッションがタスクを受け取った時点では、エージェントの作業が完了したとは限りません。
アプリケーションでは、API を通じてスケジュールの作成、更新、一時停止、削除ができます。automations ツールを有効にすると、エージェント自身が現在のセッションで次回の確認をスケジュールすることもできます。
タスクに過去の会話履歴が必要かどうかに応じて、対象のセッションを選びます。
対象
用途
必要な設定
new_session
毎月の支出の見直しなど、単独で完結する作業
エージェント、環境、および target.input に指定する初期メッセージ
existing_session
セッションで以前に得られた結果を使うフォローアップ
セッション ID、および target.instructions に指定するリマインダーのテキスト
実行のタイミングは、対象のセッションとは別に選びます。
種類
時刻の指定に使うフィールド
例
periodic
expression と timezone
毎日、America/New_York の現地時刻で午前 10 時に実行します。
once
run_at
秒単位の Unix タイムスタンプで指定した将来の時刻に、1 回だけ確認します。
どちらのスケジュールも、新しいセッションと既存のセッションの両方に使えます。オートメーションを作成すると、ステータスが active の状態で保存されます。タスクがすぐに実行されるわけではありません。定期オートメーションの初回実行は、次にスケジュールと一致する時刻に設定されます。
オートメーションを作成する前に、タスクに必要な指示とツールを備えたエージェントを作成し、ユーザーのカレンダー、タスク、メッセージにアクセスできるようにします。複数のセッションでのエージェントの再利用 を参照してください。
SDK は OpenAI-Beta: agents=v1 ヘッダーを自動で付与します。cURL で API を呼び出す場合は、このヘッダーを指定してください。
次の例では、ニューヨークの現地時刻で毎日午前 10 時に新しいセッションを開始するオートメーションを作成します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import OpenAI from "openai";
const client = new OpenAI();
const automation = await client.beta.agents.automations.create({
type: "periodic",
name: "Daily suggestions",
expression: "0 10 * * *",
timezone: "America/New_York",
target: {
type: "new_session",
agent_id: "agt_123",
environment: { type: "openai_hosted" },
input: [
{
role: "user",
content: [
{
type: "input_text",
text: "Review my calendar, tasks, and recent messages for today. Suggest the most useful actions I could take today, with a short reason for each.",
},
],
},
],
},
});
console.log(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 from openai import OpenAI
client = OpenAI()
automation = client.beta.agents.automations.create(
type = "periodic" ,
name = "Daily suggestions" ,
expression = "0 10 * * *" ,
timezone = "America/New_York" ,
target = {
"type" : "new_session" ,
"agent_id" : "agt_123" ,
"environment" : { "type" : "openai_hosted" },
"input" : [
{
"role" : "user" ,
"content" : [
{
"type" : "input_text" ,
"text" : (
"Review my calendar, tasks, and recent messages for today. "
"Suggest the most useful actions I could take today, "
"with a short reason for each."
),
}
],
}
],
},
)
print (automation.to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
automation, err := client.Beta.Agents.Automations.New(ctx,
openai.BetaAgentAutomationNewParams{
CreateAutomationParams: openai.AutomationScheduleParamUnion{
OfParamPeriodic: &openai.AutomationScheduleParamPeriodic{
Name: "Daily suggestions",
Expression: "0 10 * * *",
Timezone: "America/New_York",
Target: openai.AutomationTargetParamUnion{
OfParamNewSession: &openai.AutomationTargetParamNewSession{
AgentID: openai.String("agt_123"),
Environment: openai.EnvironmentParamUnion{
OfParamOpenAIHosted: &openai.EnvironmentParamOpenAIHosted{},
},
Input: []openai.AgentSessionInputMessageParam{
{
Content: []openai.InputContentParamUnion{
{
OfParamInputText: &openai.InputContentParamInputText{
Text: "Review my calendar, tasks, and recent messages for today. Suggest the most useful actions I could take today, with a short reason for each.",
},
},
},
},
},
},
},
},
},
})
if err != nil {
panic(err)
}
fmt.Println(automation.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.AgentSessionInputMessageParam;
import com.openai.models.beta.agents.EnvironmentParam;
import com.openai.models.beta.agents.automations.AutomationCreateParams;
import com.openai.models.beta.agents.automations.AutomationScheduleParam;
import com.openai.models.beta.agents.automations.AutomationTargetParam;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var automation =
client
.beta()
.agents()
.automations()
.create(
AutomationCreateParams.builder()
.automationScheduleParam(
AutomationScheduleParam.Periodic.builder()
.name("Daily suggestions")
.expression("0 10 * * *")
.timezone("America/New_York")
.target(
AutomationTargetParam.NewSession.builder()
.agentId("agt_123")
.environment(EnvironmentParam.OpenAIHosted.builder().build())
.addInput(
AgentSessionInputMessageParam.builder()
.addInputTextContent(
"Review my calendar, tasks, and recent messages for today. Suggest the most useful actions I could take today, with a short reason for each.")
.build())
.build())
.build())
.build());
System.out.println(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentAutomation automation = await client.CreateAutomationAsync(
new AgentAutomationCreationOptions
{
Type = AgentAutomationType.Periodic,
Name = "Daily suggestions",
Expression = "0 10 * * *",
Timezone = "America/New_York",
Target = new NewSessionAutomationTarget
{
AgentId = "agt_123",
Environment = new EnvironmentParamOpenaiHosted(),
Input =
[
new InputMessageParam(
[new InputContentParamInputText("Review my calendar, tasks, and recent messages for today. Suggest the most useful actions I could take today, with a short reason for each.")]
),
],
},
}
);
Console.WriteLine(automation.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 require "openai"
client = OpenAI::Client.new
automation = client.beta.agents.automations.create(
body: {
type: "periodic",
name: "Daily suggestions",
expression: "0 10 * * *",
timezone: "America/New_York",
target: {
type: "new_session",
agent_id: "agt_123",
environment: { type: "openai_hosted" },
input: [
{
role: "user",
content: [
{
type: "input_text",
text: "Review my calendar, tasks, and recent messages for today. Suggest the most useful actions I could take today, with a short reason for each."
}
]
}
]
}
}
)
puts automation 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 curl https://api.openai.com/v1/agents/automations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "periodic",
"name": "Daily suggestions",
"expression": "0 10 * * *",
"timezone": "America/New_York",
"target": {
"type": "new_session",
"agent_id": "agt_123",
"environment": {
"type": "openai_hosted"
},
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Review my calendar, tasks, and recent messages for today. Suggest the most useful actions I could take today, with a short reason for each."
}
]
}
]
}
}'
後でスケジュールを確認、管理できるよう、レスポンスで返されたオートメーションの id を保存してください。呼び出しのたびに新しい会話が始まります。上記の環境設定では、そのセッション用に OpenAI がホストするサンドボックス が用意されます。
エージェントの設定を target.agent に直接指定することも、保存済みエージェントの target.agent_id を指定することもできます。どちらか一方だけを指定してください。初期メッセージはリクエストの最上位ではなく、target.input 内に指定します。空でないテキストまたは画像 URL を含むメッセージが少なくとも 1 件必要です。
同じ方法で毎月の支出を見直すこともできます。保存済みのエージェントがユーザーの取引記録を参照できるようにし、毎月 1 日の午前 9 時に新しいセッションを開始するようスケジュールします。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import OpenAI from "openai";
const client = new OpenAI();
const automation = await client.beta.agents.automations.create({
type: "periodic",
name: "Monthly spending review",
expression: "0 9 1 * *",
timezone: "America/New_York",
target: {
type: "new_session",
agent_id: "agt_123",
environment: { type: "openai_hosted" },
input: [
{
role: "user",
content: [
{
type: "input_text",
text: "Review my spending for the previous month. Flag unused subscriptions, price increases, and other potential savings for me to review.",
},
],
},
],
},
});
console.log(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 from openai import OpenAI
client = OpenAI()
automation = client.beta.agents.automations.create(
type = "periodic" ,
name = "Monthly spending review" ,
expression = "0 9 1 * *" ,
timezone = "America/New_York" ,
target = {
"type" : "new_session" ,
"agent_id" : "agt_123" ,
"environment" : { "type" : "openai_hosted" },
"input" : [
{
"role" : "user" ,
"content" : [
{
"type" : "input_text" ,
"text" : (
"Review my spending for the previous month. Flag unused "
"subscriptions, price increases, and other potential "
"savings for me to review."
),
}
],
}
],
},
)
print (automation.to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
automation, err := client.Beta.Agents.Automations.New(ctx,
openai.BetaAgentAutomationNewParams{
CreateAutomationParams: openai.AutomationScheduleParamUnion{
OfParamPeriodic: &openai.AutomationScheduleParamPeriodic{
Name: "Monthly spending review",
Expression: "0 9 1 * *",
Timezone: "America/New_York",
Target: openai.AutomationTargetParamUnion{
OfParamNewSession: &openai.AutomationTargetParamNewSession{
AgentID: openai.String("agt_123"),
Environment: openai.EnvironmentParamUnion{
OfParamOpenAIHosted: &openai.EnvironmentParamOpenAIHosted{},
},
Input: []openai.AgentSessionInputMessageParam{
{
Content: []openai.InputContentParamUnion{
{
OfParamInputText: &openai.InputContentParamInputText{
Text: "Review my spending for the previous month. Flag unused subscriptions, price increases, and other potential savings for me to review.",
},
},
},
},
},
},
},
},
},
})
if err != nil {
panic(err)
}
fmt.Println(automation.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.AgentSessionInputMessageParam;
import com.openai.models.beta.agents.EnvironmentParam;
import com.openai.models.beta.agents.automations.AutomationCreateParams;
import com.openai.models.beta.agents.automations.AutomationScheduleParam;
import com.openai.models.beta.agents.automations.AutomationTargetParam;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var automation =
client
.beta()
.agents()
.automations()
.create(
AutomationCreateParams.builder()
.automationScheduleParam(
AutomationScheduleParam.Periodic.builder()
.name("Monthly spending review")
.expression("0 9 1 * *")
.timezone("America/New_York")
.target(
AutomationTargetParam.NewSession.builder()
.agentId("agt_123")
.environment(EnvironmentParam.OpenAIHosted.builder().build())
.addInput(
AgentSessionInputMessageParam.builder()
.addInputTextContent(
"Review my spending for the previous month. Flag unused subscriptions, price increases, and other potential savings for me to review.")
.build())
.build())
.build())
.build());
System.out.println(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentAutomation automation = await client.CreateAutomationAsync(
new AgentAutomationCreationOptions
{
Type = AgentAutomationType.Periodic,
Name = "Monthly spending review",
Expression = "0 9 1 * *",
Timezone = "America/New_York",
Target = new NewSessionAutomationTarget
{
AgentId = "agt_123",
Environment = new EnvironmentParamOpenaiHosted(),
Input =
[
new InputMessageParam(
[new InputContentParamInputText("Review my spending for the previous month. Flag unused subscriptions, price increases, and other potential savings for me to review.")]
),
],
},
}
);
Console.WriteLine(automation.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 require "openai"
client = OpenAI::Client.new
automation = client.beta.agents.automations.create(
body: {
type: "periodic",
name: "Monthly spending review",
expression: "0 9 1 * *",
timezone: "America/New_York",
target: {
type: "new_session",
agent_id: "agt_123",
environment: { type: "openai_hosted" },
input: [
{
role: "user",
content: [
{
type: "input_text",
text: "Review my spending for the previous month. Flag unused subscriptions, price increases, and other potential savings for me to review."
}
]
}
]
}
}
)
puts automation 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 curl https://api.openai.com/v1/agents/automations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "periodic",
"name": "Monthly spending review",
"expression": "0 9 1 * *",
"timezone": "America/New_York",
"target": {
"type": "new_session",
"agent_id": "agt_123",
"environment": {
"type": "openai_hosted"
},
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Review my spending for the previous month. Flag unused subscriptions, price increases, and other potential savings for me to review."
}
]
}
]
}
}'
5 つのフィールドからなる cron 式とタイムゾーン名を指定します。
式
実行スケジュール
0 10 * * *
毎日午前 10 時
0 */2 * * *
2 時間ごと
0 9 1 * *
毎月 1 日の午前 9 時
0 9 * * MON-FRI
月曜日から金曜日までの午前 9 時
cron 式の時刻は、指定したタイムゾーンに基づいて解釈されます。UTC 基準のスケジュールには UTC を、現地時刻を使うスケジュールには America/New_York などの IANA タイムゾーンを指定します。定期オートメーションには run_at を指定しないでください。
cron スケジュールは、選択したタイムゾーンの時刻に従います。たとえば、0 */3 * * * の実行時刻は午前 0 時、午前 3 時、午前 6 時、以降 3 時間ごとです。作成時刻から 3 時間ごとに実行する指定ではありません。
スケジュールが示すのは実行予定時刻です。Agents API は負荷を分散するため、定期実行のたびにランダムな短い遅延を加えます。対象のセッションが処理中の場合、タスクの待機時間がさらに長くなることがあります。
エージェントが過去の調査結果、メッセージ、保存済みの作業内容を必要とする場合は、既存のセッションを使います。たとえば、夕食を計画するセッションには、レストランの希望条件と過去の空席確認の結果を保持できます。
次の例では、そのセッションで 2 時間ごとにレストランの空席を確認します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import OpenAI from "openai";
const client = new OpenAI();
const automation = await client.beta.agents.automations.create({
type: "periodic",
name: "Check restaurant reservations",
expression: "0 */2 * * *",
timezone: "America/New_York",
target: {
type: "existing_session",
session_id: "sess_123",
instructions:
"Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables.",
},
});
console.log(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from openai import OpenAI
client = OpenAI()
automation = client.beta.agents.automations.create(
type = "periodic" ,
name = "Check restaurant reservations" ,
expression = "0 */2 * * *" ,
timezone = "America/New_York" ,
target = {
"type" : "existing_session" ,
"session_id" : "sess_123" ,
"instructions" : (
"Check restaurant availability for our dinner plans. "
"Compare with earlier checks and report newly available tables."
),
},
)
print (automation.to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
automation, err := client.Beta.Agents.Automations.New(ctx,
openai.BetaAgentAutomationNewParams{
CreateAutomationParams: openai.AutomationScheduleParamUnion{
OfParamPeriodic: &openai.AutomationScheduleParamPeriodic{
Name: "Check restaurant reservations",
Expression: "0 */2 * * *",
Timezone: "America/New_York",
Target: openai.AutomationTargetParamUnion{
OfParamExistingSession: &openai.AutomationTargetParamExistingSession{
SessionID: "sess_123",
Instructions: "Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables.",
},
},
},
},
})
if err != nil {
panic(err)
}
fmt.Println(automation.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.automations.AutomationCreateParams;
import com.openai.models.beta.agents.automations.AutomationScheduleParam;
import com.openai.models.beta.agents.automations.AutomationTargetParam;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var automation =
client
.beta()
.agents()
.automations()
.create(
AutomationCreateParams.builder()
.automationScheduleParam(
AutomationScheduleParam.Periodic.builder()
.name("Check restaurant reservations")
.expression("0 */2 * * *")
.timezone("America/New_York")
.target(
AutomationTargetParam.ExistingSession.builder()
.sessionId("sess_123")
.instructions(
"Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables.")
.build())
.build())
.build());
System.out.println(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentAutomation automation = await client.CreateAutomationAsync(
new AgentAutomationCreationOptions
{
Type = AgentAutomationType.Periodic,
Name = "Check restaurant reservations",
Expression = "0 */2 * * *",
Timezone = "America/New_York",
Target = new ExistingSessionAutomationTarget
{
SessionId = "sess_123",
Instructions = "Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables.",
},
}
);
Console.WriteLine(automation.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 require "openai"
client = OpenAI::Client.new
automation = client.beta.agents.automations.create(
body: {
type: "periodic",
name: "Check restaurant reservations",
expression: "0 */2 * * *",
timezone: "America/New_York",
target: {
type: "existing_session",
session_id: "sess_123",
instructions: "Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables."
}
}
)
puts automation 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 curl https://api.openai.com/v1/agents/automations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "periodic",
"name": "Check restaurant reservations",
"expression": "0 */2 * * *",
"timezone": "America/New_York",
"target": {
"type": "existing_session",
"session_id": "sess_123",
"instructions": "Check restaurant availability for our dinner plans. Compare with earlier checks and report newly available tables."
}
}'
呼び出しのたびに、保存済みの指示がオートメーションからの通知として同じセッションに届きます。その際、セッションの現在のエージェント設定と保存済みの状態が使われます。この通知は、新しいユーザーメッセージとは別に扱われます。
セッションが処理中の場合は、次のタスクを受け付けられるようになるまで配信が保留されます。スケジュール実行によって進行中のターンが中断されることはありません。また、まだ届いていないツールの結果や承認が補われることもありません。アプリケーション側で引き続き必要なアクションを処理する 必要があります。
フォローアップを 1 回だけ実行するには、type: "once" と run_at を指定します。実行時刻には、将来の時刻を表す整数の Unix タイムスタンプを秒単位 で指定してください。expression と timezone は指定しないでください。
次の例では、2027 年 1 月 1 日午前 9 時(UTC) に確認を実行するようスケジュールします。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import OpenAI from "openai";
const client = new OpenAI();
const automation = await client.beta.agents.automations.create({
type: "once",
name: "Check restaurant reply",
run_at: 1798794000,
target: {
type: "existing_session",
session_id: "sess_123",
instructions:
"Check whether the restaurant replied about our booking. Summarize any changes to the dinner plans.",
},
});
console.log(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from openai import OpenAI
client = OpenAI()
automation = client.beta.agents.automations.create(
type = "once" ,
name = "Check restaurant reply" ,
run_at = 1798794000 ,
target = {
"type" : "existing_session" ,
"session_id" : "sess_123" ,
"instructions" : (
"Check whether the restaurant replied about our booking. "
"Summarize any changes to the dinner plans."
),
},
)
print (automation.to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
automation, err := client.Beta.Agents.Automations.New(ctx,
openai.BetaAgentAutomationNewParams{
CreateAutomationParams: openai.AutomationScheduleParamUnion{
OfParamOnce: &openai.AutomationScheduleParamOnce{
Name: "Check restaurant reply",
RunAt: 1798794000,
Target: openai.AutomationTargetParamUnion{
OfParamExistingSession: &openai.AutomationTargetParamExistingSession{
SessionID: "sess_123",
Instructions: "Check whether the restaurant replied about our booking. Summarize any changes to the dinner plans.",
},
},
},
},
})
if err != nil {
panic(err)
}
fmt.Println(automation.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.automations.AutomationCreateParams;
import com.openai.models.beta.agents.automations.AutomationScheduleParam;
import com.openai.models.beta.agents.automations.AutomationTargetParam;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var automation =
client
.beta()
.agents()
.automations()
.create(
AutomationCreateParams.builder()
.automationScheduleParam(
AutomationScheduleParam.Once.builder()
.name("Check restaurant reply")
.runAt(1798794000L)
.target(
AutomationTargetParam.ExistingSession.builder()
.sessionId("sess_123")
.instructions(
"Check whether the restaurant replied about our booking. Summarize any changes to the dinner plans.")
.build())
.build())
.build());
System.out.println(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentAutomation automation = await client.CreateAutomationAsync(
new AgentAutomationCreationOptions
{
Type = AgentAutomationType.Once,
Name = "Check restaurant reply",
RunAt = 1798794000,
Target = new ExistingSessionAutomationTarget
{
SessionId = "sess_123",
Instructions = "Check whether the restaurant replied about our booking. Summarize any changes to the dinner plans.",
},
}
);
Console.WriteLine(automation.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 require "openai"
client = OpenAI::Client.new
automation = client.beta.agents.automations.create(
body: {
type: "once",
name: "Check restaurant reply",
run_at: 1798794000,
target: {
type: "existing_session",
session_id: "sess_123",
instructions: "Check whether the restaurant replied about our booking. Summarize any changes to the dinner plans."
}
}
)
puts automation 1
2
3
4
5
6
7
8
9
10
11
12
13
14 curl https://api.openai.com/v1/agents/automations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "once",
"name": "Check restaurant reply",
"run_at": 1798794000,
"target": {
"type": "existing_session",
"session_id": "sess_123",
"instructions": "Check whether the restaurant replied about our booking. Summarize any changes to the dinner plans."
}
}'
1 回限りのスケジュールが完了すると、以降の実行予定はありません。完了後も手動で呼び出せます。次のフォローアップをスケジュールするには、別のオートメーションを作成します。
エージェントのツールに automations を追加すると、ユーザーから依頼された作業をエージェント自身がスケジュールできます。この例ではサブエージェントも有効にします。メインエージェントは、スケジュール済みタスクを個別に委任し、結果の要約を保持できます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import OpenAI from "openai";
const client = new OpenAI();
const session = await client.beta.agents.sessions.create({
agent: {
model: "gpt-6-astra",
instructions:
"Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.",
tools: [{ type: "automations" }],
multi_agent: { enabled: true },
},
environment: { type: "openai_hosted" },
input:
"Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take.",
});
console.log(session.id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 from openai import OpenAI
client = OpenAI()
session = client.beta.agents.sessions.create(
agent = {
"model" : "gpt-6-astra" ,
"instructions" : (
"Use automations to schedule tasks requested by the user. "
"Delegate each scheduled task to a subagent and ask for a concise result. "
"Keep the goal, schedule, and useful summaries in the main session. "
"Adjust or stop schedules when the user asks."
),
"multi_agent" : { "enabled" : True },
"tools" : [{ "type" : "automations" }],
},
environment = { "type" : "openai_hosted" },
input = (
"Every day at 10 AM in America/New_York, review the goals we discuss here "
"and suggest the next actions I could take."
),
)
print (session.id) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
session, err := client.Beta.Agents.Sessions.New(ctx,
openai.BetaAgentSessionNewParams{
Agent: openai.BetaAgentSessionNewParamsAgent{
Model: openai.String("gpt-6-astra"),
Instructions: openai.String("Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks."),
MultiAgent: openai.MultiAgentConfigParam{
Enabled: true,
},
Tools: []openai.AgentToolParamUnion{
{OfParamAutomations: &openai.AgentToolParamAutomations{}},
},
},
Environment: openai.EnvironmentParamUnion{
OfParamOpenAIHosted: &openai.EnvironmentParamOpenAIHosted{},
},
Input: openai.BetaAgentSessionNewParamsInputUnion{
OfString: openai.String("Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take."),
},
})
if err != nil {
panic(err)
}
fmt.Println(session.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.EnvironmentParam;
import com.openai.models.beta.agents.MultiAgentConfigParam;
import com.openai.models.beta.agents.sessions.SessionCreateParams;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var session =
client
.beta()
.agents()
.sessions()
.create(
SessionCreateParams.builder()
.agent(
SessionCreateParams.Agent.builder()
.model("gpt-6-astra")
.instructions(
"Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.")
.multiAgent(MultiAgentConfigParam.builder().enabled(true).build())
.addToolAutomations()
.build())
.environment(EnvironmentParam.OpenAIHosted.builder().build())
.input(
"Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take.")
.build());
System.out.println(session.id()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentSession session = await client.CreateAgentSessionAsync(
new AgentSessionCreationOptions
{
Agent = new SessionAgentConfigParam
{
Model = "gpt-6-astra",
Instructions = "Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.",
MultiAgent = new MultiAgentConfigParam { Enabled = true },
Tools = [new AgentToolConfigParamAutomations()],
},
Environment = new EnvironmentParamOpenaiHosted(),
Input =
[
new InputMessageParam(
[new InputContentParamInputText("Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take.")]
),
],
}
);
Console.WriteLine(session.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14 require "openai"
client = OpenAI::Client.new
session = client.beta.agents.sessions.create(
agent: {
model: "gpt-6-astra",
instructions: "Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.",
multi_agent: { enabled: true },
tools: [{ type: "automations" }]
},
environment: { type: "openai_hosted" },
input: "Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take."
)
puts session.id 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 curl https://api.openai.com/v1/agents/sessions \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent": {
"model": "gpt-6-astra",
"instructions": "Use automations to schedule tasks requested by the user. Delegate each scheduled task to a subagent and ask for a concise result. Keep the goal, schedule, and useful summaries in the main session. Adjust or stop schedules when the user asks.",
"tools": [{ "type": "automations" }],
"multi_agent": { "enabled": true }
},
"environment": {
"type": "openai_hosted"
},
"input": "Every day at 10 AM in America/New_York, review the goals we discuss here and suggest the next actions I could take."
}'
これにより、エージェントは自身のオートメーションを作成、一覧表示、取得、更新、一時停止、再開、削除できます。Agents API は現在のセッションを対象に設定します。エージェントは単発実行と定期実行をスケジュールできますが、これらのツールを使って新しいセッションを開始したり、別のセッションのオートメーションを管理したりすることはできません。
これらのツールでアクセスできるのは、エージェントが現在のセッションで作成したオートメーションだけです。アプリケーションは API を通じて、これらのオートメーションをアプリケーション自身が作成したものと併せて管理できます。Agents API が作成者を created_by に記録するため、作成リクエストにこのフィールドを含めないでください。
このツールはデフォルトでは追加されません。アプリケーションはツールを有効にしなくても作業をスケジュールできます。エージェントの設定からツールを削除しても、保存済みのスケジュールは削除されません。必要に応じて API から一時停止または削除してください。
継続的に取り組む目標には、マルチエージェントオーケストレーション を agent.multi_agent.enabled: true で有効にします。メインエージェントには、目標とスケジュールを保持し、個々のタスクをサブエージェントに委任して、結果の要約を残すよう指示します。こうすると、確認のたびに生成される詳細なツール出力が、メインセッションのコンテキストウィンドウに蓄積されません。
たとえば、メインエージェントの指示に次の内容を含めます。
スケジュール済みタスクを 1 件ずつサブエージェントに委任してください。目標と関連する過去の調査結果を伝え、結果を簡潔に報告するよう求めてください。報告を確認し、役に立つ内容を要約して残したうえで、スケジュールを継続するか、変更するか、停止するかを判断してください。
automations ツールはスケジュールを管理します。スケジュール済みの作業に必要な他のツールやデータにも、エージェントが引き続きアクセスできるようにしてください。
アプリケーション内のイベントに応じてスケジュールを作成することもできます。たとえば、ユーザー登録時にオンボーディング用のセッションを開始し、48 時間後に初回のフォローアップを実行するようスケジュールします。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import OpenAI from "openai";
const client = new OpenAI();
const automation = await client.beta.agents.automations.create({
type: "once",
name: "Onboarding follow-up",
run_at: Math.floor(Date.now() / 1000) + 48 * 60 * 60,
target: {
type: "existing_session",
session_id: "sess_123",
instructions:
"Review onboarding progress and send the next onboarding message if the user has not completed onboarding.",
},
});
console.log(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import time
from openai import OpenAI
client = OpenAI()
automation = client.beta.agents.automations.create(
type = "once" ,
name = "Onboarding follow-up" ,
run_at = int (time.time()) + 48 * 60 * 60 ,
target = {
"type" : "existing_session" ,
"session_id" : "sess_123" ,
"instructions" : (
"Review onboarding progress and send the next onboarding message "
"if the user has not completed onboarding."
),
},
)
print (automation.to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 import (
"context"
"fmt"
"time"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
automation, err := client.Beta.Agents.Automations.New(ctx,
openai.BetaAgentAutomationNewParams{
CreateAutomationParams: openai.AutomationScheduleParamUnion{
OfParamOnce: &openai.AutomationScheduleParamOnce{
Name: "Onboarding follow-up",
RunAt: time.Now().Add(48 * time.Hour).Unix(),
Target: openai.AutomationTargetParamUnion{
OfParamExistingSession: &openai.AutomationTargetParamExistingSession{
SessionID: "sess_123",
Instructions: "Review onboarding progress and send the next onboarding message if the user has not completed onboarding.",
},
},
},
},
})
if err != nil {
panic(err)
}
fmt.Println(automation.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.automations.AutomationCreateParams;
import com.openai.models.beta.agents.automations.AutomationScheduleParam;
import com.openai.models.beta.agents.automations.AutomationTargetParam;
import java.time.Duration;
import java.time.Instant;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var automation =
client
.beta()
.agents()
.automations()
.create(
AutomationCreateParams.builder()
.automationScheduleParam(
AutomationScheduleParam.Once.builder()
.name("Onboarding follow-up")
.runAt(Instant.now().plus(Duration.ofHours(48)).getEpochSecond())
.target(
AutomationTargetParam.ExistingSession.builder()
.sessionId("sess_123")
.instructions(
"Review onboarding progress and send the next onboarding message if the user has not completed onboarding.")
.build())
.build())
.build());
System.out.println(automation); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentAutomation automation = await client.CreateAutomationAsync(
new AgentAutomationCreationOptions
{
Type = AgentAutomationType.Once,
Name = "Onboarding follow-up",
RunAt = DateTimeOffset.UtcNow.AddHours(48).ToUnixTimeSeconds(),
Target = new ExistingSessionAutomationTarget
{
SessionId = "sess_123",
Instructions = "Review onboarding progress and send the next onboarding message if the user has not completed onboarding.",
},
}
);
Console.WriteLine(automation.Id); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 require "openai"
client = OpenAI::Client.new
automation = client.beta.agents.automations.create(
body: {
type: "once",
name: "Onboarding follow-up",
run_at: Time.now.to_i + 48 * 60 * 60,
target: {
type: "existing_session",
session_id: "sess_123",
instructions: "Review onboarding progress and send the next onboarding message if the user has not completed onboarding."
}
}
)
puts automation 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 RUN_AT=$(($(date +%s) + 48 * 60 * 60))
curl https://api.openai.com/v1/agents/automations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"type": "once",
"name": "Onboarding follow-up",
"run_at": $RUN_AT,
"target": {
"type": "existing_session",
"session_id": "sess_123",
"instructions": "Review onboarding progress and send the next onboarding message if the user has not completed onboarding."
}
}
EOF
フォローアップが完了するたびに、アプリケーションはその 48 時間後に次のフォローアップをスケジュールできます。オンボーディングが完了するか、ユーザーが以降のフォローアップを辞退したら、フォローアップを停止し、保留中のものを削除します。この間隔で実行するには、1 回限りのスケジュールを使ってください。cron 式で月内の日付を指定しても、月をまたいで 48 時間ごとに繰り返す間隔は表せません。
オンボーディングを担当するエージェントには、オンボーディングの進捗情報とアプリケーションのメッセージ送信ツールへのアクセスが必要です。オートメーションを作成すると作業がスケジュールされます。メッセージがすぐに送信されるわけではありません。
保存済みのオートメーションをすぐにテストするには、リクエストボディを指定せずに POST /v1/agents/automations/auto_123/invocations を送信します。手動で呼び出しても、保存済みのスケジュールは変わらず、1 回限りの実行予定も消費されません。スケジュールの一時停止中も手動で呼び出せます。
レスポンスで返された呼び出し ID を保存してください。GET /v1/agents/automations/auto_123/invocations/ainv_123 でその呼び出しを取得できます。配信履歴を一覧表示するには GET /v1/agents/automations/auto_123/invocations を使います。
過去の実行状況をまとめて確認するには、オートメーションの呼び出しを一覧表示します。
1
2
3
4
5
6
7
8 import OpenAI from "openai" ;
const client = new OpenAI ();
for await ( const invocation of client.beta.agents.automations.invocations. list (
"auto_123"
)) {
console. log (invocation.id, invocation.status, invocation.session_id);
} 1
2
3
4
5
6 from openai import OpenAI
client = OpenAI()
invocations = client.beta.agents.automations.invocations.list(automation_id="auto_123")
for invocation in invocations:
print(invocation.id, invocation.status, invocation.session_id) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
invocations := client.Beta.Agents.Automations.Invocations.ListAutoPaging(ctx, "auto_123",
openai.BetaAgentAutomationInvocationListParams{})
for invocations.Next() {
invocation := invocations.Current()
fmt.Println(invocation.ID, invocation.Status, invocation.SessionID)
}
if err := invocations.Err(); err != nil {
panic(err)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.automations.invocations.InvocationListParams;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var invocations =
client
.beta()
.agents()
.automations()
.invocations()
.list(InvocationListParams.builder().automationId("auto_123").build());
for (var invocation : invocations.autoPager()) {
System.out.println(
invocation.id() + " " + invocation.status() + " " + invocation.sessionId());
} 1
2
3
4
5
6
7
8
9
10 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
await foreach (AgentAutomationInvocation invocation in client.GetAutomationInvocationsAsync("auto_123"))
{
Console.WriteLine($"{invocation.Id} {invocation.Status} {invocation.SessionId}");
} 1
2
3
4
5
6
7 require "openai"
client = OpenAI::Client.new
invocations = client.beta.agents.automations.invocations.list("auto_123")
invocations.auto_paging_each do |invocation|
puts "#{invocation.id} #{invocation.status} #{invocation.session_id}"
end 1
2
3 curl https://api.openai.com/v1/agents/automations/auto_123/invocations \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY"
履歴に含まれるのは作成済みの呼び出しです。今後の実行予定がすべて含まれるわけではありません。次のフィールドを確認してください。
フィールド
確認する内容
status
初期値は queued で、配信に成功すると completed になります。
session_id
配信後に追跡するセッションの ID です。セッションが利用可能になるまでは null の場合があります。
source.type
手動で呼び出した場合は manual、スケジュールに従って実行した場合は automation です。
scheduled_at
実行予定時刻です。手動で呼び出した場合は null です。
配信が完了しても、エージェントの作業が完了したとは限りません。 新しいセッションの場合、配信完了はセッションが初期入力を受け付けたことを示します。既存のセッションの場合は、通知と作業開始リクエストを受け付けたことを示します。
呼び出しの session_id を使ってセッションイベントを追跡し 、ターンの結果を確認してください。
オートメーションが担うのは作業のスケジュール設定です。セッションの出力の表示とユーザーへの通知はアプリケーションが行います。
オートメーションを取得するには GET /v1/agents/automations/auto_123 を使います。プロジェクト内のオートメーションを一覧表示するには GET /v1/agents/automations を使います。既存の特定のセッションを対象とするオートメーションを検索するには、session_id=sess_123 を追加します。
次の例では、cron 式を更新して定期確認の時刻を午前 11 時に変更します。
1
2
3
4
5
6
7 import OpenAI from "openai";
const client = new OpenAI();
const automation = await client.beta.agents.automations.update("auto_123", {
expression: "0 11 * * *",
});
console.log(automation); 1
2
3
4
5
6
7
8 from openai import OpenAI
client = OpenAI()
automation = client.beta.agents.automations.update(
automation_id = "auto_123" ,
expression = "0 11 * * *" ,
)
print (automation.to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
ctx := context.Background()
client := openai.NewClient()
automation, err := client.Beta.Agents.Automations.Update(ctx, "auto_123",
openai.BetaAgentAutomationUpdateParams{
Expression: openai.String("0 11 * * *"),
})
if err != nil {
panic(err)
}
fmt.Println(automation.ID) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.automations.AutomationUpdateParams;
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var automation =
client
.beta()
.agents()
.automations()
.update(
AutomationUpdateParams.builder()
.automationId("auto_123")
.expression("0 11 * * *")
.build());
System.out.println(automation); 1
2
3
4
5
6
7
8
9
10
11 using OpenAI;
using OpenAI.Agents;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AgentClient client = new OpenAIClient(key).GetAgentClient();
AgentAutomation automation = await client.UpdateAutomationAsync(
"auto_123",
new AgentAutomationUpdateOptions { Expression = "0 11 * * *" }
);
Console.WriteLine(automation.Id); 1
2
3
4
5
6
7
8 require "openai"
client = OpenAI::Client.new
automation = client.beta.agents.automations.update(
"auto_123",
expression: "0 11 * * *"
)
puts automation 1
2
3
4
5
6
7 curl https://api.openai.com/v1/agents/automations/auto_123 \
-H "OpenAI-Beta: agents=v1" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"expression": "0 11 * * *"
}'
省略したフィールドは変更されません。target を指定すると対象の設定全体が置き換わるため、必須フィールドをすべて含め、対象の種類を維持してください。リマインダーのテキストは target.instructions で、初期メッセージは target.input で更新します。エージェントが作成したオートメーションでは、作成元のセッションを引き続き対象にする必要があります。
変更は次の実行予定時刻より前に行ってください。更新内容は今後の呼び出しに適用されます。すでにキューに入っている呼び出しには、作成時に保存された対象と入力が使われます。
次の操作ではリクエストボディを指定しません。
目的
操作
効果
スケジュール実行の一時停止
POST /v1/agents/automations/auto_123/pause
予定されている未配信のタスクを保留します。手動での呼び出しは引き続き可能です。
スケジュール実行の再開
POST /v1/agents/automations/auto_123/resume
保存済みのスケジュールを再び有効にします。
スケジュールの削除
DELETE /v1/agents/automations/auto_123
以降はスケジュール実行も手動での呼び出しもできなくなります。
オートメーションを一時停止または削除しても、セッションがすでに受け付けた作業は停止せず、セッションも削除されません。配信がすでに始まっているタスクは、そのままセッションに届くことがあります。進行中の作業を停止するには、実行中のターンをキャンセルしてください 。
1 回限りのオートメーションの一時停止中に実行予定時刻を過ぎた場合は、再開する前に run_at に将来の時刻を指定し直してください。完了済みの単発オートメーションは一時停止も再開もできません。次のフォローアップをスケジュールするには、別のオートメーションを作成してください。