OMA 控制台已预留 Dreaming 入口,但当前版本尚未提供完整的 Dreams API。本页记录兼容目标,不能作为当前可用性承诺。
“Dreaming”(梦境)是一项研究预览功能。申请访问权限以进行试用。
梦境端点受
dreaming-2026-04-21 Beta 请求头控制;仅使用 managed-agents-2026-04-01 标头本身无法获得梦境的访问权限。本页面上的梦境端点示例同时发送这两个标头;会话和记忆存储调用仅需要 managed-agents-2026-04-01。SDK 会自动设置这些标头。工作原理
梦境是一个异步作业,它接收:- 一个预先存在的记忆存储: 模型对其进行验证、去重和重新组织的存储,以及
- 1 到 100 个会话: 模型从中挖掘模式和洞察并整合到输出中的过往记录。
running 后不久出现在梦境的 outputs[] 中,即工作流克隆完输入存储之后;处于 running 状态的梦境可能会短暂报告空的 outputs[]。
创建梦境
dream=$(curl -s http://localhost:38080/v1/dreams \
-H "x-api-key: $OMA_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01,dreaming-2026-04-21" \
-H "content-type: application/json" \
--data @- <<EOF
{
"inputs": [
{ "type": "memory_store", "memory_store_id": "$store_id" },
{ "type": "sessions", "session_ids": ["$session_a", "$session_b"] }
],
"model": "claude-opus-4-8",
"instructions": "Focus on coding-style preferences; ignore one-off debugging notes."
}
EOF
)
dream_id=$(jq -r '.id' <<< "$dream")
echo "$dream_id" # drm_01...
dream_id=$(ant beta:dreams create --transform id --raw-output <<YAML
inputs:
- type: memory_store
memory_store_id: $store_id
- type: sessions
session_ids: [$session_a, $session_b]
model: claude-opus-4-8
instructions: Focus on coding-style preferences; ignore one-off debugging notes.
YAML
)
dream = client.beta.dreams.create(
inputs=[
{"type": "memory_store", "memory_store_id": store_id},
{"type": "sessions", "session_ids": [session_a, session_b]},
],
model="claude-opus-4-8",
instructions="Focus on coding-style preferences; ignore one-off debugging notes.",
)
print(dream.id) # drm_01...
let dream = await client.beta.dreams.create({
inputs: [
{ type: "memory_store", memory_store_id: storeId },
{ type: "sessions", session_ids: [sessionA, sessionB] },
],
model: "claude-opus-4-8",
instructions: "Focus on coding-style preferences; ignore one-off debugging notes.",
});
console.log(dream.id); // drm_01...
var dream = await client.Beta.Dreams.Create(new()
{
Inputs =
[
new BetaDreamMemoryStoreInput
{
Type = BetaDreamMemoryStoreInputType.MemoryStore,
MemoryStoreID = storeID,
},
new BetaDreamSessionsInput
{
Type = BetaDreamSessionsInputType.Sessions,
SessionIds = [sessionA, sessionB],
},
],
Model = "claude-opus-4-8",
Instructions = "Focus on coding-style preferences; ignore one-off debugging notes.",
});
Console.WriteLine(dream.ID); // drm_01...
dream, err := client.Beta.Dreams.New(ctx, anthropic.BetaDreamNewParams{
Inputs: []anthropic.BetaDreamInputUnionParam{
anthropic.BetaDreamInputParamOfMemoryStore(storeID),
anthropic.BetaDreamInputParamOfSessions([]string{sessionA, sessionB}),
},
Model: anthropic.BetaDreamModelParamsUnion{
OfString: anthropic.String("claude-opus-4-8"),
},
Instructions: anthropic.String("Focus on coding-style preferences; ignore one-off debugging notes."),
})
if err != nil {
panic(err)
}
fmt.Println(dream.ID) // drm_01...
var dream = client.beta().dreams().create(
DreamCreateParams.builder()
.addMemoryStoreInput(storeId)
.addSessionsInput(List.of(sessionA, sessionB))
.model("claude-opus-4-8")
.instructions("Focus on coding-style preferences; ignore one-off debugging notes.")
.build()
);
IO.println(dream.id()); // drm_01...
$dream = $client->beta->dreams->create(
inputs: [
['type' => 'memory_store', 'memory_store_id' => $storeId],
['type' => 'sessions', 'session_ids' => [$sessionA, $sessionB]],
],
model: 'claude-opus-4-8',
instructions: 'Focus on coding-style preferences; ignore one-off debugging notes.',
);
echo "{$dream->id}\n"; // drm_01...
dream = client.beta.dreams.create(
inputs: [
{type: "memory_store", memory_store_id: store_id},
{type: "sessions", session_ids: [session_a, session_b]}
],
model: "claude-opus-4-8",
instructions: "Focus on coding-style preferences; ignore one-off debugging notes."
)
puts dream.id # drm_01...
claude-opus-5、claude-fable-5、claude-opus-4-8、claude-opus-4-7、claude-sonnet-5 和 claude-sonnet-4-6。您可以选择传递 instructions 来引导梦境过程;请参阅使用指令进行引导。
响应是完整的 dream 资源,其 status: "pending":
{
"type": "dream",
"id": "drm_01AbCDefGhIjKlMnOpQrStUv",
"status": "pending",
"inputs": [
{ "type": "memory_store", "memory_store_id": "memstore_01Hx..." },
{ "type": "sessions", "session_ids": ["sesn_01...", "sesn_02..."] }
],
"outputs": [],
"model": { "id": "claude-opus-4-8" },
"instructions": "Focus on coding-style preferences; ignore one-off debugging notes.",
"session_id": null,
"created_at": "2026-04-29T17:04:10Z",
"ended_at": null,
"archived_at": null,
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"cache_read_input_tokens": 0,
"cache_creation_input_tokens": 0
},
"error": null
}
如果您只有会话记录而没有现有存储,请先创建一个空的记忆存储,然后将其作为
memory_store 输入传递。使用指令进行引导
可选的instructions 字段用于引导梦境流水线的综合方向。它会应用于整个流水线:仔细阅读哪些内容、合并或删除哪些内容,以及如何组织输出存储的结构。
使用 instructions 提供高层次的综合指导,例如关注领域(“专注于编码风格偏好”)、需要保持不变的内容,或您希望在整个存储中应用的输出规范。该流水线是对输入的综合处理,而不是应用于存储文本的编辑器,因此针对特定行的命令式指令(“将句子 X 改为 Y”、“修正 Z 部分中的计数”)通常不会产生任何更改。要对单个记忆进行针对性编辑,请直接在输出存储上使用 记忆存储 API。
跟踪进度
梦境异步运行,通常需要几分钟到几小时,具体取决于输入记录的数量。通过 ID 轮询梦境以检查状态:while true; do
dream=$(curl -s "http://localhost:38080/v1/dreams/$dream_id" \
-H "x-api-key: $OMA_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01,dreaming-2026-04-21")
status=$(jq -r '.status' <<< "$dream")
echo "status=$status input_tokens=$(jq -r '.usage.input_tokens' <<< "$dream")"
[[ "$status" == "pending" || "$status" == "running" ]] || break
sleep 10
done
ant beta:dreams retrieve --dream-id "$dream_id"
while dream.status in ("pending", "running"):
time.sleep(10)
dream = client.beta.dreams.retrieve(dream.id)
print(f"status={dream.status} input_tokens={dream.usage.input_tokens}")
while (dream.status === "pending" || dream.status === "running") {
await sleep(10_000);
dream = await client.beta.dreams.retrieve(dream.id);
console.log(`status=${dream.status} input_tokens=${dream.usage.input_tokens}`);
}
while (dream.Status.Value() is BetaDreamStatus.Pending or BetaDreamStatus.Running)
{
await Task.Delay(TimeSpan.FromSeconds(10));
dream = await client.Beta.Dreams.Retrieve(dream.ID);
Console.WriteLine($"status={dream.Status.Raw()} input_tokens={dream.Usage.InputTokens}");
}
for dream.Status == anthropic.BetaDreamStatusPending || dream.Status == anthropic.BetaDreamStatusRunning {
time.Sleep(10 * time.Second)
dream, err = client.Beta.Dreams.Get(ctx, dream.ID, anthropic.BetaDreamGetParams{})
if err != nil {
panic(err)
}
fmt.Printf("status=%s input_tokens=%d\n", dream.Status, dream.Usage.InputTokens)
}
while (dream.status().equals(BetaDreamStatus.PENDING)
|| dream.status().equals(BetaDreamStatus.RUNNING)) {
Thread.sleep(10_000);
dream = client.beta().dreams().retrieve(dream.id());
IO.println("status=" + dream.status() + " input_tokens=" + dream.usage().inputTokens());
}
while (in_array($dream->status, [BetaDreamStatus::PENDING->value, BetaDreamStatus::RUNNING->value], true)) {
sleep(10);
$dream = $client->beta->dreams->retrieve($dream->id);
echo "status={$dream->status} input_tokens={$dream->usage->inputTokens}\n";
}
while %i[pending running].include?(dream.status)
sleep 10
dream = client.beta.dreams.retrieve(dream.id)
puts "status=#{dream.status} input_tokens=#{dream.usage.input_tokens}"
end
生命周期
status | 含义 |
|---|---|
pending | 梦境已成功创建并排队。 |
running | 流水线正在处理中。usage 随工作进展而更新。 |
completed | 成功完成。outputs[] 值即为新的记忆存储。 |
failed | 梦境运行以错误结束。输出记忆存储保持原样,包含失败前已写入的所有内容。 |
canceled | 梦境运行已取消。输出记忆存储保持原样。 |
观察流水线运行
一旦梦境处于running 状态,其 session_id 字段会指向运行该流水线的底层会话。您可以流式传输该会话的事件,以实时观察梦境正在读取和写入的内容。当梦境达到终止状态时,该会话会被归档(而非删除),因此记录在之后仍然可用。
使用输出
当status 达到 completed 时,outputs[] 中的 memory_store 条目引用一个已完全填充的存储。它是您工作区中的一个普通记忆存储。使用 记忆存储 API 或在控制台中审查它,然后选择以下操作之一:
# dream 结束后,memory_store 输出保存重建后的存储
output_store_id=$(jq -r 'first(.outputs[] | select(.type == "memory_store")).memory_store_id' <<< "$dream")
curl -s http://localhost:38080/v1/sessions \
-H "x-api-key: $OMA_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "content-type: application/json" \
--data @- <<EOF
{
"agent": "$agent_id",
"environment_id": "$environment_id",
"resources": [
{ "type": "memory_store", "memory_store_id": "$output_store_id" }
]
}
EOF
output_store_id=$(ant beta:dreams retrieve --dream-id "$dream_id" --format json |
jq -r 'first(.outputs[] | select(.type == "memory_store")).memory_store_id')
ant beta:sessions create <<YAML
agent: $agent_id
environment_id: $environment_id
resources:
- type: memory_store
memory_store_id: $output_store_id
YAML
# 梦境结束后,输出中保存着重建的记忆存储
output_store_id = next(
output.memory_store_id for output in dream.outputs if output.type == "memory_store"
)
session = client.beta.sessions.create(
agent=agent_id,
environment_id=environment_id,
resources=[
{"type": "memory_store", "memory_store_id": output_store_id},
],
)
// dream 结束后,输出中保存着重建的记忆存储
const output = dream.outputs.find((entry) => entry.type === "memory_store");
const outputStoreId = output!.memory_store_id;
await client.beta.sessions.create({
agent: agentId,
environment_id: environmentId,
resources: [
{ type: "memory_store", memory_store_id: outputStoreId },
],
});
var output = dream.Outputs.FirstOrDefault(entry => entry.Type == "memory_store");
if (output is { MemoryStoreID: var outputStoreID })
{
await client.Beta.Sessions.Create(new()
{
Agent = agentID,
EnvironmentID = environmentID,
Resources =
[
new BetaManagedAgentsMemoryStoreResourceParam
{
Type = BetaManagedAgentsMemoryStoreResourceParamType.MemoryStore,
MemoryStoreID = outputStoreID,
},
],
});
}
for _, output := range dream.Outputs {
if output.Type != "memory_store" {
continue
}
outputStoreID := output.MemoryStoreID
session, err := client.Beta.Sessions.New(ctx, anthropic.BetaSessionNewParams{
Agent: anthropic.BetaSessionNewParamsAgentUnion{
OfString: anthropic.String(agentID),
},
EnvironmentID: environmentID,
Resources: []anthropic.BetaSessionNewParamsResourceUnion{{
OfMemoryStore: &anthropic.BetaManagedAgentsMemoryStoreResourceParam{
MemoryStoreID: outputStoreID,
},
}},
})
if err != nil {
panic(err)
}
fmt.Println(session.ID)
break
}
var output = dream.outputs().stream()
.filter(entry -> entry.type().equals(BetaDreamOutput.Type.MEMORY_STORE))
.findFirst();
if (output.isPresent()) {
var outputStoreId = output.get().memoryStoreId();
var session = client.beta().sessions().create(
SessionCreateParams.builder()
.agent(agentId)
.environmentId(environmentId)
.addMemoryStoreResource(outputStoreId)
.build()
);
}
$matches = array_filter($dream->outputs, fn($output) => $output->type === 'memory_store');
$output = $matches ? reset($matches) : null;
if ($output !== null) {
$session = $client->beta->sessions->create(
agent: $agentId,
environmentID: $environmentId,
resources: [
['type' => 'memory_store', 'memory_store_id' => $output->memoryStoreID],
],
);
}
output = dream.outputs.find { it.type == :memory_store }
if output
client.beta.sessions.create(
agent: agent_id,
environment_id: environment_id,
resources: [
{type: "memory_store", memory_store_id: output.memory_store_id}
]
)
end
failed 或 canceled 状态下,输出存储会保留部分内容,以便您检查停止前生成的内容;如果不需要,可通过记忆存储 API 清理它。
当梦境处于
pending 或 running 状态时,400 保护机制适用于归档梦境本身,而非其存储。在运行过程中归档或删除输入记忆存储(或删除输入会话)将导致梦境失败,并返回 input_memory_store_unavailable 或 input_session_unavailable。取消梦境
取消操作会立即将pending 或 running 状态的梦境转为 canceled。取消已处于 canceled 状态的梦境是幂等的空操作;取消 completed 或 failed 状态的梦境会返回 400。
取消后,梦境的
usage 字段可能会在进行中的工作逐步结束时继续更新几秒钟。如果您需要最终计数,请轮询梦境直到 usage 稳定。curl -s -X POST "http://localhost:38080/v1/dreams/$dream_id/cancel" \
-H "x-api-key: $OMA_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01,dreaming-2026-04-21"
ant beta:dreams cancel --dream-id "$dream_id"
client.beta.dreams.cancel(dream.id)
await client.beta.dreams.cancel(dream.id);
await client.Beta.Dreams.Cancel(dream.ID);
dream, err = client.Beta.Dreams.Cancel(ctx, dream.ID, anthropic.BetaDreamCancelParams{})
if err != nil {
panic(err)
}
client.beta().dreams().cancel(dream.id());
$client->beta->dreams->cancel($dream->id);
client.beta.dreams.cancel(dream.id)
归档梦境
归档操作会在已达到终止状态(completed、failed 或 canceled)的梦境上设置 archived_at;status 保持不变。已归档的梦境会从默认列表响应中排除,但仍可通过 ID 读取。归档已归档的梦境是幂等的空操作。归档 pending 或 running 状态的梦境会返回 400;请先取消它。没有取消归档操作。
curl -s -X POST "http://localhost:38080/v1/dreams/$dream_id/archive" \
-H "x-api-key: $OMA_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01,dreaming-2026-04-21"
ant beta:dreams archive --dream-id "$dream_id"
client.beta.dreams.archive(dream.id)
await client.beta.dreams.archive(dream.id);
await client.Beta.Dreams.Archive(dream.ID);
dream, err = client.Beta.Dreams.Archive(ctx, dream.ID, anthropic.BetaDreamArchiveParams{})
if err != nil {
panic(err)
}
client.beta().dreams().archive(dream.id());
$client->beta->dreams->archive($dream->id);
client.beta.dreams.archive(dream.id)
列出梦境
返回工作区中所有未归档的梦境,按最新优先排序。使用limit(默认 20,最大 100)和 page 游标进行分页。传递 include_archived=true 以包含已归档的梦境。
curl -s "http://localhost:38080/v1/dreams?limit=20" \
-H "x-api-key: $OMA_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01,dreaming-2026-04-21"
ant beta:dreams list --limit 20
for listed_dream in client.beta.dreams.list(limit=20):
print(listed_dream.id, listed_dream.status)
for await (const listedDream of client.beta.dreams.list({ limit: 20 })) {
console.log(listedDream.id, listedDream.status);
}
var page = await client.Beta.Dreams.List(new() { Limit = 20 });
await foreach (var listed in page.Paginate())
{
Console.WriteLine($"{listed.ID} {listed.Status.Raw()}");
}
dreams := client.Beta.Dreams.ListAutoPaging(ctx, anthropic.BetaDreamListParams{
Limit: anthropic.Int(20),
})
for dreams.Next() {
listed := dreams.Current()
fmt.Println(listed.ID, listed.Status)
}
if err := dreams.Err(); err != nil {
panic(err)
}
for (var listedDream : client.beta().dreams().list(
DreamListParams.builder().limit(20).build()
).autoPager()) {
IO.println(listedDream.id() + " " + listedDream.status());
}
foreach ($client->beta->dreams->list(limit: 20)->pagingEachItem() as $dream) {
echo "{$dream->id} {$dream->status}\n";
}
client.beta.dreams.list(limit: 20).auto_paging_each do
puts "#{it.id} #{it.status}"
end
错误
以下是可能出现的梦境错误的非详尽列表。error.type | 发生时机 |
|---|---|
timeout | 流水线超出其运行时间预算。 |
internal_error | 未分类的流水线故障。 |
memory_store_org_limit_exceeded | 流水线在配置工作存储时,您的组织达到了记忆存储上限。 |
input_memory_store_too_large | 输入记忆存储超出流水线的大小限制。 |
input_memory_store_unavailable | 输入记忆存储在梦境创建后被归档或删除。 |
input_session_unavailable | 输入会话在梦境创建后被删除。 |
计费
梦境按您所选模型的标准 API 令牌费率计费;资源上的usage 报告确切的总数。成本大致与输入会话的数量和长度呈线性关系。建议先从少量会话开始,在对整理质量满意后再扩大规模。
限制
| 限制 | 值 |
|---|---|
| 每个梦境的会话数 | 100 |
instructions 长度 | 4,096 个字符 |
| 支持的模型 | claude-opus-5、claude-fable-5、claude-opus-4-8、claude-opus-4-7、claude-sonnet-5、claude-sonnet-4-6 |