pub struct Session { /* private fields */ }Expand description
One session. A cheap handle: clones share the terminal latch. Build it
with Sessions::create, Sessions::start, or Sessions::open.
Implementations§
Source§impl Session
impl Session
Sourcepub async fn over_budget(&self) -> Result<bool, LaserError>
pub async fn over_budget(&self) -> Result<bool, LaserError>
Whether this session’s usage has passed its budget: the summed input
and output tokens of its records over the token ceiling, or their
summed cost over the cost ceiling. A deployment that indexes sessions
answers from its index. On open Apache Iggy, or for a session the
index does not know yet, the retained session lane is folded: the
budget of the first start record against the usage of every record.
A session without a budget is never over it. The answer is eventually
consistent, so a budget is a cooperative limit, not a hard spending
cap.
Source§impl Session
impl Session
Sourcepub async fn parked(&self) -> Result<ParkedRecords, LaserError>
pub async fn parked(&self) -> Result<ParkedRecords, LaserError>
The work records this session’s agents held while it was paused and
have not reported handled. A session canceled while paused keeps its
held records here unprocessed. The read covers the newest
CONTEXT_READ_WINDOW records
of each agent.sessions partition.
Source§impl Session
impl Session
Sourcepub fn signed_by(self, key: SigningKey) -> Self
pub fn signed_by(self, key: SigningKey) -> Self
This handle signing its terminal record with key, so a verifying
reader can prove which agent ended the session. Feature sign.
Sourcepub fn conversation(&self) -> ConversationId
pub fn conversation(&self) -> ConversationId
This session’s id.
Sourcepub fn stream(&self) -> Result<&str, LaserError>
pub fn stream(&self) -> Result<&str, LaserError>
The stream this session lives in.
Sourcepub fn parent(&self) -> Option<ConversationId>
pub fn parent(&self) -> Option<ConversationId>
The parent session, for a child session.
Sourcepub fn root(&self) -> Option<ConversationId>
pub fn root(&self) -> Option<ConversationId>
The root of this session’s tree, for a child session.
Sourcepub fn config(&self) -> &SessionConfig
pub fn config(&self) -> &SessionConfig
The layout this session follows.
Sourcepub fn scope(&self) -> &ContextScope
pub fn scope(&self) -> &ContextScope
The underlying ContextScope, for a topic outside the session lane
or an explicit ContextPolicy.
Sourcepub async fn append(
&self,
envelope: AgentEnvelope,
) -> Result<AgdxReceipt, LaserError>
pub async fn append( &self, envelope: AgentEnvelope, ) -> Result<AgdxReceipt, LaserError>
Append one typed envelope to the session lane. The envelope must name this session as its conversation.
Sourcepub async fn end(&self) -> Result<(), LaserError>
pub async fn end(&self) -> Result<(), LaserError>
End the session as completed. State changed since the last snapshot is snapshotted first, so a reader can start from the final document.
Sourcepub async fn fail(&self, error: AgentErrorBody) -> Result<(), LaserError>
pub async fn fail(&self, error: AgentErrorBody) -> Result<(), LaserError>
End the session as failed with error.
Sourcepub async fn cancel(&self) -> Result<(), LaserError>
pub async fn cancel(&self) -> Result<(), LaserError>
End the session as canceled.
Sourcepub async fn run<F, Fut, T>(
self,
lease: SessionLease,
work: F,
) -> Result<T, LaserError>
pub async fn run<F, Fut, T>( self, lease: SessionLease, work: F, ) -> Result<T, LaserError>
Run work inside the session and end it by the outcome: completed on
success, failed on an error or a panic. A panic is re-raised after the
failure is written. When the terminal write also fails, the error from
work is returned. A dropped future, panic = "abort", an unawaited
child task, or process death is not captured, and the session then
shows idle once its heartbeat stops.
Sourcepub async fn context(&self) -> Result<Vec<SessionTurn>, LaserError>
pub async fn context(&self) -> Result<Vec<SessionTurn>, LaserError>
The model-ready context: the configured last records on the session lane, trimmed to the configured estimated token bound.
Sourcepub async fn context_with(
&self,
policy: Box<dyn ContextPolicy>,
) -> Result<Vec<SessionTurn>, LaserError>
pub async fn context_with( &self, policy: Box<dyn ContextPolicy>, ) -> Result<Vec<SessionTurn>, LaserError>
context under an explicit policy.
Sourcepub fn memory(&self) -> ScopedMemory
pub fn memory(&self) -> ScopedMemory
This session’s memory in the configured namespace, scoped to the session.
Sourcepub fn memory_in(&self, namespace: impl Into<String>) -> ScopedMemory
pub fn memory_in(&self, namespace: impl Into<String>) -> ScopedMemory
memory in an explicit namespace.
Sourcepub fn graph(&self, name: impl Into<String>) -> GraphHandle<'_>
pub fn graph(&self, name: impl Into<String>) -> GraphHandle<'_>
The knowledge graph name, the same graph Laser::graph returns.
Feature graph.
Sourcepub async fn checkpoint(&self) -> Result<Checkpoint, LaserError>
pub async fn checkpoint(&self) -> Result<Checkpoint, LaserError>
Sourcepub async fn turns_at(
&self,
checkpoint: Checkpoint,
) -> Result<Vec<SessionTurn>, LaserError>
pub async fn turns_at( &self, checkpoint: Checkpoint, ) -> Result<Vec<SessionTurn>, LaserError>
The records up to checkpoint.
Sourcepub async fn turns_since(
&self,
checkpoint: Checkpoint,
) -> Result<Vec<SessionTurn>, LaserError>
pub async fn turns_since( &self, checkpoint: Checkpoint, ) -> Result<Vec<SessionTurn>, LaserError>
The records appended after checkpoint.
Sourcepub async fn state_at<S, F>(
&self,
checkpoint: Checkpoint,
init: S,
fold: F,
) -> Result<S, LaserError>where
F: FnMut(S, &SessionTurn) -> S,
pub async fn state_at<S, F>(
&self,
checkpoint: Checkpoint,
init: S,
fold: F,
) -> Result<S, LaserError>where
F: FnMut(S, &SessionTurn) -> S,
Fold the records up to checkpoint into S: state as it stood then.
Sourcepub async fn replay<S, F>(
&self,
checkpoint: Checkpoint,
init: S,
fold: F,
) -> Result<S, LaserError>where
F: FnMut(S, &SessionTurn) -> S,
pub async fn replay<S, F>(
&self,
checkpoint: Checkpoint,
init: S,
fold: F,
) -> Result<S, LaserError>where
F: FnMut(S, &SessionTurn) -> S,
Fold the records appended after checkpoint into S: bring state
saved at that checkpoint up to date.
Source§impl Session
impl Session
Sourcepub async fn status(&self) -> Result<SessionInfo, LaserError>
pub async fn status(&self) -> Result<SessionInfo, LaserError>
This session’s summary from the deployment’s session index: status, participants, counters, and the derived idle and over-budget flags.
Source§impl Session
impl Session
Sourcepub fn reference(&self) -> Result<SessionRef, LaserError>
pub fn reference(&self) -> Result<SessionRef, LaserError>
This session as a stream-scoped reference, for writes that land outside the session’s own stream.
Sourcepub fn redact(
self,
redactor: impl Fn(&mut Value) + Send + Sync + 'static,
) -> Self
pub fn redact( self, redactor: impl Fn(&mut Value) + Send + Sync + 'static, ) -> Self
Replace the redaction applied to tool arguments and model request bodies before they are published. The default drops the values of common secret keys.
Sourcepub fn acting_on(self, source: SourceRef) -> Self
pub fn acting_on(self, source: SourceRef) -> Self
This handle with source as the record it acts on, stamped as the
source of graph writes and the origin of remembered items.
Sourcepub async fn cancel_requested(&self) -> Result<bool, LaserError>
pub async fn cancel_requested(&self) -> Result<bool, LaserError>
Whether an operator asked to cancel this session on agent.control,
by a cancel request or a forced cancel. Reads the retained control
records of this session, so it answers on open Apache Iggy too.
Sourcepub async fn pending_control(&self) -> Result<PendingControl, LaserError>
pub async fn pending_control(&self) -> Result<PendingControl, LaserError>
The pause and cancel requests operators sent this session on
agent.control, addressed to this handle’s agent or to every agent.
Inside a handler the runtime’s control subscription keeps them
current, and the first read of a session folds its retained control
records. Outside a runtime every call reads the retained records. The
runtime only records requests: the handler decides when to stop.
Sourcepub fn state(&self) -> SessionState
pub fn state(&self) -> SessionState
The session’s state document.
Sourcepub async fn assemble(
&self,
policy: Box<dyn ContextPolicy>,
) -> Result<AssembledContext, LaserError>
pub async fn assemble( &self, policy: Box<dyn ContextPolicy>, ) -> Result<AssembledContext, LaserError>
Assemble the model context under policy from the session lane and
describe it in a manifest. Nothing is written.
Sourcepub async fn model(
&self,
request: ModelRequest,
assembled: Option<&AssembledContext>,
) -> Result<ModelCall, LaserError>
pub async fn model( &self, request: ModelRequest, assembled: Option<&AssembledContext>, ) -> Result<ModelCall, LaserError>
Record a model request addressed to this agent, and the context it
received when assembled is given. Finish the returned call when the
application’s provider answers.
Sourcepub async fn tool(
&self,
name: impl Into<String>,
args: Value,
) -> Result<ToolCall, LaserError>
pub async fn tool( &self, name: impl Into<String>, args: Value, ) -> Result<ToolCall, LaserError>
Record a tool call addressed to this agent, with args redacted.
Sourcepub async fn record_model_call(
&self,
request: ModelRequest,
response: ModelResponse,
assembled: Option<&AssembledContext>,
) -> Result<AgdxReceipt, LaserError>
pub async fn record_model_call( &self, request: ModelRequest, response: ModelResponse, assembled: Option<&AssembledContext>, ) -> Result<AgdxReceipt, LaserError>
Record a model call that already happened: the request, the context
when given, and the response. duration is the measured call time.
A response with no duration records duration_micros = 0.
Sourcepub fn kv(&self, namespace: impl Into<String>) -> Result<Kv, LaserError>
pub fn kv(&self, namespace: impl Into<String>) -> Result<Kv, LaserError>
The key-value namespace namespace with every write linked to this
session. Feature kv.
Sourcepub fn linked_graph(
&self,
name: impl Into<String>,
) -> Result<GraphHandle<'_>, LaserError>
pub fn linked_graph( &self, name: impl Into<String>, ) -> Result<GraphHandle<'_>, LaserError>
The knowledge graph name with every upsert linked to this session,
stamped with this agent as producer and the current record as source.
Feature graph.
Sourcepub async fn record_retrieval(
&self,
query: Option<String>,
items: &[MemoryItem],
) -> Result<AgdxReceipt, LaserError>
pub async fn record_retrieval( &self, query: Option<String>, items: &[MemoryItem], ) -> Result<AgdxReceipt, LaserError>
Record that items, recalled for query when there was one, entered
the session’s context, with each item’s id and score.
Sourcepub async fn record_compaction(
&self,
compaction: ContextCompaction,
) -> Result<AgdxReceipt, LaserError>
pub async fn record_compaction( &self, compaction: ContextCompaction, ) -> Result<AgdxReceipt, LaserError>
Record that a summary replaced the covered records of the session’s context.
Sourcepub fn linked_memory(&self) -> ScopedMemory
pub fn linked_memory(&self) -> ScopedMemory
This session’s memory with every remembered item stamped with this agent as producer and the current record as origin.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Session
impl !UnwindSafe for Session
impl Freeze for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.