| 1 |
from typing import List, Optional |
| 2 |
from datetime import datetime |
| 3 |
from typing_extensions import Literal |
| 4 |
|
| 5 |
from ..._models import BaseModel |
| 6 |
from .beta_dream_error import BetaDreamError |
| 7 |
from .beta_dream_input import BetaDreamInput |
| 8 |
from .beta_dream_usage import BetaDreamUsage |
| 9 |
from .beta_dream_output import BetaDreamOutput |
| 10 |
from .beta_dream_status import BetaDreamStatus |
| 11 |
from .beta_output_behavior import BetaOutputBehavior |
| 12 |
from .beta_dream_model_config import BetaDreamModelConfig |
| 13 |
|
| 14 |
__all__ = ["BetaDream"] |
| 15 |
|
| 16 |
|
| 17 |
class BetaDream(BaseModel): |
| 18 |
""" |
| 19 |
An asynchronous job that reads a memory store and past sessions, then writes a reorganized version of that memory store. |
| 20 |
|
| 21 |
By default the dream writes its result to a new memory store and doesn't change the input memory store. With `output_behavior` set to `update_existing`, it writes its result into the input memory store instead. The Dreams API is in research preview, so this resource can still change. |
| 22 |
|
| 23 |
See the [Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#how-it-works) for what a dream reads and produces. |
| 24 |
""" |
| 25 |
|
| 26 |
id: str |
| 27 |
"""The unique ID of the dream (`drm_...`).""" |
| 28 |
|
| 29 |
archived_at: Optional[datetime] = None |
| 30 |
"""A timestamp in RFC 3339 format""" |
| 31 |
|
| 32 |
created_at: datetime |
| 33 |
"""A timestamp in RFC 3339 format""" |
| 34 |
|
| 35 |
ended_at: Optional[datetime] = None |
| 36 |
"""A timestamp in RFC 3339 format""" |
| 37 |
|
| 38 |
error: Optional[BetaDreamError] = None |
| 39 |
"""Failure detail for a Dream whose `status` is `failed`.""" |
| 40 |
|
| 41 |
inputs: List[BetaDreamInput] |
| 42 |
"""The sources that the dream reads, from the request that created it.""" |
| 43 |
|
| 44 |
instructions: Optional[str] = None |
| 45 |
"""The guidance given when the dream was created, or `null` if none was given.""" |
| 46 |
|
| 47 |
model: BetaDreamModelConfig |
| 48 |
"""The model that runs a dream, from the request that created it. |
| 49 |
|
| 50 |
The dream uses this model for all of its work. The response always gives the |
| 51 |
model as an object, even if the request gave only a model ID. |
| 52 |
""" |
| 53 |
|
| 54 |
output_behavior: BetaOutputBehavior |
| 55 |
"""Which memory store a dream writes its result to. |
| 56 |
|
| 57 |
Defaults to `create_new` when left out of a create request. |
| 58 |
""" |
| 59 |
|
| 60 |
outputs: List[BetaDreamOutput] |
| 61 |
""" |
| 62 |
The memory store that holds the dream's result, as a one-item array, or an empty |
| 63 |
array until the dream records that memory store. |
| 64 |
|
| 65 |
The array is empty while the dream is `pending` and for a short time after it |
| 66 |
starts `running`. It can stay empty if the dream fails or is canceled before |
| 67 |
then. The memory store holds the complete result only once `status` is |
| 68 |
`completed`. |
| 69 |
|
| 70 |
See the |
| 71 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#use-the-output) |
| 72 |
for how to review and use the result. |
| 73 |
""" |
| 74 |
|
| 75 |
session_id: Optional[str] = None |
| 76 |
""" |
| 77 |
The ID of the session that runs the dream (`sesn_...`), or `null` if that |
| 78 |
session hasn't started. |
| 79 |
|
| 80 |
Stream that session's events to follow what the dream reads and writes. |
| 81 |
|
| 82 |
See the |
| 83 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#watch-the-pipeline-run) |
| 84 |
for how to watch a running dream. |
| 85 |
""" |
| 86 |
|
| 87 |
status: BetaDreamStatus |
| 88 |
"""Where a dream is in its lifecycle. |
| 89 |
|
| 90 |
`completed`, `failed`, and `canceled` are final: once a dream has one of these |
| 91 |
statuses, its status doesn't change again. |
| 92 |
|
| 93 |
See the |
| 94 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#lifecycle) |
| 95 |
for what each status means. |
| 96 |
""" |
| 97 |
|
| 98 |
type: Literal["dream"] |
| 99 |
|
| 100 |
usage: BetaDreamUsage |
| 101 |
"""The tokens that a dream has used so far. |
| 102 |
|
| 103 |
The counts are zero while the dream is `pending` and update while it is |
| 104 |
`running`. They can keep changing after a cancel. |
| 105 |
|
| 106 |
See the |
| 107 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#billing) |
| 108 |
for how dreams are billed. See the |
| 109 |
[prompt caching guide](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#tracking-cache-performance) |
| 110 |
for how the input token counts add up. |
| 111 |
""" |