一键导入
streaming
JOB-253 — correct streaming pattern via stream() return value; removing streaming_func side-channel.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
JOB-253 — correct streaming pattern via stream() return value; removing streaming_func side-channel.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
AgentExecutor, ChatAgent (ReAct), OpenAIToolsAgent, and the Agent trait.
JOB-251 — Why Arc<dyn LLM> over LLMClone, migration pattern, and correct LLM ownership model.
All Chain types — LLMChain, ConversationalChain, SequentialChain, StuffDocuments, ConversationalRetrievalQA, SqlDatabaseChain.
Trait conformance tests, property-based tests (proptest), fuzz targets, and boundary contracts for langchainx traits.
Core langchainx patterns — LLMChain, builder pattern, Chain trait, prompt macros, and basic invocation.
Constructing LLM backends (OpenAI, Claude, DeepSeek, Qwen, Ollama) and configuring CallOptions.
| name | streaming |
| description | JOB-253 — correct streaming pattern via stream() return value; removing streaming_func side-channel. |
use futures::StreamExt;
use langchainx::{
chain::{Chain, LLMChainBuilder},
prompt_args,
};
let chain = LLMChainBuilder::new().llm(llm).prompt(prompt).build()?;
let mut stream = chain.stream(prompt_args! { "input" => "Write a poem" }).await?;
while let Some(chunk) = stream.next().await {
match chunk {
Ok(data) => print!("{}", data.content),
Err(e) => eprintln!("error: {e}"),
}
}
println!(); // final newline
## LLM-Level Streaming
use langchainx::language_models::llm::LLM;
use langchainx::schemas::Message;
let mut stream = llm.stream(&[Message::new_human_message("Hello")]).await?;
while let Some(chunk) = stream.next().await {
let data = chunk?;
if !data.content.is_empty() {
print!("{}", data.content);
}
}
## Anti-Pattern: streaming_func (JOB-253 — DO NOT USE)
// WRONG — streaming_func is a side-channel callback in CallOptions
// It will be removed in JOB-253. Do not use in new code.
let options = CallOptions::new()
.with_streaming_func(|chunk| async move {
print!("{chunk}");
Ok(())
});
let llm = OpenAI::default().with_options(options);
let result = llm.generate(&messages).await?; // side-effects in callback, result separate
Problems with streaming_func:
Arc<Mutex<FnMut>> contaminationpub struct StreamData {
pub value: Value, // raw JSON from the provider
pub tokens: Option<TokenUsage>,
pub content: String, // the text chunk — this is what you usually want
}