Skip to content

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.

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 <[email protected]>
@Phoenix500526 Phoenix500526 force-pushed the reexport/streaming-error branch from e5fa94c to 31bd411 Compare December 30, 2025 14:21
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.

1 participant