Skip to content

feat(py): stream typed chunks - #6013

Draft
huangjeff5 wants to merge 1 commit into
mainfrom
jh-fix-streaming-chunks
Draft

feat(py): stream typed chunks#6013
huangjeff5 wants to merge 1 commit into
mainfrom
jh-fix-streaming-chunks

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Experimental. Currently we stream untyped chunks (the content comes through as a dict rather than a validated model). Exploring parsing intermediate chunks into partials.

@huangjeff5 huangjeff5 changed the title fix(py): stream typed chunks feat(py): stream typed chunks Aug 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces typed streaming output support by enabling partial validation of accumulated streaming chunks against a Pydantic schema type. It updates ModelResponseChunk to handle partial validation, makes ActionRunContext generic over the chunk type, and refines type annotations across the codebase. Additionally, comprehensive tests are added to verify the partial validation behavior. The reviewer feedback suggests using getattr defensively when accessing schema_type on raw_request.output to prevent potential AttributeError exceptions.

chunks = ChunkAccumulator(
message_index,
formatter,
schema_type=raw_request.output.schema_type if raw_request.output else None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Accessing raw_request.output.schema_type directly can raise an AttributeError if schema_type is not a predefined field on GenerateActionOutputConfig (for example, when output_schema is None or a raw dictionary, and schema_type is never dynamically set).

Using getattr provides a safer, more defensive approach to avoid potential runtime crashes.

Suggested change
schema_type=raw_request.output.schema_type if raw_request.output else None,
schema_type=getattr(raw_request.output, 'schema_type', None) if raw_request.output else None,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant