> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# weave

> weave の Python SDK リファレンス

export const SourceLink = ({url}) => <a href={url} target="_blank" rel="noopener noreferrer" className="source-link">
    Source
  </a>;

<h1 id="api-overview">
  API の概要
</h1>

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/agent/agent.py#L17" />

<h2 id="class-agent">
  <kbd>class</kbd> `Agent`
</h2>

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `model_name`: `<class 'str'>`
* `temperature`: `<class 'float'>`
* `system_message`: `<class 'str'>`
* `tools`: `list[typing.Any]`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L23" />

<h3 id="method-step">
  <kbd>method</kbd> `step`
</h3>

```python theme={"system"}
step(state: AgentState) → AgentState
```

エージェントのステップを 1 回実行します。

**引数:**

* <b>`state`</b>: 環境の現在の状態。
* <b>`action`</b>: 実行する action。
  **戻り値:**
  更新後の環境の状態。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/agent/agent.py#L12" />

<h2 id="class-agentstate">
  <kbd>class</kbd> `AgentState`
</h2>

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `history`: `list[typing.Any]`

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L11" />

<h2 id="class-annotationspec">
  <kbd>class</kbd> `AnnotationSpec`
</h2>

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `field_schema`: `dict[str, typing.Any]`
* `unique_among_creators`: `<class 'bool'>`
* `op_scope`: `list[str] | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L46" />

<h3 id="classmethod-preprocess_field_schema">
  <kbd>クラスメソッド</kbd> `preprocess_field_schema`
</h3>

```python theme={"system"}
preprocess_field_schema(data: Any) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L93" />

<h3 id="classmethod-validate_field_schema">
  <kbd>クラスメソッド</kbd> `validate_field_schema`
</h3>

```python theme={"system"}
validate_field_schema(schema: dict[str, Any]) → dict[str, Any]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L109" />

<h3 id="method-value_is_valid">
  <kbd>method</kbd> `value_is_valid`
</h3>

```python theme={"system"}
value_is_valid(payload: Any) → bool
```

このアノテーション spec のスキーマに基づいてペイロードを検証します。

**引数:**

* <b>`payload`</b>: スキーマに基づいて検証するデータ
  **戻り値:**

* <b>`bool`</b>:  検証に成功した場合は True、それ以外の場合は False

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/Audio/audio.py#L81" />

<h2 id="class-audio">
  <kbd>クラス</kbd> `Audio`
</h2>

サポートされる形式 (wav または mp3) のオーディオデータを表すクラスです。

このクラスはオーディオデータの保存を担い、さまざまなソースからの読み込みやファイルへのエクスポートを行うメソッドを提供します。

**属性:**

* <b>`format`</b>:  オーディオ形式 (現在は 'wav' または 'mp3' をサポート)
* <b>`data`</b>:  生のオーディオデータ (バイト列)

**引数:**

* <b>`data`</b>: オーディオデータ (バイト列または base64 エンコードされた string)

* <b>`format`</b>: オーディオ形式 ('wav' または 'mp3')

* <b>`validate_base64`</b>: 入力データの base64 デコードを試みるかどうか
  **送出される例外:**

* <b>`ValueError`</b>:  オーディオデータが空の場合、または形式がサポートされていない場合

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/Audio/audio.py#L106" />

<h3 id="method-__init__">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(
    data: 'bytes',
    format: 'SUPPORTED_FORMATS_TYPE',
    validate_base64: 'bool' = True
) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/Audio/audio.py#L174" />

<h3 id="method-export">
  <kbd>method</kbd> `export`
</h3>

```python theme={"system"}
export(path: 'str | bytes | Path | PathLike') → None
```

オーディオデータをファイルにエクスポートします。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/Audio/audio.py#L121" />

<h3 id="classmethod-from_data">
  <kbd>クラスメソッド</kbd> `from_data`
</h3>

```python theme={"system"}
from_data(data: 'str | bytes', format: 'str') → Self
```

生データと指定された形式から Audio オブジェクトを作成します。

* <b>`path`</b>: オーディオファイルの書き込み先パス
  **引数:**

* <b>`data`</b>: bytes または base64 エンコードされた string 形式のオーディオデータ

* <b>`format`</b>: オーディオ形式 ('wav' または 'mp3')
  **戻り値:**

* <b>`Audio`</b>:  新しい Audio インスタンス

**送出される例外:**

* <b>`ValueError`</b>:  形式がサポートされていない場合

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/Audio/audio.py#L146" />

<h3 id="classmethod-from_path">
  <kbd>クラスメソッド</kbd> `from_path`
</h3>

```python theme={"system"}
from_path(path: 'str | bytes | Path | PathLike') → Self
```

ファイルパスから Audio オブジェクトを作成します。

**引数:**

* <b>`path`</b>: オーディオファイルのパス (拡張子は .wav または .mp3 である必要があります)
  **戻り値:**

* <b>`Audio`</b>:  ファイルから読み込まれた新しい Audio インスタンス

**送出される例外:**

* <b>`ValueError`</b>:  ファイルが存在しない場合、または拡張子がサポートされていない場合

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L278" />

<h2 id="class-classifiermonitor">
  <kbd>class</kbd> `ClassifierMonitor`
</h2>

複数の Scorer を 1 つの分類器に統合するモニターです。

分類器モニターは、同じモデルを対象とする複数の LLMAsAJudgeScorer のプロンプトを 1 回のスコアリング Call にまとめます。

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `sampling_rate`: `<class 'float'>`
* `scorers`: `list[flow.scorer.Scorer]`
* `op_names`: `list[typing.Union[typing.Literal['genai.turn_ended'], str]]`
* `query`: `trace_server.interface.query.Query | None`
* `is_traced`: `<class 'bool'>`
* `active`: `<class 'bool'>`
* `scorer_debounce_config`: `flow.monitor.ScorerDebounceConfig | None`
* `prompt_header`: `str | None`
* `prompt_footer`: `str | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L141" />

<h3 id="method-activate">
  <kbd>method</kbd> `activate`
</h3>

```python theme={"system"}
activate() → ObjectRef
```

モニターを有効化します。

**戻り値:**
モニターの ref。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L152" />

<h3 id="method-deactivate">
  <kbd>method</kbd> `deactivate`
</h3>

```python theme={"system"}
deactivate() → ObjectRef
```

モニターを無効化します。

**戻り値:**
モニターの ref。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L203" />

<h3 id="classmethod-from_obj">
  <kbd>クラスメソッド</kbd> `from_obj`
</h3>

```python theme={"system"}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L302" />

<h3 id="method-get_prompt_footer">
  <kbd>method</kbd> `get_prompt_footer`
</h3>

```python theme={"system"}
get_prompt_footer() → str
```

統合された分類器プロンプトの後に追加するテキスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L296" />

<h3 id="method-get_prompt_header">
  <kbd>method</kbd> `get_prompt_header`
</h3>

```python theme={"system"}
get_prompt_header(op_name: str) → str
```

統合された分類器プロンプトの先頭に付加するテキスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L118" />

<h3 id="method-model_post_init">
  <kbd>method</kbd> `model_post_init`
</h3>

```python theme={"system"}
model_post_init(context: Any) → None
```

クライアントが利用可能な場合は、構築時に `op_names` を正規化します。

パブリッシュにはオブジェクトごとの hook がないため、`activate()` を呼び出さずに `weave.publish(monitor)` だけを実行するケースにも対応できるよう、ここで短い名前を展開します。パブリッシュを行うユーザーは通常すでに `weave.init` を呼び出しているため、モニターの構築時点でクライアントが設定されています。

単体テスト、インスペクション、ワーカー内での保存済みモニターのデシリアライズなど、クライアントなしで構築するユースケースもあります。`get_weave_client()` のガードにより、クライアントがなくても構築できます。この場合は正規化が行われませんが、保存済みのモニターはすでに完全な ref を保持しているため問題ありません。

なお、SDK でモニターを作成した際に正規化が行われないエッジケースがあります。ユーザーがモニターを構築した後に weave.init を呼び出し、その後モニターをパブリッシュした場合です。このケースでは、`activate()` または `deactivate()` を呼び出すことで回避できます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L42" />

<h2 id="class-content">
  <kbd>class</kbd> `Content`
</h2>

さまざまなソースから取得したコンテンツを表すクラスです。コンテンツは、関連するメタデータを含む統一されたバイト指向の表現に変換されます。

このクラスは、次のいずれかのクラスメソッドを使用してインスタンス化する必要があります。

* from\_path()
* from\_bytes()
* from\_text()
* from\_url()
* from\_base64()
* from\_data\_url()

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L87" />

<h3 id="method-__init__-2">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(*args: 'Any', **kwargs: 'Any') → None
```

直接の初期化は無効になっています。インスタンスを作成するには、`Content.from_path()` などのクラスメソッドを使用してください。

**Pydantic のフィールド:**

* `data`: `<class 'bytes'>`
* `size`: `<class 'int'>`
* `mimetype`: `<class 'str'>`
* `digest`: `<class 'str'>`
* `filename`: `<class 'str'>`
* `content_type`: `typing.Literal['bytes', 'text', 'base64', 'file', 'url', 'data_url', 'data_url:base64', 'data_url:encoding', 'data_url:encoding:base64']`
* `input_type`: `<class 'str'>`
* `encoding`: `<class 'str'>`
* `metadata`: `dict[str, typing.Any] | None`
* `extension`: `str | None`

***

<h4 id="property-art">
  <kbd>property</kbd> art
</h4>

<h4 id="property-ref">
  <kbd>property</kbd> ref
</h4>

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L543" />

<h3 id="method-as_string">
  <kbd>メソッド</kbd> `as_string`
</h3>

```python theme={"system"}
as_string() → str
```

データを string として表示します。バイトは `encoding` 属性を使用してデコードされます。base64 の場合は、データを base64 バイトに再エンコードしてから ASCII string にデコードします。

**戻り値:**
str.

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L258" />

<h3 id="classmethod-from_base64">
  <kbd>クラスメソッド</kbd> `from_base64`
</h3>

```python theme={"system"}
from_base64(
    b64_data: 'str | bytes',
    extension: 'str | None' = None,
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None
) → Self
```

base64 でエンコードされた string または bytes から Content を初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L168" />

<h3 id="classmethod-from_bytes">
  <kbd>クラスメソッド</kbd> `from_bytes`
</h3>

```python theme={"system"}
from_bytes(
    data: 'bytes',
    extension: 'str | None' = None,
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None,
    encoding: 'str' = 'utf-8'
) → Self
```

生のバイト列から Content を初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L357" />

<h3 id="classmethod-from_data_url">
  <kbd>クラスメソッド</kbd> `from_data_url`
</h3>

```python theme={"system"}
from_data_url(url: 'str', metadata: 'dict[str, Any] | None' = None) → Self
```

データ URL から Content を初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L309" />

<h3 id="classmethod-from_path-2">
  <kbd>クラスメソッド</kbd> `from_path`
</h3>

```python theme={"system"}
from_path(
    path: 'str | Path',
    encoding: 'str' = 'utf-8',
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None
) → Self
```

ローカルのファイルパスから Content を初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L209" />

<h3 id="classmethod-from_text">
  <kbd>クラスメソッド</kbd> `from_text`
</h3>

```python theme={"system"}
from_text(
    text: 'str',
    extension: 'str | None' = None,
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None,
    encoding: 'str' = 'utf-8'
) → Self
```

テキストの string から Content を初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L399" />

<h3 id="classmethod-from_url">
  <kbd>クラスメソッド</kbd> `from_url`
</h3>

```python theme={"system"}
from_url(
    url: 'str',
    headers: 'dict[str, Any] | None' = None,
    timeout: 'int | None' = 30,
    metadata: 'dict[str, Any] | None' = None
) → Self
```

HTTP(S) URL からバイト列を取得して Content を初期化します。

コンテンツをダウンロードし、ヘッダー、URL パス、データから mimetype/拡張子を推測したうえで、取得したバイト列から Content オブジェクトを構築します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L97" />

<h3 id="classmethod-model_validate">
  <kbd>クラスメソッド</kbd> `model_validate`
</h3>

```python theme={"system"}
model_validate(
    obj: 'Any',
    strict: 'bool | None' = None,
    from_attributes: 'bool | None' = None,
    context: 'dict[str, Any] | None' = None,
    extra: 'str | None' = None,
    by_alias: 'bool | None' = None,
    by_name: 'bool | None' = None
) → Self
```

dict から Content を再構成できるように model\_validate をオーバーライドします。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L148" />

<h3 id="classmethod-model_validate_json">
  <kbd>クラスメソッド</kbd> `model_validate_json`
</h3>

```python theme={"system"}
model_validate_json(
    json_data: 'str | bytes | bytearray',
    strict: 'bool | None' = None,
    context: 'dict[str, Any] | None' = None,
    extra: 'str | None' = None,
    by_alias: 'bool | None' = None,
    by_name: 'bool | None' = None
) → Self
```

model\_validate\_json をオーバーライドし、JSON から Content を再構成できるようにします。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L553" />

<h3 id="method-open">
  <kbd>method</kbd> `open`
</h3>

```python theme={"system"}
open() → bool
```

オペレーティングシステムの既定のアプリケーションでファイルを開きます。

このメソッドは、プラットフォーム固有の仕組みを使用して、ファイルのタイプに関連付けられた既定のアプリケーションでファイルを開きます。

**戻り値:**

* <b>`bool`</b>:  ファイルを正常に開けた場合は True、それ以外の場合は False。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L583" />

<h3 id="method-save">
  <kbd>method</kbd> `save`
</h3>

```python theme={"system"}
save(dest: 'str | Path') → None
```

指定されたコピー先パスにファイルをコピーします。content のファイル名とパスを、最後に保存したコピーに合わせて更新します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L535" />

<h3 id="method-serialize_data">
  <kbd>method</kbd> `serialize_data`
</h3>

```python theme={"system"}
serialize_data(data: 'bytes') → str
```

JSON モードでモデルをダンプする場合

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_wrappers/Content/content.py#L510" />

<h3 id="method-to_data_url">
  <kbd>メソッド</kbd> `to_data_url`
</h3>

```python theme={"system"}
to_data_url(use_base64: 'bool' = True) → str
```

コンテンツからデータ URL を構築します。

* <b>`dest`</b>: ファイルのコピー先パス (string または pathlib.Path) 。コピー先パスにはファイルまたはディレクトリを指定できます。dest にファイル拡張子 (例: .txt) がない場合、コピー先はディレクトリとして扱われます。
  **引数:**

* <b>`use_base64`</b>: True の場合、データは base64 でエンコードされます。False の場合は、パーセントエンコードされます。デフォルトは True です。
  **戻り値:**
  データ URL の string。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1080" />

<h2 id="class-conversation">
  <kbd>class</kbd> `Conversation`
</h2>

会話を表します。ターンを conversation\_id ごとにグループ化します (スパンは作成しません) 。

`continue_parent_trace` は、この会話が作成するターンのトレース分離を制御します。デフォルトの `False` では、各ターンがそれぞれ独自の OTel トレースを開始します (スタンドアロンの Agents タブビューではこちらが適しています) 。エージェントの invocation を含めるべき外側のトレース (例: fastapi でインストルメントされたリクエスト) がアプリケーションにある場合は、`True` に設定します。

**Pydantic のフィールド:**

* `conversation_id`: `<class 'str'>`
* `conversation_name`: `<class 'str'>`
* `agent_name`: `<class 'str'>`
* `model`: `<class 'str'>`
* `agent_id`: `<class 'str'>`
* `agent_description`: `<class 'str'>`
* `agent_version`: `<class 'str'>`
* `include_content`: `<class 'bool'>`
* `continue_parent_trace`: `<class 'bool'>`
* `attributes`: `dict[str, typing.Any]`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1157" />

<h3 id="method-end">
  <kbd>method</kbd> `end`
</h3>

```python theme={"system"}
end() → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/pydantic/_internal/_model_construction.py#L1112" />

<h3 id="method-model_post_init-2">
  <kbd>method</kbd> `model_post_init`
</h3>

```python theme={"system"}
model_post_init(context: 'Any') → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1116" />

<h3 id="method-start_turn">
  <kbd>method</kbd> `start_turn`
</h3>

```python theme={"system"}
start_turn(
    user_message: 'str' = '',
    model: 'str' = '',
    agent_name: 'str' = '',
    agent_id: 'str' = '',
    agent_description: 'str' = '',
    agent_version: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → Turn
```

新しいターンを作成します。前のターンがまだ終了していない場合は、自動的に終了します。

`_current_turn` contextvar を設定するため、コンテキストマネージャーを使用するかどうかにかかわらず、`get_current_turn()` からターンを参照できます。`agent_name` / `model` / `agent_id` / `agent_description` / `agent_version` は、いずれも空のままにすると会話のデフォルト値が使用されます。`continue_parent_trace` は継承されます。これらの値は、後から `turn.record(...)` でいつでも上書きできます。

`system_instructions`(エージェントのシステムプロンプト)は、ターンの invoke\_agent スパンに保持されます。`start_llm` と同様に、返された `Turn` の属性に値を代入して後から設定することもできます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L26" />

<h2 id="class-dataset">
  <kbd>class</kbd> `Dataset`
</h2>

簡単に保存でき、自動でバージョン管理される Dataset オブジェクトです。

**サンプル:**

```python theme={"system"}
# データセットを作成する
dataset = Dataset(name='grammar', rows=[
     {'id': '0', 'sentence': "He no likes ice cream.", 'correction': "He doesn't like ice cream."},
     {'id': '1', 'sentence': "She goed to the store.", 'correction': "She went to the store."},
     {'id': '2', 'sentence': "They plays video games all day.", 'correction': "They play video games all day."}
])

# データセットをパブリッシュする
weave.publish(dataset)

# データセットを取得する
dataset_ref = weave.ref('grammar').get()

# 特定のサンプルにアクセスする
example_label = dataset_ref.rows[2]['sentence']
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `rows`: `trace.table.Table | trace.vals.WeaveTable`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L129" />

<h3 id="method-add_rows">
  <kbd>method</kbd> `add_rows`
</h3>

```python theme={"system"}
add_rows(rows: Iterable[dict]) → Dataset
```

既存のデータセットに行を追加して、データセットの新しいバージョンを作成します。

データセット全体をメモリに読み込まずに大規模なデータセットにサンプルを追加できるため、便利です。

**引数:**

* <b>`rows`</b>: データセットに追加する行。
  **戻り値:**
  更新されたデータセット。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L173" />

<h3 id="classmethod-convert_to_table">
  <kbd>クラスメソッド</kbd> `convert_to_table`
</h3>

```python theme={"system"}
convert_to_table(rows: Any) → Table | WeaveTable
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L61" />

<h3 id="classmethod-from_calls">
  <kbd>クラスメソッド</kbd> `from_calls`
</h3>

```python theme={"system"}
from_calls(calls: Iterable[Call]) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L71" />

<h3 id="classmethod-from_hf">
  <kbd>クラスメソッド</kbd> `from_hf`
</h3>

```python theme={"system"}
from_hf(hf_dataset: 'HFDataset | HFDatasetDict') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L52" />

<h3 id="classmethod-from_obj-2">
  <kbd>クラスメソッド</kbd> `from_obj`
</h3>

```python theme={"system"}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L66" />

<h3 id="classmethod-from_pandas">
  <kbd>クラスメソッド</kbd> `from_pandas`
</h3>

```python theme={"system"}
from_pandas(df: 'DataFrame') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L220" />

<h3 id="method-select">
  <kbd>method</kbd> `select`
</h3>

```python theme={"system"}
select(indices: Iterable[int]) → Self
```

指定したインデックスに基づいて、データセットから行を選択します。

**引数:**

* <b>`indices`</b>: 選択する行を指定する整数インデックスのイテラブル。
  **戻り値:**
  選択した行のみを含む新しい Dataset オブジェクト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L115" />

<h3 id="method-to_hf">
  <kbd>method</kbd> `to_hf`
</h3>

```python theme={"system"}
to_hf() → HFDataset
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/dataset/dataset.py#L107" />

<h3 id="method-to_pandas">
  <kbd>method</kbd> `to_pandas`
</h3>

```python theme={"system"}
to_pandas() → DataFrame
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L192" />

<h2 id="class-easyprompt">
  <kbd>クラス</kbd> `EasyPrompt`
</h2>

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L200" />

<h3 id="method-__init__-3">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(
    content: str | dict | list | None = None,
    role: str | None = None,
    dedent: bool = False,
    **kwargs: Any
) → None
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `data`: `<class 'list'>`
* `config`: `<class 'dict'>`
* `requirements`: `<class 'dict'>`

***

<h4 id="property-as_str">
  <kbd>プロパティ</kbd> as\_str
</h4>

すべてのメッセージを結合して 1 つの string にします。

***

<h4 id="property-is_bound">
  <kbd>プロパティ</kbd> is\_bound
</h4>

***

<h4 id="property-messages">
  <kbd>property</kbd> messages
</h4>

<h4 id="property-placeholders">
  <kbd>property</kbd> placeholders
</h4>

***

<h4 id="property-system_message">
  <kbd>property</kbd> system\_message
</h4>

すべてのメッセージを結合して、1 つのシステムプロンプトメッセージにします。

***

<h4 id="property-system_prompt">
  <kbd>property</kbd> system\_prompt
</h4>

すべてのメッセージを結合して、1 つのシステム プロンプト オブジェクトにします。

***

<h4 id="property-unbound_placeholders">
  <kbd>property</kbd> unbound\_placeholders
</h4>

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L230" />

<h3 id="method-append">
  <kbd>method</kbd> `append`
</h3>

```python theme={"system"}
append(item: Any, role: str | None = None, dedent: bool = False) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L489" />

<h3 id="method-as_dict">
  <kbd>method</kbd> `as_dict`
</h3>

```python theme={"system"}
as_dict() → dict[str, Any]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L486" />

<h3 id="method-as_pydantic_dict">
  <kbd>method</kbd> `as_pydantic_dict`
</h3>

```python theme={"system"}
as_pydantic_dict() → dict[str, Any]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L321" />

<h3 id="method-bind">
  <kbd>method</kbd> `bind`
</h3>

```python theme={"system"}
bind(*args: Any, **kwargs: Any) → Prompt
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L341" />

<h3 id="method-bind_rows">
  <kbd>method</kbd> `bind_rows`
</h3>

```python theme={"system"}
bind_rows(dataset: list[dict] | Any) → list['Prompt']
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L447" />

<h3 id="method-config_table">
  <kbd>method</kbd> `config_table`
</h3>

```python theme={"system"}
config_table(title: str | None = None) → Table
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L411" />

<h3 id="method-configure">
  <kbd>method</kbd> `configure`
</h3>

```python theme={"system"}
configure(config: dict | None = None, **kwargs: Any) → Prompt
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L527" />

<h3 id="method-dump">
  <kbd>method</kbd> `dump`
</h3>

```python theme={"system"}
dump(fp: <class 'IO'>) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L530" />

<h3 id="method-dump_file">
  <kbd>method</kbd> `dump_file`
</h3>

```python theme={"system"}
dump_file(filepath: str | Path) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L84" />

<h3 id="method-format">
  <kbd>method</kbd> `format`
</h3>

```python theme={"system"}
format(**kwargs: Any) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L496" />

<h3 id="classmethod-from_obj-3">
  <kbd>クラスメソッド</kbd> `from_obj`
</h3>

```python theme={"system"}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L511" />

<h3 id="classmethod-load">
  <kbd>クラスメソッド</kbd> `load`
</h3>

```python theme={"system"}
load(fp: <class 'IO'>) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L521" />

<h3 id="classmethod-load_file">
  <kbd>クラスメソッド</kbd> `load_file`
</h3>

```python theme={"system"}
load_file(filepath: str | Path) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L427" />

<h3 id="method-messages_table">
  <kbd>method</kbd> `messages_table`
</h3>

```python theme={"system"}
messages_table(title: str | None = None) → Table
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L455" />

<h3 id="method-print">
  <kbd>method</kbd> `print`
</h3>

```python theme={"system"}
print() → str
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L417" />

<h3 id="method-publish">
  <kbd>method</kbd> `publish`
</h3>

```python theme={"system"}
publish(
    name: str | None = None,
    tags: list[str] | None = None,
    aliases: list[str] | None = None
) → ObjectRef
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L407" />

<h3 id="method-require">
  <kbd>method</kbd> `require`
</h3>

```python theme={"system"}
require(param_name: str, **kwargs: Any) → Prompt
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L540" />

<h3 id="method-run">
  <kbd>method</kbd> `run`
</h3>

```python theme={"system"}
run() → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L298" />

<h3 id="method-validate_requirement">
  <kbd>method</kbd> `validate_requirement`
</h3>

```python theme={"system"}
validate_requirement(key: str, value: Any) → list
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L315" />

<h3 id="method-validate_requirements">
  <kbd>method</kbd> `validate_requirements`
</h3>

```python theme={"system"}
validate_requirements(values: dict[str, Any]) → list
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L439" />

<h3 id="method-values_table">
  <kbd>method</kbd> `values_table`
</h3>

```python theme={"system"}
values_table(title: str | None = None) → Table
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval.py#L147" />

<h2 id="class-evaluation">
  <kbd>class</kbd> `Evaluation`
</h2>

一連の Scorer とデータセットで構成される評価をセットアップします。

evaluation.evaluate(model) を呼び出すと、データセットの行がモデルに渡されます。その際、データセットの列名が model.predict の引数名と照合されます。

その後、すべての Scorer を呼び出し、結果を Weave に保存します。

データセットの行を前処理する場合は、preprocess\_model\_input に関数を渡します。

**サンプル:**

```python theme={"system"}
# サンプルを収集します
examples = [
     {"question": "What is the capital of France?", "expected": "Paris"},
     {"question": "Who wrote 'To Kill a Mockingbird'?", "expected": "Harper Lee"},
     {"question": "What is the square root of 64?", "expected": "8"},
]

# カスタムのスコアリング関数を定義します
@weave.op
def match_score1(expected: str, model_output: dict) -> dict:
     # ここにモデル出力をスコアリングするロジックを定義します
     return {'match': expected == model_output['generated_text']}

@weave.op
def function_to_evaluate(question: str):
     # ここに LLM Call を追加し、出力を返します
     return  {'generated_text': 'Paris'}

# スコアリング関数でサンプルをスコアリングします
evaluation = Evaluation(
     dataset=examples, scorers=[match_score1]
)

# 評価のトラッキングを開始します
weave.init('intro-example')
# 評価を実行します
asyncio.run(evaluation.evaluate(function_to_evaluate))
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `dataset`: `<class 'dataset.dataset.Dataset'>`
* `scorers`: `list[typing.Annotated[trace.op_protocol.Op | flow.scorer.Scorer, BeforeValidator(func=<function cast_to_scorer at 0x7f136d430d60>, json_schema_input_type=PydanticUndefined)]] | None`
* `preprocess_model_input`: `collections.abc.Callable[[dict], dict] | None`
* `trials`: `<class 'int'>`
* `metadata`: `dict[str, typing.Any] | None`
* `evaluation_name`: `str | collections.abc.Callable[trace.call.Call, str] | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L381" />

<h3 id="method-evaluate">
  <kbd>method</kbd> `evaluate`
</h3>

```python theme={"system"}
evaluate(model: Op | Model) → dict
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval.py#L205" />

<h3 id="classmethod-from_obj-4">
  <kbd>クラスメソッド</kbd> `from_obj`
</h3>

```python theme={"system"}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval.py#L329" />

<h3 id="method-get_eval_results">
  <kbd>method</kbd> `get_eval_results`
</h3>

```python theme={"system"}
get_eval_results(model: Op | Model) → EvaluationResults
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval.py#L397" />

<h3 id="method-get_evaluate_calls">
  <kbd>method</kbd> `get_evaluate_calls`
</h3>

```python theme={"system"}
get_evaluate_calls() → PaginatedIterator[CallSchema, WeaveObject]
```

この Evaluation オブジェクトを使用したすべての評価 Call を取得します。

1 つの評価に対して複数の評価 Call が存在する場合があるため (例: 同じ評価を複数回実行した場合) 、このメソッドは単一の Call ではなく CallsIter を返します。

**戻り値:**

* <b>`CallsIter`</b>:  評価の実行を表す Call オブジェクトのイテレーター。

**送出される例外:**

* <b>`ValueError`</b>:  評価に ref がない場合 (まだ保存または実行されていない場合) 。

**サンプル:**

```python theme={"system"}
evaluation = Evaluation(dataset=examples, scorers=[scorer])
await evaluation.evaluate(model)  # 先に評価を実行します
calls = evaluation.get_evaluate_calls()
for call in calls:
     print(f"Evaluation run: {call.id} at {call.started_at}")
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval.py#L433" />

<h3 id="method-get_score_calls">
  <kbd>method</kbd> `get_score_calls`
</h3>

```python theme={"system"}
get_score_calls() → dict[str, list[Call]]
```

各評価 run の Scorer Call を、トレース ID ごとにグループ化して取得します。

**戻り値:**

* <b>`dict[str, list[Call]]`</b>:  トレース ID をキー、Scorer Call オブジェクトのリストを値とする辞書。各トレース ID は 1 つの評価 run に対応し、リストにはその run で実行されたすべての Scorer Call が含まれます。

**サンプル:**

```python theme={"system"}
evaluation = Evaluation(dataset=examples, scorers=[accuracy_scorer, f1_scorer])
await evaluation.evaluate(model)
score_calls = evaluation.get_score_calls()
for trace_id, calls in score_calls.items():
     print(f"Trace {trace_id}: {len(calls)} scorer calls")
     for call in calls:
         scorer_name = call.summary.get("weave", {}).get("trace_name")
         print(f"  Scorer: {scorer_name}, Output: {call.output}")
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval.py#L472" />

<h3 id="method-get_scores">
  <kbd>method</kbd> `get_scores`
</h3>

```python theme={"system"}
get_scores() → dict[str, dict[str, list[Any]]]
```

評価 run から Scorer の出力を抽出して整理します。

**戻り値:**

* <b>`dict[str, dict[str, list[Any]]]`</b>:  次の構造を持つネストされた辞書です。
  * 第 1 階層のキーはトレース ID (評価 run) です
  * 第 2 階層のキーは Scorer 名です
  * 値は、該当する run と Scorer における Scorer の出力のリストです

**サンプル:**

```python theme={"system"}
evaluation = Evaluation(dataset=examples, scorers=[accuracy_scorer, f1_scorer])
await evaluation.evaluate(model)
scores = evaluation.get_scores()
# トレースおよび Scorer 別にスコアを参照
for trace_id, trace_scores in scores.items():
         print(f"Evaluation run {trace_id}:")
         for scorer_name, outputs in trace_scores.items():
             print(f"  {scorer_name}: {outputs}")
```

期待される出力：

```
{
     "trace_123": {
     "accuracy_scorer": [{"accuracy": 0.85}],
     "f1_scorer": [{"f1": 0.78}]
     }
}
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/pydantic/_internal/_model_construction.py#L249" />

<h3 id="method-model_post_init-3">
  <kbd>method</kbd> `model_post_init`
</h3>

```python theme={"system"}
model_post_init(context: Any) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L266" />

<h3 id="method-predict_and_score">
  <kbd>method</kbd> `predict_and_score`
</h3>

```python theme={"system"}
predict_and_score(model: Op | Model, example: dict) → dict
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L306" />

<h3 id="method-summarize">
  <kbd>method</kbd> `summarize`
</h3>

```python theme={"system"}
summarize(eval_table: EvaluationResults) → dict
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval_imperative.py#L642" />

<h2 id="class-evaluationlogger">
  <kbd>class</kbd> `EvaluationLogger`
</h2>

このクラスは、評価をログするための命令型インターフェースを提供します。

評価は、`log_prediction` メソッドで最初の予測をログした時点で自動的に開始され、`log_summary` メソッドを呼び出した時点で終了します。

予測をログするたびに、`ScoreLogger` オブジェクトが返されます。このオブジェクトを使用すると、その予測に対するスコアとメタデータをログできます。詳細については、`ScoreLogger` クラスを参照してください。

基本的な使い方 - 入力と出力を指定して予測を直接ログします:

```python theme={"system"}
ev = EvaluationLogger()

# 既知の入力と出力を指定して予測をログする
pred = ev.log_prediction(inputs={'q': 'Hello'}, outputs={'a': 'Hi there!'})
pred.log_score("correctness", 0.9)

# 評価を終了する
ev.log_summary({"avg_score": 0.9})
```

高度な使い方 - 動的な出力やネストされた操作には、コンテキストマネージャーを使用します：

```python theme={"system"}
ev = EvaluationLogger()

# ネストされた操作を取得する必要がある場合は、コンテキストマネージャーを使用します
with ev.log_prediction(inputs={'q': 'Hello'}) as pred:
     # このブロック内の操作（LLM Call など）はすべて、自動的に
     # predict Call の子になります
     response = your_llm_call(...)
     pred.output = response.content
     pred.log_score("correctness", 0.9)

# 評価を終了します
ev.log_summary({"avg_score": 0.9})
```

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval_imperative.py#L684" />

<h3 id="method-__init__-4">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(
    name: 'str | None' = None,
    model: 'Model | dict | str | None' = None,
    dataset: 'Dataset | list[dict] | str | None' = None,
    eval_attributes: 'dict[str, Any] | None' = None,
    scorers: 'list[str] | None' = None
) → None
```

***

<h4 id="property-attributes">
  <kbd>property</kbd> attributes
</h4>

***

<h4 id="property-ui_url">
  <kbd>property</kbd> ui\_url
</h4>

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval_imperative.py#L1106" />

<h3 id="method-fail">
  <kbd>method</kbd> `fail`
</h3>

```python theme={"system"}
fail(exception: 'BaseException') → None
```

例外を指定して評価を失敗させるための簡易メソッドです。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval_imperative.py#L1090" />

<h3 id="method-finish">
  <kbd>method</kbd> `finish`
</h3>

```python theme={"system"}
finish(exception: 'BaseException | None' = None) → None
```

サマリーをログせずに、評価リソースを明示的にクリーンアップします。

すべての予測 Call とメインの評価 Call を確実に確定済みにします。ロガーをコンテキストマネージャーとして使用している場合、このメソッドは自動的に呼び出されます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval_imperative.py#L950" />

<h3 id="method-log_example">
  <kbd>method</kbd> `log_example`
</h3>

```python theme={"system"}
log_example(
    inputs: 'dict[str, Any]',
    output: 'Any',
    scores: 'dict[str, ScoreType]'
) → None
```

inputs、output、scores を含む完全な例をログします。

すべてのデータが事前に揃っている場合に、log\_prediction と log\_score をまとめて実行できる便利なメソッドです。

**引数:**

* <b>`inputs`</b>: 予測の入力データ
* <b>`output`</b>: 出力値
* <b>`scores`</b>: scorer 名とスコア値を対応付ける辞書
  **例:**

```python theme={"system"}
ev = EvaluationLogger()
ev.log_example(
    inputs={'q': 'What is 2+2?'},
    output='4',
    scores={'correctness': 1.0, 'fluency': 0.9}
)
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval_imperative.py#L877" />

<h3 id="method-log_prediction">
  <kbd>method</kbd> `log_prediction`
</h3>

```python theme={"system"}
log_prediction(inputs: 'dict[str, Any]', output: 'Any' = None) → ScoreLogger
```

予測を評価にログします。

そのまま使用することも、コンテキストマネージャーとして使用することもできる ScoreLogger を返します。

**引数:**

* <b>`inputs`</b>: 予測の入力データ
* <b>`output`</b>: 出力値。デフォルトは None です。後から pred.output で設定することもできます。
  **戻り値:**
  スコアをログし、必要に応じて予測を完了するための ScoreLogger。

例 (直接使用):

* <b>`pred = ev.log_prediction({'q'`</b>:  '...'}, output="answer") pred.log\_score("correctness", 0.9) pred.finish()

例 (コンテキストマネージャー):

* <b>`with ev.log_prediction({'q'`</b>:  '...'}) as pred:  response = model(...)  pred.output = response  pred.log\_score("correctness", 0.9) # ブロックを抜けると自動的に finish() が呼び出されます

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval_imperative.py#L989" />

<h3 id="method-log_summary">
  <kbd>method</kbd> `log_summary`
</h3>

```python theme={"system"}
log_summary(summary: 'dict | None' = None, auto_summarize: 'bool' = True) → None
```

サマリーの dict を Evaluation にログします。

このメソッドはサマリーを計算し、summarize op を呼び出したうえで評価を確定します。確定後は、予測やスコアをログできなくなります。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/evaluation/eval_imperative.py#L1038" />

<h3 id="method-set_view">
  <kbd>method</kbd> `set_view`
</h3>

```python theme={"system"}
set_view(
    name: 'str',
    content: 'Content | str',
    extension: 'str | None' = None,
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None,
    encoding: 'str' = 'utf-8'
) → None
```

評価のメイン call のサマリー内の `weave.views` 配下にビューを関連付けます。

指定されたコンテンツを project 内のオブジェクトとして保存し、その参照 URI を評価の `evaluate` call の `summary.weave.views.<name>` に書き込みます。string の入力は、指定された拡張子または MIME タイプを使用し、`Content.from_text` でテキストコンテンツとしてラップされます。

**引数:**

* <b>`name`</b>: 表示するビュー名。`summary.weave.views` 配下のキーとして使用されます。
* <b>`content`</b>: シリアライズする `weave.Content` インスタンスまたは string。
* <b>`extension`</b>: string のコンテンツ入力に使用するファイル拡張子 (オプション) 。
* <b>`mimetype`</b>: string のコンテンツ入力に使用する MIME タイプ (オプション) 。
* <b>`metadata`</b>: 新しく作成される `Content` に関連付けるメタデータ (オプション) 。
* <b>`encoding`</b>: string のコンテンツ入力に使用するテキストエンコーディング。
  **戻り値:**
  None

**サンプル:**
` import weave`

> > > ev = weave.EvaluationLogger()
> > > ev.set\_view("report", "# Report", extension="md")

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/File/file.py#L30" />

<h2 id="class-file">
  <kbd>class</kbd> `File`
</h2>

パス、MIME タイプ、サイズの情報を持つファイルを表すクラスです。

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/File/file.py#L34" />

<h3 id="method-__init__-5">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(path: 'str | Path', mimetype: 'str | None' = None)
```

File オブジェクトを初期化します。

**引数:**

***

<h4 id="property-filename">
  <kbd>property</kbd> filename
</h4>

ファイル名を取得します。

* <b>`path`</b>: ファイルへのパス (string または pathlib.Path)

* <b>`mimetype`</b>: ファイルの MIME タイプ (オプション) 。指定しない場合は拡張子から推測されます
  **戻り値:**

* <b>`str`</b>:  ディレクトリパスを除いたファイル名。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/File/file.py#L60" />

<h3 id="method-open-2">
  <kbd>method</kbd> `open`
</h3>

```python theme={"system"}
open() → bool
```

オペレーティングシステムの既定のアプリケーションでファイルを開きます。

このメソッドは、プラットフォーム固有の仕組みを使用して、ファイルのタイプに関連付けられた既定のアプリケーションでファイルを開きます。

**戻り値:**

* <b>`bool`</b>:  ファイルを正常に開けた場合は True、それ以外の場合は False。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/type_handlers/File/file.py#L81" />

<h3 id="method-save-2">
  <kbd>method</kbd> `save`
</h3>

```python theme={"system"}
save(dest: 'str | Path') → None
```

ファイルを指定されたコピー先のパスにコピーします。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L418" />

<h2 id="class-llm">
  <kbd>class</kbd> `LLM`
</h2>

1 回の LLM API 呼び出しを表します。chat OTel スパンに対応します。

* <b>`dest`</b>: ファイルのコピー先パス (string または pathlib.Path) 。コピー先パスには、ファイルまたはディレクトリを指定できます。
  **Pydantic のフィールド:**

* `model`: `<class 'str'>`

* `provider_name`: `<class 'str'>`

* `response_id`: `<class 'str'>`

* `response_model`: `<class 'str'>`

* `output_type`: `<class 'str'>`

* `system_instructions`: `list[str]`

* `usage`: `<class 'conversation.types.Usage'>`

* `reasoning`: `<class 'conversation.types.Reasoning'>`

* `finish_reasons`: `list[str]`

* `input_messages`: `list[conversation.types.Message]`

* `output_messages`: `list[conversation.types.Message]`

* `media_attachments`: `list[conversation.types.MediaAttachment]`

* `request_temperature`: `float | None`

* `request_max_tokens`: `int | None`

* `request_top_p`: `float | None`

* `request_frequency_penalty`: `float | None`

* `request_presence_penalty`: `float | None`

* `request_seed`: `int | None`

* `request_stop_sequences`: `list[str]`

* `request_choice_count`: `int | None`

* `started_at`: `datetime.datetime | None`

* `ended_at`: `datetime.datetime | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/typing_extensions.py#L257" />

<h3 id="method-add_event">
  <kbd>method</kbd> `add_event`
</h3>

```python theme={"system"}
add_event(
    name: 'str',
    attributes: 'dict[str, Any] | None' = None,
    timestamp: 'datetime | None' = None
) → Self
```

このスパン内の特定の時点で OTel スパンイベントを記録します。

.. deprecated:
\`\`\`      このデータは代わりに `set_attributes` で記録してください。OpenTelemetry は      Span Event API (`Span.add_event`) を段階的に廃止しています。      `add_event` は引き続き動作し、既存のスパンイベントデータも引き続き有効です。      詳細については、[https://opentelemetry.io/blog/2026/deprecating-span-events/](https://opentelemetry.io/blog/2026/deprecating-span-events/) を参照してください。

````
マーカーやライフサイクルのデータに使用します。具体的には、権限確認プロンプト（例: ``weave.permission_request``）、ライフサイクルの遷移（例: ``spawned`` / ``streaming`` / ``finished``）、そのほかスパンの有効期間中の特定の時点で発生する任意のカスタムマイルストーンが該当します（一方、属性はスパン全体に対するプロパティです）。 

スパンの開始から終了までの間（``with`` ブロック内）で呼び出す必要があります。この範囲外で呼び出した場合は no-op となり、警告がログされます。 

---

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L462" />

### <kbd>method</kbd> `attach_media`

```python
attach_media(
    content: 'bytes | str' = '',
    uri: 'str' = '',
    file_id: 'str' = '',
    mime_type: 'str' = '',
    modality: 'str' = ''
) → LLM
````

この LLM Call にメディアを添付します。

指定されたデータから `Content` オブジェクトを作成し、パブリッシュして `weave://` ref を取得したうえで、その ref のみを保存します。`content`、`uri`、`file_id` のうち、いずれか 1 つだけを指定する必要があります。

パブリッシュ (メディアのアップロード) は専用のバックグラウンドスレッドで実行されるため、この呼び出しは呼び出し元をブロックせずにすぐに返ります。スレッドは添付ごとに 1 つずつディスパッチされるため、複数のアップロードが並行して実行されます。プレースホルダーの `MediaAttachment` は同期的に追加され、その `ref` はアップロードの完了後に設定されます。ref はスパンの送出前に必ず設定されます (ビルド処理は `_await_uploads` を通じて、進行中のアップロードの完了を待機します) 。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L555" />

<h3 id="method-attach_media_url">
  <kbd>method</kbd> `attach_media_url`
</h3>

```python theme={"system"}
attach_media_url(url: 'str', modality: 'str' = '') → LLM
```

この LLM Call にメディア URL をアタッチします。

呼び出し元が上流のメッセージから取得した URL 文字列を持っている一般的なケース向けに、`attach_media` を簡単に使えるようにしたメソッドです。`data:` URL はバイト列に解析されてからパブリッシュされ、通常の URI は取得されてからパブリッシュされます。空の URL は無視されます。メソッドチェーン用に `self` を返します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L690" />

<h3 id="method-end-2">
  <kbd>method</kbd> `end`
</h3>

```python theme={"system"}
end() → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/pydantic/_internal/_model_construction.py#L448" />

<h3 id="method-model_post_init-4">
  <kbd>method</kbd> `model_post_init`
</h3>

```python theme={"system"}
model_post_init(context: 'Any') → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L452" />

<h3 id="method-output">
  <kbd>method</kbd> `output`
</h3>

```python theme={"system"}
output(content: 'str') → LLM
```

output\_messages にアシスタント メッセージを追加します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L572" />

<h3 id="method-record">
  <kbd>method</kbd> `record`
</h3>

```python theme={"system"}
record(
    input_messages: 'list[Message] | None' = None,
    output_messages: 'list[Message] | None' = None,
    media_attachments: 'list[MediaAttachment] | None' = None,
    usage: 'Usage | None' = None,
    reasoning: 'Reasoning | str | None' = None,
    response_id: 'str | None' = None,
    response_model: 'str | None' = None,
    finish_reasons: 'list[str] | None' = None,
    output_type: 'str | None' = None
) → LLM
```

複数の LLM Call フィールドを 1 回の呼び出しで設定します。

手動でインストルメントされたエージェントでは通常、LLM Call の終了時に 8 つ以上のフィールド (`input_messages`、`output_messages`、`usage`、`response_id` など) を個別に割り当てて chat スパンを構築します。`record(...)` を使うと、これらを 1 回のキーワード引数付き呼び出しにまとめられるため、記録処理を簡潔に記述できます。

明示的に渡された (`None` 以外の) フィールドのみが適用され、既存の値は保持されます。`reasoning` には `Reasoning` インスタンスまたはプレーンな string のいずれかを指定できます (string は自動的にラップされます) 。メソッドチェーン用に `self` を返します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L241" />

<h3 id="method-set_attributes">
  <kbd>method</kbd> `set_attributes`
</h3>

```python theme={"system"}
set_attributes(attributes: 'dict[str, Any]') → Self
```

このスパンに任意の OTel 属性を設定します。

キーが 1 つでも複数でも dict を渡します。キーが 1 つの場合は `span.set_attributes({"weave.tag": "value"})` のように呼び出します。OTel の `Span.set_attributes` と同等です。

スパンの開始から終了までの間、つまり `with` ブロック内で呼び出す必要があります。この範囲外で呼び出すと no-op となり、警告がログされます。バッチでインジェストする場合は、オブジェクトで宣言されたフィールドに直接値を設定し、`log_turn` / `log_conversation` に渡してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L457" />

<h3 id="method-think">
  <kbd>method</kbd> `think`
</h3>

```python theme={"system"}
think(content: 'str') → LLM
```

推論/思考の連鎖の内容を設定します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/types.py#L256" />

<h2 id="class-logresult">
  <kbd>class</kbd> `LogResult`
</h2>

`log_*` によるバッチ呼び出しの結果です。

**Pydantic のフィールド:**

* `conversation_id`: `<class 'str'>`
* `trace_ids`: `list[str]`
* `root_span_ids`: `list[str]`
* `span_count`: `<class 'int'>`

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/rich/markdown.py#L513" />

<h2 id="class-markdown">
  <kbd>クラス</kbd> `Markdown`
</h2>

レンダリング可能な Markdown オブジェクトです。

**引数:**

* <b>`markup`</b> (str):  Markdown を含む string。
* <b>`code_theme`</b> (str, optional):  コードブロックに使用する Pygments テーマ。デフォルトは "monokai" です。コードテーマについては [https://pygments.org/styles/](https://pygments.org/styles/) を参照してください。
* <b>`justify`</b> (JustifyMethod, optional):  段落の配置 (justify) の値。デフォルトは None です。
* <b>`style`</b> (Union\[str, Style], optional):  Markdown に適用するスタイル (オプション)。
* <b>`hyperlinks`</b> (bool, optional):  ハイパーリンクを有効にします。デフォルトは `True` です。

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/rich/markdown.py#L549" />

<h3 id="method-__init__-6">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(
    markup: 'str',
    code_theme: 'str' = 'monokai',
    justify: 'JustifyMethod | None' = None,
    style: 'str | Style' = 'none',
    hyperlinks: 'bool' = True,
    inline_code_lexer: 'str | None' = None,
    inline_code_theme: 'str | None' = None
) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/types.py#L243" />

<h2 id="class-mediaattachment">
  <kbd>class</kbd> `MediaAttachment`
</h2>

LLM Call に添付されたメディアです。

常に `weave://` 形式の content ref URI を保持します。生のバイト列、data URL、およびプレーンな HTTP URI は、ここに格納される前に `LLM.attach_media` によってパブリッシュ済みの `Content` オブジェクトに変換されます。

* <b>`inline_code_lexer`</b>: (str, optional): インラインコードのハイライトが有効な場合に使用するレキサー。デフォルトは None です。

* <b>`inline_code_theme`</b>: (Optional\[str], optional): インラインコードのハイライトに使用する Pygments テーマ。ハイライトしない場合は None を指定します。デフォルトは None です。
  **Pydantic のフィールド:**

* `ref`: `<class 'str'>`

* `modality`: `<class 'str'>`

* `mime_type`: `<class 'str'>`

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/types.py#L158" />

<h2 id="class-message">
  <kbd>class</kbd> `Message`
</h2>

会話内の 1 つのメッセージを表します。

次の 2 つの構築方法がサポートされています。

1. フラット形式 (後方互換性があり、プレーンテキストを簡単に扱えます):  `Message(role="assistant", content="Hi there")`

2. 明示的なパーツ形式 (より表現力が高く、ツール呼び出し、推論とテキストの混在、インラインメディアをサポートします):  `Message(role="assistant", parts=[TextPart(content="Let me check"),  ToolCallPart(id="c1", name="get_weather", arguments='{...}')])`

`parts` が空でない場合は、`parts` が正規の表現となります。空の場合、シリアライザーはフラットフィールドから単一の TextPart (`role="tool"` の場合は ToolCallResponsePart) を合成します。

**Pydantic のフィールド:**

* `role`: `typing.Literal['user', 'assistant', 'system', 'tool']`
* `content`: `<class 'str'>`
* `tool_call_id`: `<class 'str'>`
* `tool_name`: `<class 'str'>`
* `parts`: `list[typing.Annotated[conversation.types.TextPart | conversation.types.ReasoningPart | conversation.types.ToolCallPart | conversation.types.ToolCallResponsePart | conversation.types.BlobPart | conversation.types.UriPart | conversation.types.FilePart, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/types.py#L192" />

<h3 id="classmethod-assistant">
  <kbd>クラスメソッド</kbd> `assistant`
</h3>

```python theme={"system"}
assistant(
    text: 'str' = '',
    tool_calls: 'list[ToolCallPart] | None' = None
) → Message
```

テキストとツール呼び出し (いずれも省略可能) を含むアシスタント メッセージを作成します。

単純な応答にはプレーン テキストを使用します。アシスタントが 1 つ以上のツールをリクエストする場合は、`tool_calls` を渡します。両方を指定した場合、テキストが先頭の `TextPart` として出力され、その後に各 `ToolCallPart` が続きます。これにより、チャット ビューでそれらがインラインでレンダリングされます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/types.py#L187" />

<h3 id="classmethod-system">
  <kbd>クラスメソッド</kbd> `system`
</h3>

```python theme={"system"}
system(text: 'str') → Message
```

プレーンテキストからシステムメッセージを作成します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/types.py#L214" />

<h3 id="classmethod-tool_result">
  <kbd>クラスメソッド</kbd> `tool_result`
</h3>

```python theme={"system"}
tool_result(call_id: 'str', output: 'Any') → Message
```

以前にリクエストされたツール呼び出しに対する、ツール結果メッセージを作成します。

`output` には string、dict、list、スカラー値、または `None` を指定できます。内部で使用される `ToolCallResponsePart` が、string 以外の値を JSON エンコードします。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/types.py#L182" />

<h3 id="classmethod-user">
  <kbd>クラスメソッド</kbd> `user`
</h3>

```python theme={"system"}
user(text: 'str') → Message
```

プレーンテキストからユーザーメッセージを構築します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L164" />

<h2 id="class-messagesprompt">
  <kbd>クラス</kbd> `MessagesPrompt`
</h2>

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L168" />

<h3 id="method-__init__-7">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(messages: list[dict])
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `messages`: `list[dict]`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L180" />

<h3 id="method-format-2">
  <kbd>method</kbd> `format`
</h3>

```python theme={"system"}
format(**kwargs: Any) → list
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L172" />

<h3 id="method-format_message">
  <kbd>method</kbd> `format_message`
</h3>

```python theme={"system"}
format_message(message: dict, **kwargs: Any) → dict
```

テンプレート変数を置換して、単一のメッセージをフォーマットします。

このメソッドは、実際のフォーマット処理をスタンドアロンの format\_message\_with\_template\_vars 関数に委譲します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L183" />

<h3 id="classmethod-from_obj-5">
  <kbd>クラスメソッド</kbd> `from_obj`
</h3>

```python theme={"system"}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/model.py#L25" />

<h2 id="class-model">
  <kbd>class</kbd> `Model`
</h2>

入力に対して処理を行うコードとデータの組み合わせを取得するためのものです。たとえば、プロンプトを指定して LLM を呼び出し、予測を行ったりテキストを生成したりできます。

モデルを定義する属性やコードを変更すると、その変更がログされ、バージョンが更新されます。これにより、モデルの異なるバージョン間で予測を比較できます。プロンプトを繰り返し改善したり、最新の LLM を試して異なる設定間で予測を比較したりする際に使用します。

**サンプル:**

```python theme={"system"}
class YourModel(Model):
     attribute1: str
     attribute2: int

     @weave.op
     def predict(self, input_data: str) -> dict:
         # ここにモデルのロジックを記述します
         prediction = self.attribute1 + ' ' + input_data
         return {'pred': prediction}
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/model.py#L51" />

<h3 id="method-get_infer_method">
  <kbd>method</kbd> `get_infer_method`
</h3>

```python theme={"system"}
get_infer_method() → Callable
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L48" />

<h2 id="class-monitor">
  <kbd>class</kbd> `Monitor`
</h2>

受信した Call を自動的にスコアリングするモニターを設定します。

op 名は、Weave クライアントの entity と project を使って weave ref に変換される点に注意してください。1 つのクライアントで複数の entity や project を扱う場合は、完全修飾の weave ref を指定する必要があります。詳細は \_normalized\_op\_names を参照してください。

**サンプル:**

```python theme={"system"}
import weave
from weave.scorers import ValidJSONScorer

json_scorer = ValidJSONScorer()

my_monitor = weave.Monitor(
     name="my-monitor",
     description="This is a test monitor",
     sampling_rate=0.5,
     op_names=["my_op"],
     query={
         "$expr": {
             "$gt": [
                 {
                         "$getField": "started_at"
                     },
                     {
                         "$literal": 1742540400
                     }
                 ]
             }
         }
     },
     scorers=[json_scorer],
)

my_monitor.activate()
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `sampling_rate`: `<class 'float'>`
* `scorers`: `list[flow.scorer.Scorer]`
* `op_names`: `list[typing.Union[typing.Literal['genai.turn_ended'], str]]`
* `query`: `trace_server.interface.query.Query | None`
* `is_traced`: `<class 'bool'>`
* `active`: `<class 'bool'>`
* `scorer_debounce_config`: `flow.monitor.ScorerDebounceConfig | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L141" />

<h3 id="method-activate-2">
  <kbd>method</kbd> `activate`
</h3>

```python theme={"system"}
activate() → ObjectRef
```

モニターを有効化します。

**戻り値:**
モニターの ref。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L152" />

<h3 id="method-deactivate-2">
  <kbd>method</kbd> `deactivate`
</h3>

```python theme={"system"}
deactivate() → ObjectRef
```

モニターを無効化します。

**戻り値:**
モニターの ref。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L203" />

<h3 id="classmethod-from_obj-6">
  <kbd>クラスメソッド</kbd> `from_obj`
</h3>

```python theme={"system"}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/monitor.py#L118" />

<h3 id="method-model_post_init-5">
  <kbd>method</kbd> `model_post_init`
</h3>

```python theme={"system"}
model_post_init(context: Any) → None
```

クライアントが利用可能な場合は、構築時に `op_names` を正規化します。

パブリッシュにはオブジェクト単位の hook がありません。そのため、`activate()` を呼び出さずに `weave.publish(monitor)` だけを実行した場合にも対応できるよう、ここで短い名前を展開します。パブリッシュを行うユーザーは通常すでに `weave.init` を呼び出しているため、モニターの構築時にはクライアントが設定されています。

ユニットテスト、検査、ワーカーでの保存済みモニターのデシリアライズなど、クライアントなしで構築するユースケースもいくつかあります。`get_weave_client()` に対するガードにより、クライアントなしでも構築できます。この場合は正規化が行われませんが、保存済みのモニターはすでに完全な ref を保持しているため問題ありません。

なお、SDK を使用して、正規化されないままモニターが作成されるエッジケースがあります。ユーザーがモニターを構築してから weave.init を呼び出し、その後モニターをパブリッシュした場合です。このケースでは、`activate()` または `deactivate()` を呼び出すことで回避できます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/object/obj.py#L26" />

<h2 id="class-object">
  <kbd>class</kbd> `Object`
</h2>

追跡およびバージョン管理が可能な Weave オブジェクトの基底クラスです。

このクラスは Pydantic の BaseModel を拡張し、オブジェクトの追跡、参照、シリアライズといった Weave 固有の機能を提供します。オブジェクトには名前、説明、参照を持たせることができ、これらを使って Weave システムへの保存や Weave システムからの取得を行えます。

**属性:**

* <b>`name`</b> (str | None):  オブジェクトの、人が読みやすい名前。
* <b>`description`</b> (str | None):  オブジェクトが表す内容の説明。
* <b>`ref`</b> (ObjectRef | None):  Weave システム内のオブジェクトへの参照。

**サンプル:**

```python theme={"system"}
# シンプルなオブジェクトを作成する
obj = Object(name="my_object", description="A test object")

# URI からオブジェクトを作成する
obj = Object.from_uri("weave:///entity/project/object:digest")
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/object/obj.py#L65" />

<h3 id="classmethod-from_uri">
  <kbd>クラスメソッド</kbd> `from_uri`
</h3>

```python theme={"system"}
from_uri(uri: str, objectify: bool = True) → Self
```

Weave URI からオブジェクトのインスタンスを作成します。

**引数:**

* <b>`uri`</b> (str):  オブジェクトを指す Weave URI。
* <b>`objectify`</b> (bool):  結果をオブジェクト化するかどうか。デフォルトは True です。

**戻り値:**

* <b>`Self`</b>:  URI から作成されたクラスのインスタンス。

**送出される例外:**

* <b>`NotImplementedError`</b>:  クラスがデシリアライズに必要なメソッドを実装していない場合。

**サンプル:**

```python theme={"system"}
obj = MyObject.from_uri("weave:///entity/project/object:digest")
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/object/obj.py#L108" />

<h3 id="classmethod-handle_relocatable_object">
  <kbd>クラスメソッド</kbd> `handle_relocatable_object`
</h3>

```python theme={"system"}
handle_relocatable_object(
    v: Any,
    handler: ValidatorFunctionWrapHandler,
    info: ValidationInfo
) → Any
```

ObjectRef や WeaveObject などの再配置可能なオブジェクトの検証を処理します。

このバリデーターは、入力が ObjectRef または WeaveObject であり、標準の Object インスタンスへの適切な変換が必要となる特殊なケースを処理します。検証プロセスにおいて、参照が保持され、無視されるタイプが正しく処理されるようにします。

**引数:**

* <b>`v`</b> (Any):  検証する値。
* <b>`handler`</b> (ValidatorFunctionWrapHandler):  標準の pydantic 検証ハンドラ。
* <b>`info`</b> (ValidationInfo):  検証のコンテキスト情報。

**戻り値:**

* <b>`Any`</b>:  検証済みのオブジェクトインスタンス。

**サンプル:**
このメソッドは、オブジェクトの作成時および検証時に自動的に呼び出され、次のようなケースを処理します: \`\`\`python

<h1 id="when-an-objectref-is-passed">
  ObjectRef が渡された場合
</h1>

obj = MyObject(some\_object\_ref)

<h1 id="when-a-weaveobject-is-passed">
  WeaveObject が渡された場合
</h1>

obj = MyObject(some\_weave\_object)

````

---

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/object/obj.py#L91" />

### <kbd>classmethod</kbd> `strip_weave_serialization_metadata`

```python
strip_weave_serialization_metadata(data: Any) → Any
````

dict 入力から Weave のシリアライズメタデータを削除します。

Weave のシリアライズでは、型を再構成するために dict に \_type、\_class\_name、\_bases が追加されます。これらは実際のモデルフィールドではないため、extra="forbid" を使用する Pydantic の検証の前に削除する必要があります。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L183" />

<h2 id="class-objectref">
  <kbd>クラス</kbd> `ObjectRef`
</h2>

ObjectRef(entity: 'str', project: 'str', name: 'str', \_digest: 'str | Future\[str]', \_extra: 'tuple\[str | Future\[str], ...]' = ())

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/../../../../weave/trace/refs/__init__" />

<h3 id="method-__init__-8">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(
    entity: 'str',
    project: 'str',
    name: 'str',
    _digest: 'str | Future[str]',
    _extra: 'tuple[str | Future[str], ]' = ()
) → None
```

***

<h4 id="property-digest">
  <kbd>property</kbd> digest
</h4>

***

<h4 id="property-extra">
  <kbd>property</kbd> extra
</h4>

***

<h4 id="property-is_digest_resolved">
  <kbd>property</kbd> is\_digest\_resolved
</h4>

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L191" />

<h3 id="method-as_param_dict">
  <kbd>method</kbd> `as_param_dict`
</h3>

```python theme={"system"}
as_param_dict() → dict
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L287" />

<h3 id="method-delete">
  <kbd>method</kbd> `delete`
</h3>

```python theme={"system"}
delete() → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L243" />

<h3 id="method-get">
  <kbd>method</kbd> `get`
</h3>

```python theme={"system"}
get(objectify: 'bool' = True) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L271" />

<h3 id="method-is_descended_from">
  <kbd>method</kbd> `is_descended_from`
</h3>

```python theme={"system"}
is_descended_from(potential_ancestor: 'ObjectRef') → bool
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L93" />

<h3 id="method-maybe_parse_uri">
  <kbd>method</kbd> `maybe_parse_uri`
</h3>

```python theme={"system"}
maybe_parse_uri(s: 'str') → AnyRef | None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L294" />

<h3 id="method-parse_uri">
  <kbd>method</kbd> `parse_uri`
</h3>

```python theme={"system"}
parse_uri(uri: 'str') → ObjectRef
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L173" />

<h3 id="method-with_attr">
  <kbd>method</kbd> `with_attr`
</h3>

```python theme={"system"}
with_attr(attr: 'str') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L165" />

<h3 id="method-with_extra">
  <kbd>method</kbd> `with_extra`
</h3>

```python theme={"system"}
with_extra(extra: 'tuple[str | Future[str], ]') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L176" />

<h3 id="method-with_index">
  <kbd>method</kbd> `with_index`
</h3>

```python theme={"system"}
with_index(index: 'int') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L179" />

<h3 id="method-with_item">
  <kbd>method</kbd> `with_item`
</h3>

```python theme={"system"}
with_item(item_digest: 'str | Future[str]') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/refs.py#L170" />

<h3 id="method-with_key">
  <kbd>method</kbd> `with_key`
</h3>

```python theme={"system"}
with_key(key: 'str') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L83" />

<h2 id="class-prompt">
  <kbd>class</kbd> `Prompt`
</h2>

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L84" />

<h3 id="method-format-3">
  <kbd>method</kbd> `format`
</h3>

```python theme={"system"}
format(**kwargs: Any) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L494" />

<h2 id="class-savedview">
  <kbd>class</kbd> `SavedView`
</h2>

SavedView オブジェクトを操作するための Fluent スタイルのクラスです。

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L500" />

<h3 id="method-__init__-9">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(view_type: 'str' = 'traces', label: 'str' = 'SavedView') → None
```

***

<h4 id="property-entity">
  <kbd>property</kbd> entity
</h4>

***

<h4 id="property-label">
  <kbd>property</kbd> label
</h4>

***

<h4 id="property-project">
  <kbd>property</kbd> project
</h4>

***

<h4 id="property-view_type">
  <kbd>property</kbd> view\_type
</h4>

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L624" />

<h3 id="method-add_column">
  <kbd>method</kbd> `add_column`
</h3>

```python theme={"system"}
add_column(path: 'str | ObjectPath', label: 'str | None' = None) → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L633" />

<h3 id="method-add_columns">
  <kbd>method</kbd> `add_columns`
</h3>

```python theme={"system"}
add_columns(*columns: 'str') → SavedView
```

グリッドに複数の列をまとめて追加するための便利メソッドです。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L525" />

<h3 id="method-add_filter">
  <kbd>method</kbd> `add_filter`
</h3>

```python theme={"system"}
add_filter(
    field: 'str',
    operator: 'str',
    value: 'Any | None' = None
) → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L599" />

<h3 id="method-add_sort">
  <kbd>method</kbd> `add_sort`
</h3>

```python theme={"system"}
add_sort(field: 'str', direction: 'SortDirection') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L664" />

<h3 id="method-column_index">
  <kbd>method</kbd> `column_index`
</h3>

```python theme={"system"}
column_index(path: 'int | str | ObjectPath') → int
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L579" />

<h3 id="method-filter_op">
  <kbd>method</kbd> `filter_op`
</h3>

```python theme={"system"}
filter_op(op_name: 'str | None') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L849" />

<h3 id="method-get_calls">
  <kbd>method</kbd> `get_calls`
</h3>

```python theme={"system"}
get_calls(
    limit: 'int | None' = None,
    offset: 'int | None' = None,
    include_costs: 'bool' = False,
    include_feedback: 'bool' = False,
    all_columns: 'bool' = False
) → CallsIter
```

この保存済みビューのフィルターと設定に一致する Call を取得します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L907" />

<h3 id="method-get_known_columns">
  <kbd>method</kbd> `get_known_columns`
</h3>

```python theme={"system"}
get_known_columns(num_calls_to_query: 'int | None' = None) → list[str]
```

存在が確認されている列のセットを取得します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L917" />

<h3 id="method-get_table_columns">
  <kbd>method</kbd> `get_table_columns`
</h3>

```python theme={"system"}
get_table_columns() → list[TableColumn]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L618" />

<h3 id="method-hide_column">
  <kbd>method</kbd> `hide_column`
</h3>

```python theme={"system"}
hide_column(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L639" />

<h3 id="method-insert_column">
  <kbd>method</kbd> `insert_column`
</h3>

```python theme={"system"}
insert_column(
    idx: 'int',
    path: 'str | ObjectPath',
    label: 'str | None' = None
) → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L977" />

<h3 id="classmethod-load-2">
  <kbd>クラスメソッド</kbd> `load`
</h3>

```python theme={"system"}
load(ref: 'str') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L742" />

<h3 id="method-page_size">
  <kbd>method</kbd> `page_size`
</h3>

```python theme={"system"}
page_size(page_size: 'int') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L712" />

<h3 id="method-pin_column_left">
  <kbd>method</kbd> `pin_column_left`
</h3>

```python theme={"system"}
pin_column_left(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L722" />

<h3 id="method-pin_column_right">
  <kbd>method</kbd> `pin_column_right`
</h3>

```python theme={"system"}
pin_column_right(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L684" />

<h3 id="method-remove_column">
  <kbd>method</kbd> `remove_column`
</h3>

```python theme={"system"}
remove_column(path: 'int | str | ObjectPath') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L703" />

<h3 id="method-remove_columns">
  <kbd>method</kbd> `remove_columns`
</h3>

```python theme={"system"}
remove_columns(*columns: 'str') → SavedView
```

保存済みビューから列を削除します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L548" />

<h3 id="method-remove_filter">
  <kbd>method</kbd> `remove_filter`
</h3>

```python theme={"system"}
remove_filter(index_or_field: 'int | str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L563" />

<h3 id="method-remove_filters">
  <kbd>method</kbd> `remove_filters`
</h3>

```python theme={"system"}
remove_filters() → SavedView
```

保存済みビューからすべてのフィルターを削除します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L521" />

<h3 id="method-rename">
  <kbd>method</kbd> `rename`
</h3>

```python theme={"system"}
rename(label: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L678" />

<h3 id="method-rename_column">
  <kbd>method</kbd> `rename_column`
</h3>

```python theme={"system"}
rename_column(path: 'int | str | ObjectPath', label: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L834" />

<h3 id="method-save-3">
  <kbd>method</kbd> `save`
</h3>

```python theme={"system"}
save() → SavedView
```

保存済みビューをサーバーにパブリッシュします。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L658" />

<h3 id="method-set_columns">
  <kbd>method</kbd> `set_columns`
</h3>

```python theme={"system"}
set_columns(*columns: 'str') → SavedView
```

グリッドに表示する列を設定します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L612" />

<h3 id="method-show_column">
  <kbd>method</kbd> `show_column`
</h3>

```python theme={"system"}
show_column(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L606" />

<h3 id="method-sort_by">
  <kbd>method</kbd> `sort_by`
</h3>

```python theme={"system"}
sort_by(field: 'str', direction: 'SortDirection') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L890" />

<h3 id="method-to_grid">
  <kbd>method</kbd> `to_grid`
</h3>

```python theme={"system"}
to_grid(limit: 'int | None' = None) → Grid
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L771" />

<h3 id="method-to_rich_table_str">
  <kbd>method</kbd> `to_rich_table_str`
</h3>

```python theme={"system"}
to_rich_table_str() → str
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L754" />

<h3 id="method-ui_url">
  <kbd>method</kbd> `ui_url`
</h3>

```python theme={"system"}
ui_url() → str | None
```

この保存済みビューを UI で表示するための URL です。

これはトレースなどが表示される「結果」ページの URL であり、ビューオブジェクト自体の URL ではない点に注意してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/saved_view.py#L732" />

<h3 id="method-unpin_column">
  <kbd>method</kbd> `unpin_column`
</h3>

```python theme={"system"}
unpin_column(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/scorer.py#L30" />

<h2 id="class-scorer">
  <kbd>クラス</kbd> `Scorer`
</h2>

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `column_map`: `dict[str, str] | None`

***

<h4 id="property-display_name">
  <kbd>property</kbd> display\_name
</h4>

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/scorer.py#L57" />

<h3 id="classmethod-from_obj-7">
  <kbd>クラスメソッド</kbd> `from_obj`
</h3>

```python theme={"system"}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/flow/scorer.py#L36" />

<h3 id="method-model_post_init-6">
  <kbd>method</kbd> `model_post_init`
</h3>

```python theme={"system"}
model_post_init(context: Any) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L49" />

<h3 id="method-score">
  <kbd>method</kbd> `score`
</h3>

```python theme={"system"}
score(output: Any, **kwargs: Any) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L53" />

<h3 id="method-summarize-2">
  <kbd>method</kbd> `summarize`
</h3>

```python theme={"system"}
summarize(score_rows: list) → dict | None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/_deprecated.py#L119" />

<h2 id="class-session">
  <kbd>class</kbd> `Session`
</h2>

:class:`weave.Conversation` の非推奨のエイリアスです。

従来の `session_id` / `session_name` コンストラクターフィールドを受け入れるほか、これらを `conversation_id` / `conversation_name` にプロキシする読み書き可能なプロパティとしても公開します。元の `Session` ではこれらがモデルフィールドとして定義されていたため、`s.session_id` の読み取りや代入を行う既存のコードもそのまま動作します。

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/_deprecated.py#L129" />

<h3 id="method-__init__-10">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(**data: 'Any') → None
```

**Pydantic のフィールド:**

* `conversation_id`: `<class 'str'>`
* `conversation_name`: `<class 'str'>`
* `agent_name`: `<class 'str'>`
* `model`: `<class 'str'>`
* `agent_id`: `<class 'str'>`
* `agent_description`: `<class 'str'>`
* `agent_version`: `<class 'str'>`
* `include_content`: `<class 'bool'>`
* `continue_parent_trace`: `<class 'bool'>`
* `attributes`: `dict[str, typing.Any]`

<h4 id="property-session_id">
  <kbd>property</kbd> session\_id
</h4>

:attr:`conversation_id` の非推奨のエイリアスです。

***

<h4 id="property-session_name">
  <kbd>property</kbd> session\_name
</h4>

:attr:`conversation_name` の非推奨のエイリアスです。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L88" />

<h2 id="class-stringprompt">
  <kbd>class</kbd> `StringPrompt`
</h2>

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L92" />

<h3 id="method-__init__-11">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(content: str)
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `content`: `<class 'str'>`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L96" />

<h3 id="method-format-4">
  <kbd>method</kbd> `format`
</h3>

```python theme={"system"}
format(**kwargs: Any) → str
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/prompt/prompt.py#L99" />

<h3 id="classmethod-from_obj-8">
  <kbd>クラスメソッド</kbd> `from_obj`
</h3>

```python theme={"system"}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L732" />

<h2 id="class-subagent">
  <kbd>class</kbd> `SubAgent`
</h2>

ターン内で委譲されたエージェントの invocation です。

同じトレース内でネストされた invoke\_agent OTel スパンに対応します。

**Pydantic のフィールド:**

* `name`: `<class 'str'>`
* `model`: `<class 'str'>`
* `agent_id`: `<class 'str'>`
* `agent_description`: `<class 'str'>`
* `agent_version`: `<class 'str'>`
* `system_instructions`: `list[str]`
* `started_at`: `datetime.datetime | None`
* `ended_at`: `datetime.datetime | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/typing_extensions.py#L257" />

<h3 id="method-add_event-2">
  <kbd>method</kbd> `add_event`
</h3>

```python theme={"system"}
add_event(
    name: 'str',
    attributes: 'dict[str, Any] | None' = None,
    timestamp: 'datetime | None' = None
) → Self
```

このスパン内の特定の時点で OTel スパンイベントを記録します。

.. deprecated:
\`\`\`      このデータは `set_attributes` で記録してください。OpenTelemetry は      Span Event API (`Span.add_event`) を段階的に廃止しています。      `add_event` は現在も動作し、既存のスパンイベントデータも引き続き有効です。      詳しくは [https://opentelemetry.io/blog/2026/deprecating-span-events/](https://opentelemetry.io/blog/2026/deprecating-span-events/) を参照してください。

````
マーカーやライフサイクルに関するデータに使用します。対象となるのは、許可プロンプト（例: ``weave.permission_request``）、ライフサイクルの遷移（例: ``spawned`` / ``streaming`` / ``finished``）、そのほかスパンの有効期間中の特定の時点で発生する任意のカスタムマイルストーンです（これに対して属性は、スパン全体に関するプロパティです）。 

スパンの開始から終了までの間（``with`` ブロック内）で呼び出す必要があります。この範囲外で呼び出した場合は no-op となり、警告がログされます。 

---

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L843" />

### <kbd>method</kbd> `end`

```python
end() → None
````

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L749" />

<h3 id="method-llm">
  <kbd>method</kbd> `llm`
</h3>

```python theme={"system"}
llm(
    model: 'str' = '',
    provider_name: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → LLM
```

このサブエージェント内で LLM Call を開始します。

`_current_llm` contextvar を設定するため、コンテキストマネージャーを使用するかどうかにかかわらず、`get_current_llm()` から LLM を参照できます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L773" />

<h3 id="method-record-2">
  <kbd>method</kbd> `record`
</h3>

```python theme={"system"}
record(
    name: 'str | None' = None,
    model: 'str | None' = None,
    system_instructions: 'list[str] | None' = None,
    agent_id: 'str | None' = None,
    agent_description: 'str | None' = None,
    agent_version: 'str | None' = None
) → SubAgent
```

サブエージェントの複数のフィールドを 1 回の呼び出しで設定します。

手動でインストルメントされたエージェントでは、サブエージェントに対してフィールドごとに代入 (`system_instructions`、`agent_id` など) を行いますが、このメソッドではそれらを 1 回のキーワード引数付き呼び出しにまとめられます。明示的に渡されたフィールド (`None` 以外) のみが適用され、既存の値は保持されます。メソッドチェーン用に `self` を返します。`Turn.record` / `LLM.record` と同様の動作です。

注: ストリーミング (`with`) パスでは、サブエージェントのスパン名は `__enter__` 時点の `name` から決まります。そのため、スパン名に `name` を反映させる必要がある場合は、`record` ではなく `start_subagent` / `turn.subagent` で `name` を設定してください。なお、`record` でも `gen_ai.agent.name` 属性は更新されます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L241" />

<h3 id="method-set_attributes-2">
  <kbd>method</kbd> `set_attributes`
</h3>

```python theme={"system"}
set_attributes(attributes: 'dict[str, Any]') → Self
```

このスパンに任意の OTel 属性を設定します。

キーが 1 つでも複数でも dict を渡します。キーが 1 つの場合は `span.set_attributes({"weave.tag": "value"})` のように呼び出します。OTel の `Span.set_attributes` と同じ仕様です。

スパンの開始から終了までの間、つまり `with` ブロック内で呼び出す必要があります。それ以外のタイミングで呼び出した場合は no-op となり、警告がログされます。バッチ取り込みの場合は、オブジェクトで宣言されたフィールドに直接値を設定し、`log_turn` / `log_conversation` に渡してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L769" />

<h3 id="method-tool">
  <kbd>method</kbd> `tool`
</h3>

```python theme={"system"}
tool(name: 'str', arguments: 'str' = '', tool_call_id: 'str' = '') → Tool
```

このサブエージェント内でツール実行を開始します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/table.py#L9" />

<h2 id="class-table">
  <kbd>クラス</kbd> `Table`
</h2>

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/table.py#L12" />

<h3 id="method-__init__-12">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(rows: 'list[dict]') → None
```

***

<h4 id="property-rows">
  <kbd>property</kbd> rows
</h4>

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/table.py#L50" />

<h3 id="method-append-2">
  <kbd>method</kbd> `append`
</h3>

```python theme={"system"}
append(row: 'dict') → None
```

表に行を追加します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/table.py#L56" />

<h3 id="method-pop">
  <kbd>method</kbd> `pop`
</h3>

```python theme={"system"}
pop(index: 'int') → None
```

指定したインデックスの行を表から削除します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/util.py#L105" />

<h2 id="class-contextawarethread">
  <kbd>class</kbd> `ContextAwareThread`
</h2>

呼び出し元のコンテキストで関数を実行するスレッドです。

これは threading.Thread のドロップイン置換で、スレッド内でも Call が期待どおりに動作するようにします。Weave では特定の contextvar が設定されている必要があります (call\_context.py を参照) 。しかし、新しいスレッドは親スレッドのコンテキストを自動的にコピーしないため、Call のコンテキストが失われるおそれがあります。これは望ましくありません。このクラスは contextvar のコピーを自動で行うため、このスレッドを使用すれば、ユーザーが想定するとおりに「そのまま動作」します。

このクラスを使用しなくても、代わりに次のように記述すれば同じ効果が得られます。

```python theme={"system"}
def run_with_context(func, *args, **kwargs):
     context = copy_context()
     def wrapper():
         context.run(func, *args, **kwargs)
     return wrapper

thread = threading.Thread(target=run_with_context(your_func, *args, **kwargs))
thread.start()
```

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/util.py#L129" />

<h3 id="method-__init__-13">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(*args: 'Any', **kwargs: 'Any') → None
```

***

<h4 id="property-daemon">
  <kbd>property</kbd> daemon
</h4>

このスレッドがデーモンスレッドかどうかを示す真偽値です。

この値は start() を呼び出す前に設定する必要があります。呼び出し後に設定すると RuntimeError が発生します。初期値は作成元のスレッドから継承されます。メインスレッドはデーモンスレッドではないため、メインスレッドで作成されたスレッドはすべてデフォルトで daemon = False になります。

デーモンスレッドだけが残ると、Python プログラム全体が終了します。

***

<h4 id="property-ident">
  <kbd>property</kbd> ident
</h4>

このスレッドのスレッド識別子です。スレッドがまだ開始されていない場合は None です。

これは 0 以外の整数です。get\_ident() 関数を参照してください。スレッドが終了した後に別のスレッドが作成されると、スレッド識別子が再利用されることがあります。識別子はスレッドの終了後も引き続き利用できます。

***

<h4 id="property-name">
  <kbd>property</kbd> name
</h4>

識別の目的にのみ使用される string です。

特別な意味は持ちません。複数のスレッドに同じ名前を付けることもできます。初期名はコンストラクターで設定されます。

***

<h4 id="property-native_id">
  <kbd>property</kbd> native\_id
</h4>

このスレッドのネイティブな整数スレッド ID です。スレッドがまだ開始されていない場合は None になります。

この値は非負の整数です。get\_native\_id() 関数も参照してください。これは、カーネルから報告されるスレッド ID を表します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/util.py#L133" />

<h3 id="method-run-2">
  <kbd>method</kbd> `run`
</h3>

```python theme={"system"}
run() → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L535" />

<h2 id="class-threadcontext">
  <kbd>class</kbd> `ThreadContext`
</h2>

現在のスレッドとターンの情報にアクセスするためのコンテキストオブジェクトです。

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L538" />

<h3 id="method-__init__-14">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(thread_id: 'str | None')
```

指定された thread\_id で ThreadContext を初期化します。

**引数:**

***

<h4 id="property-thread_id">
  <kbd>property</kbd> thread\_id
</h4>

このコンテキストの thread\_id を取得します。

* <b>`thread_id`</b>: このコンテキストのスレッド識別子。無効な場合は None。
  **戻り値:**
  スレッド識別子。スレッドのトラッキングが無効な場合は None。

***

<h4 id="property-turn_id">
  <kbd>property</kbd> turn\_id
</h4>

アクティブなコンテキストから現在の turn\_id を取得します。

**戻り値:**
turn\_id が設定されている場合は現在の turn\_id、設定されていない場合は None。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/util.py#L45" />

<h2 id="class-contextawarethreadpoolexecutor">
  <kbd>class</kbd> `ContextAwareThreadPoolExecutor`
</h2>

呼び出し元のコンテキストで関数を実行する ThreadPoolExecutor です。

これは concurrent.futures.ThreadPoolExecutor のドロップイン置換であり、executor 内でも Weave の Call が期待どおりに動作するようにします。Weave では特定の contextvar が設定されている必要があります (call\_context.py を参照) 。しかし、新しいスレッドは親スレッドのコンテキストを自動的にはコピーしないため、Call のコンテキストが失われてしまうことがあり、望ましくありません。このクラスは contextvar のコピーを自動化するため、この executor を使用すれば、ユーザーが期待するとおりに "そのまま動作" します。

このクラスを使用しなくても、次のように記述すれば同じ効果が得られます。

```python theme={"system"}
with concurrent.futures.ThreadPoolExecutor() as executor:
     contexts = [copy_context() for _ in range(len(vals))]

     def _wrapped_fn(*args):
         return contexts.pop().run(fn, *args)

     executor.map(_wrapped_fn, vals)
```

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/util.py#L68" />

<h3 id="method-__init__-15">
  <kbd>method</kbd> `__init__`
</h3>

```python theme={"system"}
__init__(*args: 'Any', **kwargs: 'Any') → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/util.py#L77" />

<h3 id="method-map">
  <kbd>method</kbd> `map`
</h3>

```python theme={"system"}
map(
    fn: 'Callable',
    *iterables: 'Iterable[Any]',
    timeout: 'float | None' = None,
    chunksize: 'int' = 1
) → Iterator
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/util.py#L73" />

<h3 id="method-submit">
  <kbd>method</kbd> `submit`
</h3>

```python theme={"system"}
submit(fn: 'Callable', *args: 'Any', **kwargs: 'Any') → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L326" />

<h2 id="class-tool">
  <kbd>class</kbd> `Tool`
</h2>

1 回のツール実行を表します。OTel の execute\_tool スパンに対応します。

`arguments` と `result` には `JSONString` アノテーションが使用されています。呼び出し側は dict / list / スカラー値を代入でき、SDK が構築時または代入時に JSON エンコードします。格納される値は常に string となり、GenAI semconv で規定されたワイヤーフォーマットと一致します。

**Pydantic のフィールド:**

* `name`: `<class 'str'>`
* `arguments`: `<class 'str'>`
* `result`: `<class 'str'>`
* `tool_call_id`: `<class 'str'>`
* `tool_type`: `<class 'str'>`
* `tool_description`: `<class 'str'>`
* `tool_definitions`: `<class 'str'>`
* `duration_ms`: `<class 'int'>`
* `started_at`: `datetime.datetime | None`
* `ended_at`: `datetime.datetime | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/typing_extensions.py#L257" />

<h3 id="method-add_event-3">
  <kbd>method</kbd> `add_event`
</h3>

```python theme={"system"}
add_event(
    name: 'str',
    attributes: 'dict[str, Any] | None' = None,
    timestamp: 'datetime | None' = None
) → Self
```

このスパン内の特定の時点で OTel のスパンイベントを記録します。

.. deprecated:
\`\`\`      このデータは、代わりに `set_attributes` を使用して記録してください。OpenTelemetry は      Span Event API (`Span.add_event`) を段階的に廃止しています。      `add_event` は引き続き使用でき、既存のスパンイベントデータも引き続き有効です。      詳細については、[https://opentelemetry.io/blog/2026/deprecating-span-events/](https://opentelemetry.io/blog/2026/deprecating-span-events/) を参照してください。

````
マーカーやライフサイクルのデータに使用します。具体的には、権限確認プロンプト（例: ``weave.permission_request``）、ライフサイクルの遷移（例: ``spawned`` / ``streaming`` / ``finished``）など、スパンの有効期間内の特定の時点で発生する任意のカスタムマイルストーンが該当します（一方、属性はスパン全体に関わるプロパティです）。 

スパンの開始から終了までの間（``with`` ブロック内）に呼び出す必要があります。このウィンドウ外で呼び出すと no-op となり、警告がログされます。 

---

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L382" />

### <kbd>method</kbd> `end`

```python
end() → None
````

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L241" />

<h3 id="method-set_attributes-3">
  <kbd>method</kbd> `set_attributes`
</h3>

```python theme={"system"}
set_attributes(attributes: 'dict[str, Any]') → Self
```

このスパンに任意の OTel 属性を付与します。

キーが 1 つでも複数でも dict を渡します。キーが 1 つの場合は `span.set_attributes({"weave.tag": "value"})` のように呼び出します。OTel の `Span.set_attributes` と同じ仕様です。

スパンの開始から終了までの間、つまり `with` ブロック内で呼び出す必要があります。この範囲外で呼び出した場合は no-op となり、警告がログされます。バッチ取り込みを行う場合は、オブジェクトの宣言済みフィールドに直接値を設定し、`log_turn` / `log_conversation` に渡してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L882" />

<h2 id="class-turn">
  <kbd>class</kbd> `Turn`
</h2>

ユーザーとエージェント間の 1 回のやり取りです。invoke\_agent の OTel スパンに対応します。

デフォルトでは、各ターンは独自の OTel トレースを開始します (`continue_parent_trace=False`) 。そのため、Agents タブにはターンごとに 1 つのトレースが表示されます。外側のトレースがすでに実行中で、エージェントの invocation をその内側にネストしたい場合 (例: fastapi でインストルメントされたリクエスト内) は、Conversation (または Turn に直接) に `continue_parent_trace=True` を設定します。

**Pydantic のフィールド:**

* `agent_name`: `<class 'str'>`
* `model`: `<class 'str'>`
* `agent_id`: `<class 'str'>`
* `agent_description`: `<class 'str'>`
* `agent_version`: `<class 'str'>`
* `system_instructions`: `list[str]`
* `messages`: `list[conversation.types.Message]`
* `spans`: `list[conversation.conversation.LLM | conversation.conversation.Tool | conversation.conversation.SubAgent]`
* `continue_parent_trace`: `<class 'bool'>`
* `started_at`: `datetime.datetime | None`
* `ended_at`: `datetime.datetime | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/typing_extensions.py#L257" />

<h3 id="method-add_event-4">
  <kbd>method</kbd> `add_event`
</h3>

```python theme={"system"}
add_event(
    name: 'str',
    attributes: 'dict[str, Any] | None' = None,
    timestamp: 'datetime | None' = None
) → Self
```

このスパン内の特定の時点で、OTel スパンイベントを記録します。

.. deprecated:
\`\`\`      代わりに `set_attributes` を使用してこのデータを記録してください。OpenTelemetry は      Span Event API (`Span.add_event`) を段階的に廃止しています。      `add_event` は引き続き使用でき、既存のスパンイベントデータも有効なままです。      詳しくは [https://opentelemetry.io/blog/2026/deprecating-span-events/](https://opentelemetry.io/blog/2026/deprecating-span-events/) を参照してください。

````
マーカーやライフサイクルのデータに使用します。具体的には、権限確認プロンプト（例: ``weave.permission_request``）、ライフサイクルの遷移（例: ``spawned`` / ``streaming`` / ``finished``）、そのほかスパンの存続期間中の特定の時点で発生する任意のカスタムマイルストーンが該当します（一方、属性はスパン全体に関するプロパティです）。 

スパンの開始から終了までの間（``with`` ブロック内）に呼び出す必要があります。この範囲外で呼び出すと no-op となり、警告がログされます。 

---

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1033" />

### <kbd>method</kbd> `end`

```python
end() → None
````

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L916" />

<h3 id="method-llm-2">
  <kbd>method</kbd> `llm`
</h3>

```python theme={"system"}
llm(
    model: 'str' = '',
    provider_name: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → LLM
```

LLM Call (このターンの子となるチャットスパン) を開始します。

`_current_llm` contextvar を設定します。これにより、コンテキストマネージャーを使用するかどうかにかかわらず、`get_current_llm()` で LLM を参照できるようになります。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/pydantic/_internal/_model_construction.py#L907" />

<h3 id="method-model_post_init-7">
  <kbd>method</kbd> `model_post_init`
</h3>

```python theme={"system"}
model_post_init(context: 'Any') → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L954" />

<h3 id="method-record-3">
  <kbd>method</kbd> `record`
</h3>

```python theme={"system"}
record(
    messages: 'list[Message] | None' = None,
    system_instructions: 'list[str] | None' = None,
    agent_name: 'str | None' = None,
    model: 'str | None' = None,
    agent_id: 'str | None' = None,
    agent_description: 'str | None' = None,
    agent_version: 'str | None' = None
) → Turn
```

1 回の呼び出しで複数のターンフィールドをまとめて設定します。

手動でインストルメントされたエージェントでは、ターンに対してフィールドごとに代入 (`system_instructions`、`agent_id` など) を行う必要がありますが、このメソッドを使用すると、それらを 1 回のキーワード引数呼び出しにまとめられます。明示的に渡された (`None` 以外の) フィールドのみが適用され、既存の値は保持されます。`messages` はターンの既存のメッセージを**置き換えます** (メッセージを 1 件追加する `Turn.user(...)` とは異なります) 。メソッドチェーン用に `self` を返します。`LLM.record` と同様の動作です。

注: ストリーミング (`with`) パスでは、ターンのスパン名は `__enter__` の時点で `agent_name` に基づいて決まります。そのため、スパン名に `agent_name` を反映させる必要がある場合は、`record` ではなく `start_turn` で `agent_name` を設定してください。なお、`record` を使用した場合も `gen_ai.agent.name` 属性は更新されます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L241" />

<h3 id="method-set_attributes-4">
  <kbd>method</kbd> `set_attributes`
</h3>

```python theme={"system"}
set_attributes(attributes: 'dict[str, Any]') → Self
```

任意の OTel 属性をこのスパンに付与します。

キーが 1 つでも複数でも dict を渡してください。キーが 1 つの場合は `span.set_attributes({"weave.tag": "value"})` のように使用します。OTel の `Span.set_attributes` に準拠しています。

スパンの開始から終了までの間、つまり `with` ブロック内で呼び出す必要があります。この範囲外で呼び出すと no-op となり、警告がログされます。バッチ取り込みの場合は、オブジェクトで宣言されたフィールドに直接値を設定し、`log_turn` / `log_conversation` に渡してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L940" />

<h3 id="method-subagent">
  <kbd>method</kbd> `subagent`
</h3>

```python theme={"system"}
subagent(
    name: 'str',
    model: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → SubAgent
```

サブエージェントの invocation を開始します (同じトレース内にネストされた invoke\_agent スパン) 。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L936" />

<h3 id="method-tool-2">
  <kbd>method</kbd> `tool`
</h3>

```python theme={"system"}
tool(name: 'str', arguments: 'str' = '', tool_call_id: 'str' = '') → Tool
```

ツール実行を開始します (この turn の子となる execute\_tool スパン) 。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L911" />

<h3 id="method-user">
  <kbd>method</kbd> `user`
</h3>

```python theme={"system"}
user(content: 'str') → Turn
```

ターンの途中でユーザーメッセージを追加します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/types.py#L227" />

<h2 id="class-usage">
  <kbd>class</kbd> `Usage`
</h2>

LLM Call のトークン使用量です。

**Pydantic のフィールド:**

* `input_tokens`: `<class 'int'>`
* `output_tokens`: `<class 'int'>`
* `reasoning_tokens`: `<class 'int'>`
* `cache_creation_input_tokens`: `<class 'int'>`
* `cache_read_input_tokens`: `<class 'int'>`

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L270" />

<h3 id="function-add_tags">
  <kbd>関数</kbd> `add_tags`
</h3>

```python theme={"system"}
add_tags(obj_ref: 'ObjectRef | str', tags: 'list[str]') → None
```

オブジェクトのバージョンにタグを追加します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L1477" />

<h3 id="function-as_op">
  <kbd>関数</kbd> `as_op`
</h3>

```python theme={"system"}
as_op(fn: 'Callable[P, R]') → Op[P, R]
```

@weave.op でデコレートされた関数を受け取り、その Op を返します。

@weave.op でデコレートされた関数はすでに Op のインスタンスであるため、この関数は実行時には no-op になります。ただし、OpDef の属性に型安全にアクセスする必要がある場合は、型チェッカーを満たす目的でこの関数を使用できます。

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef (weave.publish() の戻り値) または weave /// URI 文字列を指定します。

* <b>`tags`</b>: 追加するタグ文字列のリスト。
  **引数:**

* <b>`fn`</b>: weave.op でデコレートされた関数。
  **戻り値:**
  関数の Op。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/../../../../weave/trace/api/attributes#L462" />

<h3 id="function-attributes">
  <kbd>function</kbd> `attributes`
</h3>

```python theme={"system"}
attributes(attributes: 'dict[str, Any]') → Iterator
```

Call に属性を設定するためのコンテキストマネージャーです。

**例:**

```python theme={"system"}
with weave.attributes({'env': 'production'}):
     print(my_function.call("World"))
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1317" />

<h3 id="function-end_conversation">
  <kbd>function</kbd> `end_conversation`
</h3>

```python theme={"system"}
end_conversation() → None
```

現在の会話 (contextvar から取得) を終了します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1331" />

<h3 id="function-end_llm">
  <kbd>function</kbd> `end_llm`
</h3>

```python theme={"system"}
end_llm() → None
```

現在の LLM Call (contextvar から取得) を終了します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/_deprecated.py#L107" />

<h3 id="function-end_session">
  <kbd>function</kbd> `end_session`
</h3>

```python theme={"system"}
end_session() → None
```

:func:`weave.end_conversation` の非推奨のエイリアスです。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1324" />

<h3 id="function-end_turn">
  <kbd>関数</kbd> `end_turn`
</h3>

```python theme={"system"}
end_turn() → None
```

現在のターン (contextvar から取得) を終了します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L612" />

<h3 id="function-finish">
  <kbd>function</kbd> `finish`
</h3>

```python theme={"system"}
finish() → None
```

Weave へのログを停止します。

finish を呼び出した後は、weave.op でデコレートされた関数の Call はログされなくなります。ログを再開するには、weave.init() を再度実行してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L436" />

<h3 id="function-get">
  <kbd>function</kbd> `get`
</h3>

```python theme={"system"}
get(uri: 'str | ObjectRef') → Any
```

URI からオブジェクトを取得するための便利な関数です。

Weave でログされたオブジェクトの多くは、Weave サーバーに自動的に登録されます。この関数を使用すると、それらのオブジェクトを URI で取得できます。

**引数:**

* <b>`uri`</b>: 完全修飾された weave ref URI。
  **戻り値:**
  オブジェクト。

**例:**

```python theme={"system"}
weave.init("weave_get_example")
dataset = weave.Dataset(rows=[{"a": 1, "b": 2}])
ref = weave.publish(dataset)

dataset2 = weave.get(ref)  # dataset と同じ内容です！
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L332" />

<h3 id="function-get_aliases">
  <kbd>関数</kbd> `get_aliases`
</h3>

```python theme={"system"}
get_aliases(obj_ref: 'ObjectRef | str') → list[str]
```

オブジェクトのバージョンのエイリアスを取得します。

**引数:**

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef または weave /// URI 文字列のいずれかを指定します。
  **戻り値:**
  エイリアスの strings のリスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L184" />

<h3 id="function-get_client">
  <kbd>function</kbd> `get_client`
</h3>

```python theme={"system"}
get_client() → WeaveClient | None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/context/call_context.py#L119" />

<h3 id="function-get_current_call">
  <kbd>function</kbd> `get_current_call`
</h3>

```python theme={"system"}
get_current_call() → Call | None
```

Op の内部から、現在実行中の Op の Call オブジェクトを取得します。

**戻り値:**
現在実行中の Op の Call オブジェクト。トラッキングが初期化されていない場合、またはこのメソッドが Op の外部で呼び出された場合は None。

**メモ:**

> 返された Call の `attributes` 辞書は、Call の開始後は不変になります。Call のメタデータを設定するには、Op を呼び出す前に :func:`weave.attributes` を使用してください。`summary` フィールドは Op の実行中に更新でき、Call の終了時に、算出されたサマリー情報とマージされます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1338" />

<h3 id="function-get_current_conversation">
  <kbd>function</kbd> `get_current_conversation`
</h3>

```python theme={"system"}
get_current_conversation() → Conversation | None
```

contextvar からアクティブな会話を返します。存在しない場合は None を返します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1348" />

<h3 id="function-get_current_llm">
  <kbd>function</kbd> `get_current_llm`
</h3>

```python theme={"system"}
get_current_llm() → LLM | None
```

contextvar から実行中の LLM Call を返します。存在しない場合は None を返します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/_deprecated.py#L113" />

<h3 id="function-get_current_session">
  <kbd>function</kbd> `get_current_session`
</h3>

```python theme={"system"}
get_current_session() → Conversation | None
```

:func:`weave.get_current_conversation` の非推奨のエイリアスです。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1343" />

<h3 id="function-get_current_turn">
  <kbd>function</kbd> `get_current_turn`
</h3>

```python theme={"system"}
get_current_turn() → Turn | None
```

contextvar からアクティブなターンを返します。存在しない場合は None を返します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L294" />

<h3 id="function-get_tags">
  <kbd>関数</kbd> `get_tags`
</h3>

```python theme={"system"}
get_tags(obj_ref: 'ObjectRef | str') → list[str]
```

オブジェクトのバージョンのタグを取得します。

**引数:**

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef または weave /// URI 文字列のいずれかを指定します。
  **戻り値:**
  タグの strings のリスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L346" />

<h3 id="function-get_tags_and_aliases">
  <kbd>関数</kbd> `get_tags_and_aliases`
</h3>

```python theme={"system"}
get_tags_and_aliases(obj_ref: 'ObjectRef | str') → tuple[list[str], list[str]]
```

1 回の呼び出しで、オブジェクトのバージョンのタグとエイリアスをまとめて取得します。

**引数:**

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef または weave /// URI 文字列を指定します。
  **戻り値:**
  (tags, aliases) のタプル。いずれも list of strings です。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L41" />

<h3 id="function-init">
  <kbd>function</kbd> `init`
</h3>

```python theme={"system"}
init(
    project_name: 'str',
    settings: 'UserSettings | dict[str, Any] | None' = None,
    autopatch_settings: 'AutopatchSettings | None' = None,
    postprocess_inputs: 'PostprocessInputsFunc | None' = None,
    postprocess_output: 'PostprocessOutputFunc | None' = None,
    attributes: 'dict[str, Any] | None' = None,
    global_postprocess_inputs: 'PostprocessInputsFunc | None' = None,
    global_postprocess_output: 'PostprocessOutputFunc | None' = None,
    global_attributes: 'dict[str, Any] | None' = None
) → WeaveClient
```

Weave のトラッキングを初期化し、wandb の project へのログを開始します。

ログはグローバルに初期化されるため、init の戻り値への参照を保持しておく必要はありません。

init を実行すると、それ以降に weave.op でデコレートされた関数を呼び出した Call は、指定した project にログされます。

**引数:**

NOTE: クライアントレベルの後処理は、各 op 固有の後処理の後に実行されます。順序は常に次のとおりです: 1. op 固有の後処理 2. クライアントレベルの後処理

* <b>`project_name`</b>: ログする先の Weights & Biases のチーム名と project 名です。チームを指定しない場合は、デフォルトの entity が使用されます。デフォルトの entity を確認または変更するには、W\&B Models ドキュメントの [User Settings](/ja/products/wandb/platform/app/settings-page/user-settings#default-team) を参照してください。
* <b>`settings`</b>: Weave クライアント全体の設定です。UserSettings インスタンス、または以下のキーを任意に含む dict (すべてオプション) を指定できます。すべての設定は、接頭辞 WEAVE\_ を付けた
  環境変数でも設定できます (例: WEAVE\_DISABLED=true) 。使用可能な設定: - `disabled` (bool): すべての関数のトレースを無効にします。デフォルト: `False` - `print_call_link`
  (bool): op の Weave UI へのリンクをターミナルに出力します。デフォルト: `True` - `log_level` (str): ログする情報のタイプを設定します (`DEBUG`、`INFO`、`WARNING`、`ERROR`、`CRITICAL`) 。デフォルト: `INFO` -
  `display_viewer` (str): Weave がコンソールでオブジェクトを表示する方法を制御します (`auto`、`rich`、`print`) 。デフォルト: `auto` - `capture_code` (bool): トレースされた op のコードを取得し、Weave プロジェクトに保存します。
  デフォルト: `True` - `implicitly_patch_integrations` (bool): サポートされるライブラリに自動でパッチを適用します。デフォルト: `True` - `redact_pii` (bool): すべてのトレースデータをスキャンしてメールアドレス、電話
  番号、クレジットカード番号などの機密情報を検出し、サーバーに送信する前にプレースホルダー値に置き換えます。presidio-analyzer パッケージと presidio-anonymizer パッケージが必要です。
* <b>`Default`</b>: `False` - `redact_pii_fields` (list\[str]): `redact_pii` が True の場合にマスクする PII エンティティのタイプを指定します。空の場合は、Presidio のデフォルトのセットを使用します。例:  \['EMAIL','PHONE\_NUMBER','CREDIT\_CARD','US\_SSN']。一覧については、次を参照してください:  [https://microsoft.github.io/presidio/supported\&#95;entities/](https://microsoft.github.io/presidio/supported\&#95;entities/)
* <b>`Default`</b>: `[]` - `redact_pii_exclude_fields` (list\[str]): 除外する PII エンティティのタイプ。デフォルト: `[]` - `capture_client_info` (bool): Python/SDK のバージョン情報を取得します。デフォルト: `True` -
  `capture_system_info` (bool): OS 情報を取得します。デフォルト: `True` - `client_parallelism` (int): バックグラウンド Op のワーカー数。デフォルト: `auto` - `use_server_cache` (bool): サーバー応答のローカル
  ディスク キャッシュを有効にします。 - `server_cache_size_limit` (int): キャッシュ サイズの上限 (バイト単位)。デフォルト: `1_000_000_000` - `server_cache_dir` (str): サーバー キャッシュのディレクトリ。デフォルト: `temporary` -
  `scorers_dir` (str): Scorer のモデル チェックポイントを保存するディレクトリ。デフォルト: `~/.cache/wandb/weave-scorers` - `max_calls_queue_size` (int): キューの最大サイズ (0 = 無制限)。デフォルト: `100_000` -
  `retry_max_interval` (float): 再試行の最大間隔 (秒)。デフォルト: `300` - `retry_max_attempts` (int): 再試行の最大回数。デフォルト: `3` - `enable_disk_fallback` (bool): 破棄された
  項目をディスクに書き込みます。デフォルト: `True` - `use_parallel_table_upload` (bool): 大きな表をチャンク単位で並列アップロードします。False の場合、表はより小さなチャンクに分けて順次アップロードされます。
* <b>`Default`</b>: `True` - `http_timeout` (float): HTTP リクエストの完了を待機する最大時間 (秒) です。接続時間、データ転送、サーバー側の処理時間が含まれます。ネットワークが低速な場合や、大きなペイロードを扱う場合は、この値を大きくしてください。
* <b>`Default`</b>: `30.0` - `use_stainless_server` (bool): Stainless で生成された HTTP クライアントを使用します。このクライアントでは、型安全性の向上、自動リトライ、エラー処理の改善が得られます。この機能は実験的なものであり、将来のバージョンでデフォルトになる可能性があります。
* <b>`Default`</b>: `False` - `use_calls_complete` (bool): 最適化された書き込みパスを使用します。このパスでは、Call の開始と終了のリクエストを別々に送信する代わりに、完了した Call のデータ (開始と終了) を 1 つのリクエストにまとめて送信します。これによりサーバーの負荷が軽減され、特に短時間で終了する Op のパフォーマンスが向上します。
* <b>`Default`</b>: `True` - `use_otel_v2`: (bool): OTel に対応したインテグレーションを、それぞれの OTel 版経由でルーティングします。
* <b>`Default`</b>: `True`
* <b>`autopatch_settings`</b>: (非推奨) autopatch インテグレーションの設定です。代わりに明示的なパッチ適用を使用してください。
* <b>`postprocess_inputs`</b>: このクライアントがトレースするすべての op の入力に適用される関数です。
* <b>`postprocess_output`</b>: このクライアントがトレースするすべての op の出力に適用される関数。
* <b>`attributes`</b>: このクライアントが生成するすべてのトレースに適用される属性の辞書。
  **戻り値:**
  Weave クライアント。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L409" />

<h3 id="function-link_prompt_to_registry">
  <kbd>関数</kbd> `link_prompt_to_registry`
</h3>

```python theme={"system"}
link_prompt_to_registry(
    prompt: 'LinkablePrompt',
    target_path: 'str',
    aliases: 'Sequence[str] | None' = None
) → LinkAssetToRegistryRes
```

パブリッシュ済みのプロンプトのバージョンを Registry にリンクします。

**引数:**

* <b>`prompt`</b>: パブリッシュ済みのプロンプト、`ObjectRef`、または完全修飾された weave ///... URI 文字列。

* <b>`target_path`</b>: Registry 内のリンク先パス。形式は `<registry_project>/<portfolio_name>` です (例:  `wandb-registry-prompts/my-prompt-collection`) 。

* <b>`aliases`</b>: 作成される Registry のバージョンに付与するエイリアス (オプション) 。
  **戻り値:**

* <b>`LinkAssetToRegistryRes`</b>:  registry-link エンドポイントから返された応答を解析したもの。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L370" />

<h3 id="function-list_aliases">
  <kbd>関数</kbd> `list_aliases`
</h3>

```python theme={"system"}
list_aliases() → list[str]
```

project 内の一意なエイリアスをすべて一覧表示します。

**戻り値:**
project 内のすべてのエイリアス strings をソートしたリスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L360" />

<h3 id="function-list_tags">
  <kbd>関数</kbd> `list_tags`
</h3>

```python theme={"system"}
list_tags() → list[str]
```

project 内の一意なタグをすべて一覧表示します。

**戻り値:**
project 内のすべてのタグ (strings) をソートしたリスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/log_call.py#L18" />

<h3 id="function-log_call">
  <kbd>関数</kbd> `log_call`
</h3>

```python theme={"system"}
log_call(
    op: 'str',
    inputs: 'dict[str, Any]',
    output: 'Any',
    parent: 'Call | None' = None,
    attributes: 'dict[str, Any] | None' = None,
    display_name: 'str | Callable[[Call], str] | None' = None,
    use_stack: 'bool' = True,
    exception: 'BaseException | None' = None
) → Call
```

デコレーターパターンを使用せずに、Call を Weave に直接ログします。

この関数は、Weave に操作をログするための命令型 API を提供します。実行済みの Call を後からログしたい場合や、デコレーターパターンがユースケースに適さない場合に便利です。

**引数:**

* <b>`op`</b> (str):  ログする操作の名前。Call の op\_name として使用されます。匿名の操作 (パブリッシュ済みの Op を参照しない strings) もサポートされています。
* <b>`inputs`</b> (dict\[str, Any]):  操作の入力パラメーターを格納する辞書。
* <b>`output`</b> (Any):  操作の出力または結果。
* <b>`parent`</b> (Call | None):  この Call のネスト先となる親 Call (オプション) 。指定しない場合、Call はルートレベルの Call になります (現在の Call コンテキストが存在する場合は、その配下にネストされます) 。デフォルトは None です。
* <b>`attributes`</b> (dict\[str, Any] | None):  Call に付与するメタデータ (オプション) 。Call の作成後は変更できません。デフォルトは None です。
* <b>`display_name`</b> (str | Callable\[\[Call], str] | None):  UI に表示する Call の表示名 (オプション) 。string、または Call を受け取って string を返す 呼び出し可能オブジェクト を指定できます。デフォルトは None です。
* <b>`use_stack`</b> (bool):  Call をランタイムスタックにプッシュするかどうか。True の場合、Call は Call コンテキストで利用可能になり、weave.require\_current\_call() でアクセスできます。False の場合、Call はログされますが、コールスタックには追加されません。デフォルトは True です。
* <b>`exception`</b> (BaseException | None):  操作が失敗した場合にログする例外 (オプション) 。デフォルトは None です。

**戻り値:**

* <b>`Call`</b>:  完全なトレース情報を含む、作成済みかつ終了済みの Call オブジェクト。

**サンプル:**
基本的な使用方法:

````python theme={"system"}
import weave
    >>> weave.init('my-project')
    >>> call = weave.log_call(
    ...     op="my_function",
    ...     inputs={"x": 5, "y": 10},
    ...     output=15
    ... )

    Logging with attributes and display name:
    >>> call = weave.log_call(
    ...     op="process_data",
    ...     inputs={"data": [1, 2, 3]},
    ...     output={"mean": 2.0},
    ...     attributes={"version": "1.0", "env": "prod"},
    ...     display_name="Data Processing"
    ... )

    Logging a failed operation:
    >>> try:
    ...     result = risky_operation()
    ... except Exception as e:
    ...     call = weave.log_call(
    ...         op="risky_operation",
    ...         inputs={},
    ...         output=None,
    ...         exception=e
    ...     )

    Nesting calls:
    >>> parent_call = weave.log_call("parent", {"input": 1}, 2)
    >>> child_call = weave.log_call(
    ...     "child",
    ...     {"input": 2},
    ...     4,
    ...     parent=parent_call
    ... )

    Logging without adding to call stack:
    >>> call = weave.log_call(
    ...     op="background_task",
    ...     inputs={"task_id": 123},
    ...     output="completed",
    ...     use_stack=False  # コールスタックにプッシュしない
    ... )

---

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1584" />

### <kbd>function</kbd> `log_conversation`

```python
log_conversation(
    turns: 'list[Turn]',
    conversation_id: 'str' = '',
    conversation_name: 'str' = '',
    agent_name: 'str' = '',
    model: 'str' = '',
    agent_id: 'str' = '',
    agent_description: 'str' = '',
    agent_version: 'str' = '',
    include_content: 'bool' = True,
    continue_parent_trace: 'bool' = False,
    attributes: 'Attributes' = None
) → LogResult
````

会話全体を命令的に出力します。

各 Turn の子要素は、その Turn の `.spans` 属性で指定します。`conversation_id` が空の場合は自動生成されます。デフォルトでは、ターンごとに個別の OTel トレースが作成されます。`agent_name` / `model` / `agent_id` / `agent_description` / `agent_version` は会話レベルのデフォルト値です。Turn 自身の値が優先され、Turn で値が空の場合にのみ会話の値で補完されます。会話の `continue_parent_trace` はすべてのターンに適用されます (ここでは、Turn ごとの `continue_parent_trace` は意図的に無視されます) 。

`attributes` は出力されるすべてのスパンに付与されます。semconv 以外のカスタムキーを使用してください。スパン自身の `gen_ai.*` / `weave.*` 属性と重複するキーはサポートされていません (どちらの値が優先されるかは処理経路によって異なります) 。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/_deprecated.py#L78" />

<h3 id="function-log_session">
  <kbd>function</kbd> `log_session`
</h3>

```python theme={"system"}
log_session(
    turns: 'list[Turn]',
    session_id: 'str' = '',
    session_name: 'str' = '',
    agent_name: 'str' = '',
    model: 'str' = '',
    include_content: 'bool' = True,
    continue_parent_trace: 'bool' = False,
    attributes: 'Attributes' = None
) → LogResult
```

:func:`weave.log_conversation` の非推奨のエイリアスです。

`session_id` / `session_name` は、それぞれ `conversation_id` / `conversation_name` に対応します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1518" />

<h3 id="function-log_turn">
  <kbd>function</kbd> `log_turn`
</h3>

```python theme={"system"}
log_turn(
    conversation_id: 'str',
    agent_name: 'str' = '',
    conversation_name: 'str' = '',
    model: 'str' = '',
    agent_id: 'str' = '',
    agent_description: 'str' = '',
    agent_version: 'str' = '',
    messages: 'list[Message] | None' = None,
    system_instructions: 'list[str] | None' = None,
    spans: 'list[LLM | Tool | SubAgent] | None' = None,
    started_at: 'datetime | None' = None,
    ended_at: 'datetime | None' = None,
    include_content: 'bool' = True,
    continue_parent_trace: 'bool' = False,
    attributes: 'Attributes' = None
) → LogResult
```

1 つのターンとその子スパンを命令的に OTel へ出力します。

コンテキストマネージャーを使用できない場合 (ステートレスなコンテナー、コールバック、キューワーカーなど) に使用します。渡す各子スパンには `started_at` / `ended_at` を設定しておく必要があります。出力される OTel スパンのタイムスタンプは、これらのフィールドから取得されます。ターン自体にタイムスタンプが指定されていない場合は、子スパンの最も早い／最も遅いタイムスタンプにフォールバックし、それもない場合は `now()` を使用します。`agent_id` / `agent_description` / `agent_version` は、ストリーミングパスと同じように動作します。

`attributes` は、出力されるすべてのスパンに付与されます。ストリーミングパスでは、これらは代わりに実行中の会話から読み取られます。semconv に含まれないカスタムキーを使用してください。スパン自身の `gen_ai.*` / `weave.*` 属性と衝突するキーはサポートされていません (どちらの値が優先されるかはパスによって異なります) 。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/op.py#L1240" />

<h3 id="function-op">
  <kbd>function</kbd> `op`
</h3>

```python theme={"system"}
op(
    func: 'Callable[P, R] | None' = None,
    name: 'str | None' = None,
    call_display_name: 'str | CallDisplayNameFunc | None' = None,
    postprocess_inputs: 'PostprocessInputsFunc | None' = None,
    postprocess_output: 'PostprocessOutputFunc | None' = None,
    tracing_sample_rate: 'float' = 1.0,
    enable_code_capture: 'bool' = True,
    accumulator: 'Callable[[Any | None, Any], Any] | None' = None,
    kind: 'OpKind | None' = None,
    color: 'OpColor | None' = None,
    attributes: 'dict[str, Any] | None' = None,
    eager_call_start: 'bool' = False
) → Callable[[Callable[P, R]], Op[P, R]] | Op[P, R]
```

関数またはメソッドを Weave op に変換するデコレーターです。同期関数と非同期関数の両方に対応しています。イテレーター関数を自動的に検出し、それに応じた動作を適用します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/urls.py#L14" />

<h3 id="function-otel_traces_endpoint">
  <kbd>関数</kbd> `otel_traces_endpoint`
</h3>

```python theme={"system"}
otel_traces_endpoint(base_url: str | None = None) → str
```

Weave GenAI のトレース取り込み用の完全な OTLP HTTP エンドポイント URL を返します。

外部の呼び出し元 (たとえば、エクスポートを通知なく破棄することがある BatchSpanProcessor に処理を任せる前に、取り込みエンドポイントに到達可能かどうかを検証したい起動時のプローブなど) は、URL を手動で組み立てるのではなく、この関数を呼び出してください。パスは SDK が管理しており、変更される可能性があります。

* <b>`func`</b>: デコレートする関数。
* <b>`name`</b>: op のカスタム名。デフォルトは関数名です。
* <b>`call_display_name`</b>: Call の表示名。string または呼び出し可能オブジェクトを指定できます。
* <b>`postprocess_inputs`</b>: ログする前に入力を変換する関数。
* <b>`postprocess_output`</b>: ログする前に出力を変換する関数。
* <b>`tracing_sample_rate`</b>: トレースする Call の割合 (0.0 から 1.0) 。
* <b>`enable_code_capture`</b>: この op のソースコードを取得するかどうか。
* <b>`accumulator`</b>: ストリーミング op の結果を蓄積する関数。
* <b>`attributes`</b>: この op が作成するすべての Call に、最も低い優先順位でマージされるデフォルトの属性。キーが衝突した場合は、`weave.attributes()` コンテキストと明示的な Call ごとの属性がこれを上書きします。予約済みの "weave" キーはここでは設定できません。
* <b>`eager_call_start`</b>: True の場合、Call の開始はバッチ処理されずに即座に送信されます。評価のように、UI にすぐ表示する必要がある長時間実行の操作に便利です。
  **引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L188" />

<h3 id="function-publish">
  <kbd>function</kbd> `publish`
</h3>

```python theme={"system"}
publish(
    obj: 'Any',
    name: 'str | None' = None,
    tags: 'list[str] | None' = None,
    aliases: 'list[str] | None' = None
) → ObjectRef
```

Python オブジェクトを保存し、バージョン管理します。

同じ名前のオブジェクトがすでに存在し、そのコンテンツハッシュが当該オブジェクトの最新バージョンと一致しない場合、Weave はオブジェクトの新しいバージョンを作成します。

* <b>`base_url`</b>: トレースサーバーのベース URL。デフォルトは  `weave_trace_server_url()` です。
  **引数:**

* <b>`obj`</b>: 保存してバージョン管理するオブジェクト。

* <b>`name`</b>: オブジェクトの保存に使用する名前。

* <b>`tags`</b>: パブリッシュされたオブジェクトのバージョンに追加するタグのリスト (オプション)。

* <b>`aliases`</b>: パブリッシュされたオブジェクトのバージョンに設定するエイリアスのリスト (オプション)。
  **戻り値:**
  保存されたオブジェクトへの Weave Ref。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L380" />

<h3 id="function-ref">
  <kbd>function</kbd> `ref`
</h3>

```python theme={"system"}
ref(location: 'str') → ObjectRef
```

既存の Weave オブジェクトへの Ref を作成します。この関数はオブジェクトを直接取得するのではなく、そのオブジェクトを他の Weave API 関数に渡せるようにします。

**引数:**

* <b>`location`</b>: Weave Ref URI。`weave.init()` を呼び出し済みの場合は、`name:version` または `name` も指定できます。バージョンを指定しない場合は `latest` が使用されます。
  **戻り値:**
  オブジェクトへの Weave Ref。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L320" />

<h3 id="function-remove_aliases">
  <kbd>function</kbd> `remove_aliases`
</h3>

```python theme={"system"}
remove_aliases(obj_ref: 'ObjectRef | str', alias: 'str | list[str]') → None
```

オブジェクトから 1 つ以上のエイリアスを削除します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L282" />

<h3 id="function-remove_tags">
  <kbd>関数</kbd> `remove_tags`
</h3>

```python theme={"system"}
remove_tags(obj_ref: 'ObjectRef | str', tags: 'list[str]') → None
```

オブジェクトのバージョンからタグを削除します。

* <b>`obj_ref`</b>: オブジェクトへの参照。ObjectRef または weave /// URI 文字列を指定します。
* <b>`alias`</b>: 削除するエイリアス名、またはエイリアス名のリスト。
  **引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/context/call_context.py#L70" />

<h3 id="function-require_current_call">
  <kbd>関数</kbd> `require_current_call`
</h3>

```python theme={"system"}
require_current_call() → Call
```

現在実行中の Op 内から、その Op の Call オブジェクトを取得します。

これにより、Call の実行中に id やフィードバックなどの属性にアクセスできます。

```python theme={"system"}
@weave.op
def hello(name: str) -> None:
     print(f"Hello {name}!")
     current_call = weave.require_current_call()
     print(current_call.id)
```

Op の実行が完了した後に Call にアクセスすることもできます。

UI などで Call の id がわかっている場合は、`weave.init` から返される `WeaveClient` の `get_call` メソッドを使用して Call オブジェクトを取得できます。

```python theme={"system"}
client = weave.init("<project>")
mycall = client.get_call("<call_id>")
```

または、Op を定義した後に、その `call` メソッドを使用することもできます。例：

```python theme={"system"}
@weave.op
def add(a: int, b: int) -> int:
     return a + b

result, call = add.call(1, 2)
print(call.id)
```

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef または weave /// URI 文字列を指定します。
* <b>`tags`</b>: 削除するタグ (strings) のリスト。
  **戻り値:**
  現在実行中の Op の Call オブジェクト

**送出される例外:**

* <b>`NoCurrentCallError`</b>:  トラッキングが初期化されていない場合、またはこのメソッドが Op の外部で呼び出された場合。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L308" />

<h3 id="function-set_aliases">
  <kbd>function</kbd> `set_aliases`
</h3>

```python theme={"system"}
set_aliases(obj_ref: 'ObjectRef | str', alias: 'str | list[str]') → None
```

オブジェクトのバージョンに 1 つ以上のエイリアスを設定します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/trace/api.py#L482" />

<h3 id="function-set_view">
  <kbd>関数</kbd> `set_view`
</h3>

```python theme={"system"}
set_view(
    name: 'str',
    content: 'Content | str',
    extension: 'str | None' = None,
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None,
    encoding: 'str' = 'utf-8'
) → None
```

現在の Call のサマリーの `_weave.views.<name>` にカスタムビューを添付します。

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef または weave /// URI 文字列を指定します。

* <b>`alias`</b>: 設定するエイリアス名、またはエイリアス名のリスト (例: "production") 。
  **引数:**

* <b>`name`</b>: ビュー名 (`summary._weave.views` 配下のキー) 。

* <b>`content`</b>: `weave.Content` インスタンスまたは生の string。string の場合は、指定された extension または mimetype を使用して `Content.from_text` でラップされます。

* <b>`extension`</b>: `content` が string の場合に使用するファイル拡張子 (オプション) 。

* <b>`mimetype`</b>: `content` が string の場合に使用する MIME タイプ (オプション) 。

* <b>`metadata`</b>: テキストから `Content` を作成する際に添付するメタデータ (オプション) 。

* <b>`encoding`</b>: テキストから `Content` を作成する際に適用するテキストエンコーディング。
  **戻り値:**
  None

**サンプル:**
` import weave`

> > > weave.init("proj")
> > > @weave.op
> > > ... def foo():
> > > ...     weave.set\_view("readme", "# Hello", extension="md")
> > > ...     return 1
> > > foo()

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1198" />

<h3 id="function-start_conversation">
  <kbd>関数</kbd> `start_conversation`
</h3>

```python theme={"system"}
start_conversation(
    agent_name: 'str' = '',
    model: 'str' = '',
    conversation_id: 'str' = '',
    conversation_name: 'str' = '',
    include_content: 'bool' = True,
    continue_parent_trace: 'bool' = False,
    attributes: 'Attributes' = None
) → Conversation
```

会話を作成して有効化します。モジュールをまたいでアクセスできるように contextvar を設定します。

`attributes` は、この会話が出力するすべてのスパンに付与されます (例: `weave.integration.*` のようなインテグレーションのアイデンティティ) 。セマンティック規約に含まれないカスタムキーを使用してください。セマンティック規約のフィールドは、型付きの params (`conversation_name`、`model` など) で設定します。スパン自体の `gen_ai.*` / `weave.*` 属性と衝突するキーはサポートされていません。どちらの値が優先されるかは、処理経路 (ストリーミングか `log_turn` か) によって異なります。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1262" />

<h3 id="function-start_llm">
  <kbd>function</kbd> `start_llm`
</h3>

```python theme={"system"}
start_llm(
    model: 'str' = '',
    provider_name: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → LLM
```

LLM Call を作成して有効化します。現在のターンが存在する場合は、そのターンを使用します。

実行中のターンがない場合は、切り離された LLM (contextvar は設定されません) を返します。

`provider_name` は明示的に渡してください。SDK はモデル識別子からこの値を推測しません。接頭辞に基づいて推測すると、ユーザーのファインチューン (例: `text-...` という名前のモデル) のプロバイダーを誤って判定したり、将来のモデル名に関する前提をテレメトリに組み込んでしまったりするおそれがあり、後から修正するには大きなコストがかかります。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/_deprecated.py#L51" />

<h3 id="function-start_session">
  <kbd>function</kbd> `start_session`
</h3>

```python theme={"system"}
start_session(
    agent_name: 'str' = '',
    model: 'str' = '',
    session_id: 'str' = '',
    session_name: 'str' = '',
    include_content: 'bool' = True,
    continue_parent_trace: 'bool' = False,
    attributes: 'Attributes' = None
) → Conversation
```

:func:`weave.start_conversation` の非推奨のエイリアスです。

`session_id` / `session_name` は、それぞれ `conversation_id` / `conversation_name` に対応します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1302" />

<h3 id="function-start_subagent">
  <kbd>関数</kbd> `start_subagent`
</h3>

```python theme={"system"}
start_subagent(
    name: 'str',
    model: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → SubAgent
```

サブエージェントの invocation スパンを作成します。

SubAgent の OTel スパンは、OTel コンテキストで現在のスパン (通常は、実行中の Turn スパンがあればそのスパン) の子に自動的になります。構成は `start_tool` と同様です。親子関係の伝播は OTel コンテキストが処理するため、明示的な委譲は不要です。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1291" />

<h3 id="function-start_tool">
  <kbd>function</kbd> `start_tool`
</h3>

```python theme={"system"}
start_tool(name: 'str', arguments: 'str' = '', tool_call_id: 'str' = '') → Tool
```

ツール実行スパンを作成します。

Tool の OTel スパンは、OTel コンテキストで現在のスパンの子として自動的に作成されます。Turn スパンが実行中の場合は、通常その Turn スパンが親になります。ターンを明示的に委譲する必要はありません。親子関係は、Conversation SDK の contextvar ではなく、OTel コンテキストを介して伝播されます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/conversation/conversation.py#L1230" />

<h3 id="function-start_turn">
  <kbd>function</kbd> `start_turn`
</h3>

```python theme={"system"}
start_turn(
    user_message: 'str' = '',
    model: 'str' = '',
    agent_name: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → Turn
```

ターンを作成してアクティブにします。現在の会話がある場合は、その会話を使用します。

アクティブな会話がない場合は、contextvar に設定されていない、切り離された Turn を返します。この場合、`get_current_turn()` は None を返します。contextvar を利用してモジュールをまたいでアクセスする必要がある場合は、代わりに `conversation.start_turn()` を使用してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/../../../../weave/trace/api/thread#L565" />

<h3 id="function-thread">
  <kbd>function</kbd> `thread`
</h3>

```python theme={"system"}
thread(
    thread_id: 'str | object | None' = <object object at 0x7f136d9f4bd0>
) → Iterator[ThreadContext]
```

コンテキスト内の Call に thread\_id を設定するコンテキストマネージャーです。

**サンプル:**

```python theme={"system"}
# thread_id を自動生成
with weave.thread() as t:
     print(f"Thread ID: {t.thread_id}")
     result = my_function("input")  # この Call には自動生成された thread_id が設定されます
     print(f"Current turn: {t.turn_id}")

# thread_id を明示的に指定
with weave.thread("custom_thread") as t:
     result = my_function("input")  # この Call には thread_id="custom_thread" が設定されます

# スレッドの追跡を無効にする
with weave.thread(None) as t:
     result = my_function("input")  # この Call には thread_id=None が設定されます
```

**引数:**

* <b>`thread_id`</b>: このコンテキスト内の Call に関連付けるスレッド識別子。指定しない場合は、UUID v7 が自動生成されます。None を指定した場合、スレッドのトラッキングは無効になります。
  **生成される値:**

* <b>`ThreadContext`</b>:  thread\_id と現在の turn\_id にアクセスするためのオブジェクト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.53.1/weave/integrations/wandb/wandb.py#L9" />

<h3 id="function-wandb_init_hook">
  <kbd>関数</kbd> `wandb_init_hook`
</h3>

```python theme={"system"}
wandb_init_hook() → None
```


## Related topics

- [weave](/ja/products/wandb/weave/reference/typescript-sdk.md)
