Skip to main content

Session

Struct Session 

Source
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

Source

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

Source

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

Source

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.

Source

pub fn as_agent(self, agent: impl Into<AgentId>) -> Self

This handle writing as agent.

Source

pub fn conversation(&self) -> ConversationId

This session’s id.

Source

pub fn stream(&self) -> Result<&str, LaserError>

The stream this session lives in.

Source

pub fn agent(&self) -> Option<&AgentId>

The agent this handle writes as.

Source

pub fn parent(&self) -> Option<ConversationId>

The parent session, for a child session.

Source

pub fn root(&self) -> Option<ConversationId>

The root of this session’s tree, for a child session.

Source

pub fn config(&self) -> &SessionConfig

The layout this session follows.

Source

pub fn scope(&self) -> &ContextScope

The underlying ContextScope, for a topic outside the session lane or an explicit ContextPolicy.

Source

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.

Source

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.

Source

pub async fn fail(&self, error: AgentErrorBody) -> Result<(), LaserError>

End the session as failed with error.

Source

pub async fn cancel(&self) -> Result<(), LaserError>

End the session as canceled.

Source

pub async fn run<F, Fut, T>( self, lease: SessionLease, work: F, ) -> Result<T, LaserError>
where F: FnOnce(Session) -> Fut, Fut: Future<Output = 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.

Source

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.

Source

pub async fn context_with( &self, policy: Box<dyn ContextPolicy>, ) -> Result<Vec<SessionTurn>, LaserError>

context under an explicit policy.

Source

pub fn memory(&self) -> ScopedMemory

This session’s memory in the configured namespace, scoped to the session.

Source

pub fn memory_in(&self, namespace: impl Into<String>) -> ScopedMemory

memory in an explicit namespace.

Source

pub fn graph(&self, name: impl Into<String>) -> GraphHandle<'_>

The knowledge graph name, the same graph Laser::graph returns. Feature graph.

Source

pub async fn checkpoint(&self) -> Result<Checkpoint, LaserError>

Where the session lane ends right now. Persist it (it serializes) and hand it to state_at or replay.

Source

pub async fn turns_at( &self, checkpoint: Checkpoint, ) -> Result<Vec<SessionTurn>, LaserError>

The records up to checkpoint.

Source

pub async fn turns_since( &self, checkpoint: Checkpoint, ) -> Result<Vec<SessionTurn>, LaserError>

The records appended after checkpoint.

Source

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.

Source

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

Source

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

Source

pub fn reference(&self) -> Result<SessionRef, LaserError>

This session as a stream-scoped reference, for writes that land outside the session’s own stream.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn state(&self) -> SessionState

The session’s state document.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn record_compaction( &self, compaction: ContextCompaction, ) -> Result<AgdxReceipt, LaserError>

Record that a summary replaced the covered records of the session’s context.

Source

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§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .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
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .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
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more