SdkOutput (_sdk.py)

agents · ai

Shared helper for reading Claude Agent SDK message streams. Both the judge and Monte Carlo layers consume the same `query()` message stream (assistant text blocks + a terminal result message). This centralizes that walk so the two layers can't drift on how SDK message types are h

# Source: https://github.com/wshobson/agents | License: MIT | Copyright 2024 Seth Hobson
# Provided via justclaw.it.com; keep this notice with the code.
"""Shared helper for reading Claude Agent SDK message streams.

Both the judge and Monte Carlo layers consume the same `query()` message stream
(assistant text blocks + a terminal result message). This centralizes that
walk so the two layers can't drift on how SDK message types are handled.
"""

from __future__ import annotations

from typing import Any, NamedTuple


class SdkOutput(NamedTuple):
    """Extracted view of one SDK message stream."""

    text: str  # concatenated assistant TextBlock text
    result: str | None  # ResultMessage.result, if present (fallback text)
    errored: bool  # a ResultMessage reported is_error
    usage:

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key