Skip to content

feat(agent): export StreamingError to public API#1200

Merged
joshua-mo-143 merged 1 commit into0xPlaygrounds:mainfrom
Phoenix500526:reexport/streaming-error
Jan 5, 2026
Merged

feat(agent): export StreamingError to public API#1200
joshua-mo-143 merged 1 commit into0xPlaygrounds:mainfrom
Phoenix500526:reexport/streaming-error

Conversation

@Phoenix500526
Copy link
Contributor

@Phoenix500526 Phoenix500526 commented Dec 30, 2025

Export StreamingError from the rig::agent module to enable proper error handling in multi-provider abstractions.

Motivation

When building applications that support multiple LLM providers, a common pattern is to create an enum wrapper to abstract over different model types:

  pub enum AgentBuilder {
      Anthropic(agent::AgentBuilder<anthropic::completion::CompletionModel>),
      OpenAI(agent::AgentBuilder<openai::completion::CompletionModel>),
      Gemini(agent::AgentBuilder<gemini::completion::CompletionModel>),
      OpenRouter(agent::AgentBuilder<openai::completion::CompletionModel>),
  }

To unify error handling across these providers, users need to define their own error types and implement conversions from the underlying errors:

  pub enum MyStreamingError {
      Streaming(StreamingError),
      // ...
  }

  impl From<StreamingError> for MyStreamingError {
      fn from(e: StreamingError) -> Self {
          MyStreamingError::Streaming(e)
      }
  }

However, StreamingError was not re-exported from the agent module, making this pattern impossible.

The Problem

StreamingResult is defined as:

  pub type StreamingResult<R> =
      Pin<Box<dyn Stream<Item = Result<MultiTurnStreamItem<R>, StreamingError>> + Send>>;
  • MultiTurnStreamItem — exported, users can pattern match on Ok variants
  • StreamingError — not exported, users cannot pattern match on Err variants

This inconsistency prevents users from implementing fine-grained error handling or building provider-agnostic abstractions.

Closes: #1208

StreamingError was not re-exported despite being the error type in
StreamingResult. This prevented users from pattern matching on
error variants or implementing From<StreamingError> for custom
error types when building multi-provider abstractions.

Signed-off-by: Jiawei Zhao <Phoenix500526@163.com>
@Phoenix500526 Phoenix500526 force-pushed the reexport/streaming-error branch from e5fa94c to 31bd411 Compare December 30, 2025 14:21
Copy link
Collaborator

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

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

lgtm, thank you for opening this PR!

@joshua-mo-143 joshua-mo-143 linked an issue Jan 5, 2026 that may be closed by this pull request
1 task
@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Jan 5, 2026
Merged via the queue into 0xPlaygrounds:main with commit c6d7ca0 Jan 5, 2026
5 checks passed
@github-actions github-actions bot mentioned this pull request Dec 19, 2025
ThomasMarches pushed a commit to ThomasMarches/rig that referenced this pull request Feb 13, 2026
StreamingError was not re-exported despite being the error type in
StreamingResult. This prevented users from pattern matching on
error variants or implementing From<StreamingError> for custom
error types when building multi-provider abstractions.

Signed-off-by: Jiawei Zhao <Phoenix500526@163.com>
@Phoenix500526 Phoenix500526 deleted the reexport/streaming-error branch February 25, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: export StreamingError in public API for structured streaming error handling feat: export StreamingError

2 participants