Skip to main content

ToolCallContext

Struct ToolCallContext 

Source
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

Source

pub fn new(call_id: ToolCallId) -> Self

创建上下文 — 只需 call_id,其余使用默认值。

Source

pub fn with_cancellation(self, token: CancellationToken) -> Self

注入已有的取消令牌(Agent loop 持有另一端用于触发取消)。

Source

pub fn with_extra(self, extra: Value) -> Self

注入扩展数据。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.