pub struct ToolCallContext {
pub call_id: ToolCallId,
pub cancellation: CancellationToken,
pub extra: Value,
}Expand description
工具执行上下文 — Agent loop 构造后传入 Tool::execute。
§Builder 模式
必填字段通过 new(call_id) 提供,可选字段通过 with_* 链式设置。
§Examples
use katu_core::{ToolCallContext, ToolCallId, CancellationToken};
use serde_json::json;
let token = CancellationToken::new();
let ctx = ToolCallContext::new(ToolCallId::new("call_1"))
.with_cancellation(token.clone())
.with_extra(json!({"cwd": "/home/user/project"}));
assert_eq!(ctx.call_id.as_str(), "call_1");
assert!(!ctx.cancellation.is_cancelled());Fields§
§call_id: ToolCallId本次 tool_call 的唯一标识(由 LLM 或 agent loop 分配)。
cancellation: CancellationToken取消令牌 — 工具在长循环中检查是否需要提前退出。
extra: Value扩展数据 — 上层应用注入的额外上下文。
如当前工作目录、环境变量、session 信息等。 基座不预设上层需求,工具按 key 取值。
Implementations§
Source§impl ToolCallContext
impl ToolCallContext
Sourcepub fn new(call_id: ToolCallId) -> Self
pub fn new(call_id: ToolCallId) -> Self
创建上下文 — 只需 call_id,其余使用默认值。
Sourcepub fn with_cancellation(self, token: CancellationToken) -> Self
pub fn with_cancellation(self, token: CancellationToken) -> Self
注入已有的取消令牌(Agent loop 持有另一端用于触发取消)。
Sourcepub fn with_extra(self, extra: Value) -> Self
pub fn with_extra(self, extra: Value) -> Self
注入扩展数据。
Auto Trait Implementations§
impl Freeze for ToolCallContext
impl RefUnwindSafe for ToolCallContext
impl Send for ToolCallContext
impl Sync for ToolCallContext
impl Unpin for ToolCallContext
impl UnsafeUnpin for ToolCallContext
impl UnwindSafe for ToolCallContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more