pub struct Agents { /* private fields */ }Expand description
The kernel’s audited agent table (spec 3.3 §5.7, §10 K7), from
Kernel::agents: the one front door for adding, changing,
pausing and removing the agents a person adds, whichever surface asks.
Its rules:
| Rule | Spec |
|---|---|
| Only a person changes an agent; a device only answers suggestions | S-I11, decision 16 |
| A change previews first and applies only with its preview’s digest | §5.7 |
| High risk or money needs presence: a paired local terminal or “Confirm it’s you” | §7.2, decision 22 |
| A definition stays within its area: its mode, limit and mounted drivers | §5.7, K-I13 |
| A suggestion stays within its suggester, checked when made and again when approved | S-I12 |
Every change is recorded (kernel.agent.*) before it acts, and refused when the record cannot be written | S-I18, K-I16 |
| A removed agent’s id is never given again | S-I14 |
Cloning shares the table.
§Example
use adk_core::principal::SubjectRef;
use adk_kernel::agents::{AgentAction, AgentCaller, AgentDefinition, Presence};
let caller = AgentCaller::new(SubjectRef::human("alice"), "terminal", "keyboard")
.with_presence(Presence::PairedLocal);
let add = AgentAction::Create { definition: AgentDefinition::new("Finance", "default"), replaces: None };
let preview = kernel.agents().preview(&caller, &add).await?;
println!("{} — {:?} risk; confirm with {}", preview.id, preview.risk, preview.code());
kernel.agents().apply(&caller, add, &preview.digest).await?;Implementations§
Source§impl Agents
impl Agents
Sourcepub fn store(&self) -> &Arc<dyn AgentStore> ⓘ
pub fn store(&self) -> &Arc<dyn AgentStore> ⓘ
The store the agents live in.
Sourcepub async fn list(&self) -> Result<Vec<AgentView>>
pub async fn list(&self) -> Result<Vec<AgentView>>
Every agent with its state — suggested, active, paused, being removed and removed — ordered by id, each with why this kernel cannot build it when it cannot (“Can’t start”). Refused suggestions, which never were agents, are left out. A surface reads a removed agent’s state here, so it never looks agents up one by one (spec 3.3 §5.7).
§Errors
Returns the store’s error.
Sourcepub async fn choices(&self) -> Result<AgentChoices>
pub async fn choices(&self) -> Result<AgentChoices>
What a person may choose for an agent on this host: the models whose key it has, and the packs.
§Errors
Returns the factory’s error; an empty choice when the host builds no agents.
Sourcepub async fn preview(
&self,
caller: &AgentCaller,
action: &AgentAction,
) -> Result<AgentPreview>
pub async fn preview( &self, caller: &AgentCaller, action: &AgentAction, ) -> Result<AgentPreview>
What action would do, without doing it: the agent’s abilities and risk as it would
be, what it changes, what a removal ends, and the digest that applies it (spec 3.3
§5.7).
§Errors
Returns kernel.agent.refused when caller may change no agent, kernel.agent.invalid
for a definition that breaks a rule, kernel.agent.not_found,
kernel.agent.out_of_date for a change against an older version, or a store error.
Sourcepub async fn apply(
&self,
caller: &AgentCaller,
action: AgentAction,
digest: &str,
) -> Result<AgentOutcome>
pub async fn apply( &self, caller: &AgentCaller, action: AgentAction, digest: &str, ) -> Result<AgentOutcome>
Applies action for caller when digest is its preview’s (spec 3.3 §5.7), writing
its kernel.agent.* record first.
§Errors
As preview; kernel.agent.unconfirmed when digest is not the
preview’s; kernel.agent.refused for high risk or money without presence; the audit
trail’s error under AuditFailureMode::Block, in which case nothing changed.
Sourcepub async fn create(
&self,
caller: &AgentCaller,
definition: AgentDefinition,
digest: &str,
) -> Result<AgentRecord>
pub async fn create( &self, caller: &AgentCaller, definition: AgentDefinition, digest: &str, ) -> Result<AgentRecord>
Sourcepub async fn change(
&self,
caller: &AgentCaller,
id: &str,
expected_version: u64,
definition: AgentDefinition,
digest: &str,
) -> Result<AgentRecord>
pub async fn change( &self, caller: &AgentCaller, id: &str, expected_version: u64, definition: AgentDefinition, digest: &str, ) -> Result<AgentRecord>
Sourcepub async fn pause(&self, caller: &AgentCaller, id: &str) -> Result<AgentRecord>
pub async fn pause(&self, caller: &AgentCaller, id: &str) -> Result<AgentRecord>
Sourcepub async fn resume(
&self,
caller: &AgentCaller,
id: &str,
) -> Result<AgentRecord>
pub async fn resume( &self, caller: &AgentCaller, id: &str, ) -> Result<AgentRecord>
Sourcepub async fn remove(
&self,
caller: &AgentCaller,
id: &str,
expected_version: u64,
digest: &str,
) -> Result<EndedWork>
pub async fn remove( &self, caller: &AgentCaller, id: &str, expected_version: u64, digest: &str, ) -> Result<EndedWork>
Removes agent id asked against expected_version, returning what ended:
apply of AgentAction::Remove.
§Errors
As apply.
Sourcepub async fn propose(
&self,
definition: AgentDefinition,
proposer: &AgentProposer,
) -> Result<AgentProposal>
pub async fn propose( &self, definition: AgentDefinition, proposer: &AgentProposer, ) -> Result<AgentProposal>
Suggests definition for proposer, an agent (spec 3.3 §5.7, S-I12): checks it
against the suggester’s limits now and its area’s, keeps it Proposed, and puts one
kernel:agent.create request in the inbox, which only a person’s approval of the
same definition applies. The same suggestion waiting already is returned merged; at
most MAX_OPEN_SUGGESTIONS wait per suggesting agent.
§Errors
kernel.agent.refused for a suggestion over its suggester’s or area’s limits, too
many waiting, or a kernel without an inbox or a factory; kernel.agent.invalid for a
definition that breaks a rule; a store or audit error.
Sourcepub async fn area(&self, id: &PartitionId) -> Result<Partition>
pub async fn area(&self, id: &PartitionId) -> Result<Partition>
The area id as the table checks a definition against it (spec 3.3 §5.7): its mode —
the mode its agent started in, else its record’s, tightened by a mode the person set
while the kernel runs — and its quotas — the kernel’s, lowered by its own and by a
daily limit the person set. The default area exists even when no record of it does.
§Errors
kernel.agent.invalid for an area the kernel does not have, or the store’s error.
§Example
let home = kernel.agents().area(&adk_kernel::PartitionId::default()).await?;
println!("agents in Home ask at most as {:?}", home.default_mode);Sourcepub async fn answered(&self, request_id: &str, caller: &AgentCaller)
pub async fn answered(&self, request_id: &str, caller: &AgentCaller)
Applies a person’s answer to the suggestion whose inbox request is request_id now,
as caller gave it, rather than on the next tick, so the agent’s
kernel.agent.created names the surface, device and presence it was approved with
(spec 3.3 §11). Does nothing for a request that is not a waiting suggestion’s.
§Example
use adk_core::principal::SubjectRef;
use adk_kernel::agents::AgentCaller;
let phone = AgentCaller::new(SubjectRef::human("alice"), "phone", "touch");
kernel.agents().answered("agent-finance-0123456789ab", &phone).await;Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Agents
impl !UnwindSafe for Agents
impl Forget for Agents
impl Freeze for Agents
impl Move for Agents
impl Send for Agents
impl Sync for Agents
impl Unpin for Agents
impl UnsafeUnpin for Agentswhere
*const ArcInner<AgentsInner> is !null: UnsafeUnpin,
PhantomData<ArcInner<AgentsInner>>: UnsafeUnpin,
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.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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§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<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.