Summary
chat_with_tools() is currently non-streaming. The entire model response must complete before tool calls are parsed and dispatched. For long-running model reasoning, the user sees no output until completion.
Claude API supports streaming with tool_use (SSE content_block_start with type: tool_use). OpenAI also supports streaming function calls.
Proposed Approach
New trait method
fn chat_with_tools_stream(
&self,
messages: Vec<Message>,
tools: Vec<ToolDefinition>,
options: &ChatOptions,
) -> Pin<Box<dyn Stream<Item = Result<ChatStreamEvent>> + Send + '_>>;
ChatStreamEvent enum (new)
pub enum ChatStreamEvent {
TextChunk(String),
ToolCallStart { id: String, tool_id: String },
ToolCallDelta { id: String, input_delta: String },
ToolCallEnd { id: String },
}
Agent loop changes
- Process stream events in real-time
- Display
TextChunk events immediately to the channel
- Accumulate
ToolCall* events into complete tool calls
- After stream ends, dispatch accumulated tool calls
Acceptance Criteria
Trade-offs
- (+) Much better UX — user sees model "thinking" text before tool calls
- (-) Significant implementation complexity (different SSE formats per provider)
- (-) Ollama tool streaming may not be supported by
ollama_rs
- (-) Increases test surface substantially
Status
Deferred to post-1.0. Implement only after Phases 1-3 are stable and if UX feedback demands it.
References
Summary
chat_with_tools()is currently non-streaming. The entire model response must complete before tool calls are parsed and dispatched. For long-running model reasoning, the user sees no output until completion.Claude API supports streaming with tool_use (SSE
content_block_startwithtype: tool_use). OpenAI also supports streaming function calls.Proposed Approach
New trait method
ChatStreamEventenum (new)Agent loop changes
TextChunkevents immediately to the channelToolCall*events into complete tool callsAcceptance Criteria
Trade-offs
ollama_rsStatus
Deferred to post-1.0. Implement only after Phases 1-3 are stable and if UX feedback demands it.
References
.local/plan/native-tools-improvement.md(Phase 4)