Skip to content

feat: add streaming responses to LLM provider interface #44

Closed

Description

@pavelanni

Summary

Add streaming support to the llm.Provider interface so LLM responses are delivered incrementally instead of waiting for the full response.

Motivation

DocsClaw currently uses synchronous CompleteWithTools() which blocks until the entire response is ready. For a business agent producing long-form output (document summaries, report analysis), this creates poor UX — the user stares at a blank screen for seconds.

Pi-mono streams all responses with typed events (text_delta, toolcall_delta, thinking_delta), enabling progressive rendering. Both Anthropic and OpenAI APIs support streaming natively.

Proposed design

New provider method

type StreamEvent struct {
    Type    string // "text_delta", "tool_call", "done", "error"
    Content string // text chunk or tool call JSON
}

type Provider interface {
    Complete(ctx context.Context, prompt string, systemPrompt string) (string, error)
    CompleteWithTools(ctx context.Context, messages []Message, tools []ToolDefinition) (*Response, error)
    StreamWithTools(ctx context.Context, messages []Message, tools []ToolDefinition) (<-chan StreamEvent, error)
}

Integration points

  • Chat TUI: Bubble Tea model subscribes to channel, renders text deltas incrementally
  • A2A server: stream responses using A2A streaming protocol (SSE)
  • Agentic loop (pkg/tools/loop.go): collect stream to final Response for tool extraction, but emit text deltas for observability

Implementation order

  1. Add StreamWithTools() to Anthropic provider (native SSE support)
  2. Add to OpenAI provider
  3. Update chat TUI to render incrementally
  4. Update agentic loop to use streaming internally

Related

Identified from analysis of pi-mono's AssistantMessageEventStream architecture.

Activity

  1. pavelanni commented on May 5, 2026

    @pavelanni
    CollaboratorAuthor

    Update: OpenAI-compatible API as integration point

    PR #55 added an OpenAI-compatible Chat Completions API (/v1/chat/completions) with SSE streaming. Currently it uses simulated streaming — the full response is obtained from the provider, then chunked word-by-word over SSE.

    With true provider-level streaming, the OpenAI endpoint becomes the fourth consumer:

    Updated integration points

    • Chat TUI: Bubble Tea model subscribes to stream, renders text deltas incrementally
    • A2A server: stream responses using A2A streaming protocol (SSE)
    • OpenAI-compatible API: pipe provider stream events directly into SSE chunks for real-time token delivery to Open WebUI and other clients
    • Agentic loop (pkg/tools/loop.go): collect stream to final Response for tool extraction, but emit text deltas for observability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions