pub struct Policy {
pub id: PolicyId,
pub title: String,
pub action: PolicyAction,
pub decision: PolicyDecision,
pub reason: Option<String>,
}Fields§
§id: PolicyId§title: String§action: PolicyAction§decision: PolicyDecision§reason: Option<String>Implementations§
Source§impl Policy
impl Policy
Sourcepub fn require_approval(
id: PolicyId,
title: impl Into<String>,
action: PolicyAction,
) -> Self
pub fn require_approval( id: PolicyId, title: impl Into<String>, action: PolicyAction, ) -> Self
Examples found in repository?
examples/policy_approval.rs (lines 11-15)
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let state = YoAgentState::load(MemoryEventStore::new()).await?;
10 let mut runtime = YoAgentRuntime::new(state.clone());
11 runtime.register_policy(Policy::require_approval(
12 PolicyId::new("policy_create_node_review"),
13 "Creating graph nodes requires review",
14 PolicyAction::CreateNode,
15 ));
16
17 let result = runtime
18 .create_typed_node(
19 ActorRef::agent("demo"),
20 NodeId::new("sensitive_node"),
21 "memory",
22 json!({ "title": "Potentially sensitive memory" }),
23 )
24 .await;
25
26 match result {
27 Err(StateError::PolicyDenied(message)) => println!("blocked: {message}"),
28 other => println!("unexpected: {other:?}"),
29 }
30
31 let approvals = state
32 .graph()
33 .await
34 .nodes
35 .values()
36 .filter(|node| node.kind == "approval_request")
37 .count();
38 println!("approval_requests={approvals}");
39 Ok(())
40}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Policy
impl<'de> Deserialize<'de> for Policy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Policy
Auto Trait Implementations§
impl Freeze for Policy
impl RefUnwindSafe for Policy
impl Send for Policy
impl Sync for Policy
impl Unpin for Policy
impl UnsafeUnpin for Policy
impl UnwindSafe for Policy
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