WIP: Wiring context_new into agent — turn loop, StreamToken, dead code removal
Work in progress. New turn loop uses ResponseParser + StreamToken. Killed StreamEvent, append_streaming, finalize_streaming, streaming_index, assemble_api_messages, working_stack. Many methods still reference old types — fixing next. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
648356ae40
commit
9c79d7a037
4 changed files with 202 additions and 424 deletions
|
|
@ -50,28 +50,10 @@ fn tools_to_json_str(tools: &[agent_tools::Tool]) -> String {
|
|||
format!("[{}]", inner.join(","))
|
||||
}
|
||||
|
||||
/// Events produced by the streaming API backends.
|
||||
/// The runner reads these and decides what to display where.
|
||||
pub(crate) enum StreamEvent {
|
||||
/// Content token from the model's response.
|
||||
Content(String),
|
||||
/// Reasoning/thinking token (internal monologue).
|
||||
Reasoning(String),
|
||||
/// Incremental tool call delta (structured, from APIs that support it).
|
||||
ToolCallDelta {
|
||||
index: usize,
|
||||
id: Option<String>,
|
||||
call_type: Option<String>,
|
||||
name: Option<String>,
|
||||
arguments: Option<String>,
|
||||
},
|
||||
/// Token usage stats.
|
||||
Usage(Usage),
|
||||
/// Stream finished.
|
||||
Finished {
|
||||
reason: String,
|
||||
},
|
||||
/// Error from the stream.
|
||||
/// One token from the streaming completions API.
|
||||
pub(crate) enum StreamToken {
|
||||
Token { text: String, id: u32 },
|
||||
Done { usage: Option<Usage> },
|
||||
Error(String),
|
||||
}
|
||||
|
||||
|
|
@ -133,14 +115,14 @@ impl ApiClient {
|
|||
(rx, AbortOnDrop(handle))
|
||||
}
|
||||
|
||||
/// Start a streaming completion with raw token IDs.
|
||||
/// No message formatting — the caller provides the complete prompt as tokens.
|
||||
pub(crate) fn start_stream_completions(
|
||||
/// Stream a completion with raw token IDs.
|
||||
/// Returns (text, token_id) per token via channel.
|
||||
pub(crate) fn stream_completion(
|
||||
&self,
|
||||
prompt_tokens: &[u32],
|
||||
sampling: SamplingParams,
|
||||
priority: Option<i32>,
|
||||
) -> (mpsc::UnboundedReceiver<StreamEvent>, AbortOnDrop) {
|
||||
) -> (mpsc::UnboundedReceiver<StreamToken>, AbortOnDrop) {
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
let client = self.client.clone();
|
||||
let api_key = self.api_key.clone();
|
||||
|
|
@ -154,7 +136,7 @@ impl ApiClient {
|
|||
&prompt_tokens, &tx, sampling, priority,
|
||||
).await;
|
||||
if let Err(e) = result {
|
||||
let _ = tx.send(StreamEvent::Error(e.to_string()));
|
||||
let _ = tx.send(StreamToken::Error(e.to_string()));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue