> ## 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.

# バッチでのログ記録

> log_turn と log_conversation を使用して、完了したターンや会話を後からまとめて出力します。

これらには `tracing` モジュールからアクセスします：

```python theme={"system"}
from coreweave.forge.agentlens import tracing
```

<h2 id="log_turn">
  log\_turn
</h2>

```python theme={"system"}
def log_turn(
    *,
    conversation_id: str,
    agent_name: str = '',
    conversation_name: str = '',
    model: str = '',
    agent_id: str = '',
    agent_description: str = '',
    agent_version: str = '',
    messages: Union[list[Message], None] = None,
    output_messages: Union[list[Message], None] = None,
    system_instructions: Union[list[str], None] = None,
    spans: Union[list[Union[LLM, Tool, SubAgent]], None] = None,
    started_at: Union[datetime, None] = None,
    ended_at: Union[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` は送信されるすべてのスパンに付与されます。ストリーミングパスでは、これらは
実行中の会話から読み取られます。セマンティック規約 に含まれない独自のキーを使用してください。
スパン自身の `gen_ai.*` / `weave.*` 属性と重複するキーはサポートされていません
(どちらの値が優先されるかはパスによって異なります)。

`messages` にはターンの入力が、`output_messages` にはエージェントの最終的な応答が記録されます。どちらも
同じ `invoke_agent` スパンに記録されます。

<h2 id="log_conversation">
  log\_conversation
</h2>

```python theme={"system"}
def 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 ごとの値よりも優先されます。

`attributes` は出力されるすべてのスパンに付与されます。セマンティック規約に含まれない独自の
キーを使用してください。スパン自身の `gen_ai.*` / `weave.*`
属性と衝突するキーはサポートされていません (どちらの値が優先されるかは処理経路によって異なります) 。

<h2 id="logresult">
  LogResult
</h2>

```python theme={"system"}
class LogResult(BaseModel): ...
```

log\_\* のバッチ呼び出しの結果です。

`LogResult` は Pydantic モデルです。インスタンスを構築する際に、以下の各フィールドをキーワード引数として指定できます。

**フィールド**

| フィールド | タイプ | デフォルト |
| - | - | - |
| `conversation_id` | `str` | `''` |
| `trace_ids` | `list[str]` | `[]` |
| `root_span_ids` | `list[str]` | `[]` |
| `span_count` | `int` | `0` |
