pub struct AutonomyLadder { /* private fields */ }charter and harness-kernel only.Expand description
The autonomy ladder of a site’s jobs (spec 3.5 §7.11, A-I13): promotion only by an owner’s decision, demotion one level by the site on a guardrail breach, two owner rejections in a row, or an incident in the job’s area, each with its reason.
| Call | Who | Effect |
|---|---|---|
register, sync | the site | A job enters at its charter level; a charter that sets a lower level lowers it; a higher one changes nothing |
promote, promote_to | an owner, with an OwnerDecision | One level up, or to a named higher level; refused for anyone else |
lower | the site | One level down |
guardrail_breach, incident | the site | One level down |
record_decision | the owner’s inbox | Counts towards promotion; the second rejection in a row lowers one level |
eligibility, offers | the weekly review | The promotions the record earned |
A promotion’s change carries the owner’s decision, from which the harness creates the
standing rule (spec 3.5 §6 D-7). Every change is audited as website.job.promoted or
website.job.demoted and emitted as CharterEvent::AutonomyChanged.
§Example
use std::sync::Arc;
use adk_core::principal::SubjectRef;
use adk_kernel::charter::{AutonomyLadder, InMemoryAutonomyStore, OwnerDecision};
use awp_types::AutonomyLevel;
let ladder = AutonomyLadder::new(Arc::new(InMemoryAutonomyStore::new()));
let site = uuid::Uuid::nil();
ladder.register(site, "review-replies", AutonomyLevel::Propose, Some("serve")).await?;
let agent = OwnerDecision::new("d-1", SubjectRef::service("urn:adk:agent:example/steward"), chrono::Utc::now());
assert!(ladder.promote(site, "review-replies", &agent).await.is_err(), "the site never raises itself");
let owner = OwnerDecision::new("d-2", SubjectRef::human("amina"), chrono::Utc::now());
assert_eq!(ladder.promote(site, "review-replies", &owner).await?.level, AutonomyLevel::ActWithApproval);
assert_eq!(ladder.guardrail_breach(site, "review-replies", "complaints").await?.unwrap().level, AutonomyLevel::Propose);Implementations§
Source§impl AutonomyLadder
impl AutonomyLadder
Sourcepub fn new(store: Arc<dyn AutonomyStore>) -> AutonomyLadder
pub fn new(store: Arc<dyn AutonomyStore>) -> AutonomyLadder
A ladder over store with the default promotion policy, no charter store (an owner
decision is then checked for a person only), the system clock, no audit and no events.
Sourcepub fn with_charters(self, charters: Arc<dyn CharterStore>) -> AutonomyLadder
pub fn with_charters(self, charters: Arc<dyn CharterStore>) -> AutonomyLadder
Checks owner decisions against the governance of the charter in force: the decider must hold the owner role.
Sourcepub fn with_policy(self, policy: PromotionPolicy) -> AutonomyLadder
pub fn with_policy(self, policy: PromotionPolicy) -> AutonomyLadder
Sets the promotion policy.
Sourcepub fn with_clock(self, clock: Arc<dyn Clock>) -> AutonomyLadder
pub fn with_clock(self, clock: Arc<dyn Clock>) -> AutonomyLadder
Reads time from clock.
Sourcepub fn with_audit(self, trail: AuditTrail) -> AutonomyLadder
pub fn with_audit(self, trail: AuditTrail) -> AutonomyLadder
Audits every change on trail.
Sourcepub fn with_events(self, sink: Arc<dyn CharterEventSink>) -> AutonomyLadder
pub fn with_events(self, sink: Arc<dyn CharterEventSink>) -> AutonomyLadder
Emits every change on sink.
Sourcepub fn store(&self) -> &Arc<dyn AutonomyStore> ⓘ
pub fn store(&self) -> &Arc<dyn AutonomyStore> ⓘ
The store.
Sourcepub fn policy(&self) -> &PromotionPolicy
pub fn policy(&self) -> &PromotionPolicy
The promotion policy.
Sourcepub async fn register(
&self,
site: Uuid,
job: &str,
level: AutonomyLevel,
area: Option<&str>,
) -> Result<JobAutonomy, KernelError>
pub async fn register( &self, site: Uuid, job: &str, level: AutonomyLevel, area: Option<&str>, ) -> Result<JobAutonomy, KernelError>
Registers job at level in area unless it is registered; returns its record.
§Errors
Returns a store error.
Sourcepub async fn sync(
&self,
charter: &Charter,
) -> Result<Vec<JobAutonomy>, KernelError>
pub async fn sync( &self, charter: &Charter, ) -> Result<Vec<JobAutonomy>, KernelError>
Brings the jobs of charter’s authority onto the ladder (spec 3.5 §7.11): a job not
registered enters at the charter’s level; a registered job above the charter’s level
is lowered to it, unless an owner promoted it there after the charter took effect; a
job below it stays where it is, since only an owner’s promote
raises a level.
The charter took effect when its owner signed it — the committing decision’s time — or, for an unsigned charter, when the charter store committed it; a charter with neither lowers every job above it. Syncing the charter in force again — as every start of a site does — so keeps the owner’s promotions (A-I13), and a later charter that sets a lower level still lowers.
§Errors
Returns a store error.
Sourcepub async fn level(
&self,
site: Uuid,
job: &str,
) -> Result<Option<AutonomyLevel>, KernelError>
pub async fn level( &self, site: Uuid, job: &str, ) -> Result<Option<AutonomyLevel>, KernelError>
Sourcepub async fn promote(
&self,
site: Uuid,
job: &str,
decision: &OwnerDecision,
) -> Result<JobAutonomy, KernelError>
pub async fn promote( &self, site: Uuid, job: &str, decision: &OwnerDecision, ) -> Result<JobAutonomy, KernelError>
Raises job one level by decision (A-I13). See promote_to.
§Errors
As promote_to; also KernelError::Config at the top rung.
Sourcepub async fn promote_to(
&self,
site: Uuid,
job: &str,
to: AutonomyLevel,
decision: &OwnerDecision,
) -> Result<JobAutonomy, KernelError>
pub async fn promote_to( &self, site: Uuid, job: &str, to: AutonomyLevel, decision: &OwnerDecision, ) -> Result<JobAutonomy, KernelError>
Raises job to to by decision (spec 3.5 §7.11, A-I13). The decision must be a
person’s (OwnerDecision::check_person); with a charter store, that person must hold
the owner role in the charter in force. The change carries the decision, from which
the harness creates the standing rule.
§Errors
Returns KernelError::Unauthorized for a decision no owner made,
KernelError::Config when to is not above the job’s level, or a store error.
Sourcepub async fn lower(
&self,
site: Uuid,
job: &str,
reason: &str,
) -> Result<Option<JobAutonomy>, KernelError>
pub async fn lower( &self, site: Uuid, job: &str, reason: &str, ) -> Result<Option<JobAutonomy>, KernelError>
Lowers job one level for reason (spec 3.5 §7.11): the site may always lower its
own autonomy. None when the job is at Observe already.
§Errors
Returns KernelError::Config for an unregistered job, or a store error.
Sourcepub async fn guardrail_breach(
&self,
site: Uuid,
job: &str,
guardrail: &str,
) -> Result<Option<JobAutonomy>, KernelError>
pub async fn guardrail_breach( &self, site: Uuid, job: &str, guardrail: &str, ) -> Result<Option<JobAutonomy>, KernelError>
Lowers job one level because guardrail was breached (spec 3.5 §7.11, A-I15).
§Errors
Returns KernelError::Config for an unregistered job, or a store error.
Sourcepub async fn incident(
&self,
site: Uuid,
area: &str,
incident: &str,
) -> Result<Vec<JobAutonomy>, KernelError>
pub async fn incident( &self, site: Uuid, area: &str, incident: &str, ) -> Result<Vec<JobAutonomy>, KernelError>
Lowers every job of area one level for incident (spec 3.5 §7.11); returns the
jobs it lowered.
§Errors
Returns a store error.
Sourcepub async fn record_decision(
&self,
decision: JobDecision,
) -> Result<Option<JobAutonomy>, KernelError>
pub async fn record_decision( &self, decision: JobDecision, ) -> Result<Option<JobAutonomy>, KernelError>
Records the owner’s decision on a proposal of its job (spec 3.5 §7.11). The second
rejection in a row since the job’s last change lowers it one level, which is
returned. A repeated decision id changes nothing.
§Errors
Returns KernelError::Unauthorized for a decision no person made — an agent’s
approvals never build a promotion — KernelError::Config for an unregistered job,
or a store error.
Sourcepub async fn eligibility(
&self,
site: Uuid,
job: &str,
) -> Result<PromotionEligibility, KernelError>
pub async fn eligibility( &self, site: Uuid, job: &str, ) -> Result<PromotionEligibility, KernelError>
Whether job has earned a promotion (spec 3.5 §7.11): the unchanged approvals in a
row, latest first, made within the policy’s window since the job’s last change.
§Errors
Returns KernelError::Config for an unregistered job, or a store error.
Sourcepub async fn offers(
&self,
site: Uuid,
) -> Result<Vec<PromotionEligibility>, KernelError>
pub async fn offers( &self, site: Uuid, ) -> Result<Vec<PromotionEligibility>, KernelError>
The promotions the site’s jobs earned, for the weekly review; each is emitted as
CharterEvent::PromotionOffered.
§Errors
Returns a store error.
Trait Implementations§
Source§impl Clone for AutonomyLadder
impl Clone for AutonomyLadder
Source§fn clone(&self) -> AutonomyLadder
fn clone(&self) -> AutonomyLadder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for AutonomyLadder
impl !UnwindSafe for AutonomyLadder
impl Forget for AutonomyLadder
impl Freeze for AutonomyLadderwhere
*const ArcInner<dyn AutonomyStore> is !null: Freeze,
PhantomData<ArcInner<dyn AutonomyStore>>: Freeze,
*const ArcInner<dyn CharterStore> is !null: Freeze,
PhantomData<ArcInner<dyn CharterStore>>: Freeze,
*const ArcInner<dyn Clock> is !null: Freeze,
PhantomData<ArcInner<dyn Clock>>: Freeze,
*const ArcInner<dyn AuditRecorder> is !null: Freeze,
PhantomData<ArcInner<dyn AuditRecorder>>: Freeze,
*const ArcInner<dyn CharterEventSink> is !null: Freeze,
PhantomData<ArcInner<dyn CharterEventSink>>: Freeze,
impl Move for AutonomyLadder
impl Send for AutonomyLadderwhere
Arc<dyn AutonomyStore>: Send,
Arc<dyn CharterStore>: Send,
Arc<dyn Clock>: Send,
Arc<dyn AuditRecorder>: Send,
Arc<dyn CharterEventSink>: Send,
impl Sync for AutonomyLadderwhere
Arc<dyn AutonomyStore>: Sync,
Arc<dyn CharterStore>: Sync,
Arc<dyn Clock>: Sync,
Arc<dyn AuditRecorder>: Sync,
Arc<dyn CharterEventSink>: Sync,
impl Unpin for AutonomyLadderwhere
Arc<dyn AutonomyStore>: Unpin,
Arc<dyn CharterStore>: Unpin,
Arc<dyn Clock>: Unpin,
Arc<dyn AuditRecorder>: Unpin,
Arc<dyn CharterEventSink>: Unpin,
impl UnsafeUnpin for AutonomyLadderwhere
*const ArcInner<dyn AutonomyStore> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn AutonomyStore>>: UnsafeUnpin,
*const ArcInner<dyn CharterStore> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn CharterStore>>: UnsafeUnpin,
*const ArcInner<dyn Clock> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Clock>>: UnsafeUnpin,
*const ArcInner<dyn AuditRecorder> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn AuditRecorder>>: UnsafeUnpin,
*const ArcInner<dyn CharterEventSink> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn CharterEventSink>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSend for Twhere
T: Send,
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> Pointable for T
impl<T> Pointable for T
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.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.