Skip to content

Document what happens when a caller stops consuming an agent run early #61

Description

@shibayan

Motivation

A consumer that relays agent.run() over Server-Sent Events will see clients disconnect
routinely, so what a break out of for await — or an aborted signal — does has to be a
documented promise rather than an implementation detail. The behaviour is already implemented and
covered by tests; it is not written down anywhere a caller would look.

Measured behaviour

  1. Breaking out of the loop calls the iterator's return(), which closes the source and releases
    the provider SDK stream.
  2. The run's afterRun still runs, and the partial response is persisted. Structured-output
    parsing is skipped for an abandoned run, so break never raises.
  3. The invoke_agent span is ended, on both the abandon and the abort path.

An aborted run reports the failure to afterRun instead, and the default history provider stores
nothing for it.

The reference implementations disagree here

  • .NET disposes the inner enumerator but never reaches its provider notification, so nothing is
    persisted.
  • Go falls through to its Invoked calls after the consumer stops, persisting the partial
    response.
  • Python runs its cleanup hooks only on exhaustion or an exception, and exposes no close(), so a
    consumer that stops early has no supported way to finish the run at all.

This framework follows Go. Saying so explicitly makes it read as a decision rather than an
accident, and tells a caller which of the three behaviours to design against.

Scope

TSDoc on AgentRunStream and ResponseStream covering the three points above and the abort
variant. No behaviour change is expected — if writing it down turns up a case that does not hold,
that becomes a separate bug report with a failing test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreUsage: [Issues, PRs], Target: packages/coredocumentationUsage: [Issues, PRs], Target: documentation changes

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions