pub struct LoopContext<T: Clone + Send + Sync = ()> {
pub state: T,
/* private fields */
}Expand description
Generic context wrapper with built-in depth tracking.
Wraps any Clone + Send + Sync state and automatically implements
LoopDepth, eliminating the boilerplate of storing a depth field
and writing the trait impl yourself.
§Examples
use llm_stack::tool::{LoopContext, LoopDepth, ToolRegistry};
#[derive(Clone)]
struct AppState {
user_id: String,
api_key: String,
}
let ctx = LoopContext::new(AppState {
user_id: "user_123".into(),
api_key: "sk-secret".into(),
});
assert_eq!(ctx.loop_depth(), 0);
assert_eq!(ctx.state.user_id, "user_123");
// Use with a typed registry
let registry: ToolRegistry<LoopContext<AppState>> = ToolRegistry::new();For the zero-state case, use LoopContext<()>:
use llm_stack::tool::{LoopContext, LoopDepth};
let ctx = LoopContext::empty();
assert_eq!(ctx.loop_depth(), 0);
let nested = ctx.with_depth(1);
assert_eq!(nested.loop_depth(), 1);Fields§
§state: TThe application state accessible from tool handlers.
Implementations§
Trait Implementations§
Source§impl<T: Clone + Clone + Send + Sync> Clone for LoopContext<T>
impl<T: Clone + Clone + Send + Sync> Clone for LoopContext<T>
Source§fn clone(&self) -> LoopContext<T>
fn clone(&self) -> LoopContext<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for LoopContext<T>where
T: Freeze,
impl<T> RefUnwindSafe for LoopContext<T>where
T: RefUnwindSafe,
impl<T> Send for LoopContext<T>
impl<T> Sync for LoopContext<T>
impl<T> Unpin for LoopContext<T>where
T: Unpin,
impl<T> UnwindSafe for LoopContext<T>where
T: UnwindSafe,
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