pub struct PolicyId(pub String);Tuple Fields§
§0: StringImplementations§
Source§impl PolicyId
impl PolicyId
Sourcepub fn new(value: impl Into<String>) -> Self
pub fn new(value: impl Into<String>) -> Self
Examples found in repository?
examples/policy_approval.rs (line 12)
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}pub fn generate() -> Self
pub fn as_str(&self) -> &str
Trait Implementations§
Source§impl<'de> Deserialize<'de> for PolicyId
impl<'de> Deserialize<'de> for PolicyId
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 Eq for PolicyId
Source§impl Ord for PolicyId
impl Ord for PolicyId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for PolicyId
impl PartialOrd for PolicyId
impl StructuralPartialEq for PolicyId
Auto Trait Implementations§
impl Freeze for PolicyId
impl RefUnwindSafe for PolicyId
impl Send for PolicyId
impl Sync for PolicyId
impl Unpin for PolicyId
impl UnsafeUnpin for PolicyId
impl UnwindSafe for PolicyId
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