Skip to content

Add Executor.stream() async generator and ModuleAnnotations.streaming #2

@tercel

Description

@tercel

Summary

Add optional stream() async generator to Executor and streaming: bool to ModuleAnnotations, enabling modules to produce incremental output.

Changes

ModuleAnnotations

  • Added streaming: bool = False to frozen dataclass

Executor.stream()

  • New async def stream(module_id, inputs?, context?) -> AsyncIterator[dict]
  • Steps 1-6 identical to call_async() (context, safety, lookup, ACL, validate, before-middleware)
  • Inline async-aware middleware dispatch (matches call_async() pattern with inspect.iscoroutinefunction)
  • If module has no stream(): falls back to _execute_async(), yields single chunk
  • If module has stream(): iterates it, yields each chunk, accumulates via {**accumulated, **chunk}
  • Output validation + after-middleware on accumulated result
  • Error recovery via _execute_on_error_async()

Tests (5 new)

  • Fallback single chunk, multiple chunks, ModuleNotFoundError
  • Before/after middleware ordering
  • Disjoint-key shallow merge accumulation

Files Changed

  • src/apcore/module.pystreaming field
  • src/apcore/executor.pystream() method
  • tests/test_executor_stream.py — 5 new tests

Test Results

957 tests pass, 0 failures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions