Skip to main content

Pack

Struct Pack 

Source
pub struct Pack {
    pub id: PackId,
    pub name: String,
    pub version: String,
    pub object_types: BTreeMap<String, ObjectType>,
    pub relation_types: BTreeMap<String, RelationType>,
    pub policies: Vec<String>,
    pub prompts: Vec<String>,
    pub settings: Value,
}

Fields§

§id: PackId§name: String§version: String§object_types: BTreeMap<String, ObjectType>§relation_types: BTreeMap<String, RelationType>§policies: Vec<String>§prompts: Vec<String>§settings: Value

Implementations§

Source§

impl Pack

Source

pub fn new( id: PackId, name: impl Into<String>, version: impl Into<String>, ) -> Self

Examples found in repository?
examples/typed_pack.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_pack(
12        Pack::new(PackId::new("pack_lineage"), "lineage", "0.1.0")
13            .add_object_type(ObjectType::new("goal").require("title"))
14            .add_object_type(ObjectType::new("task").require("title"))
15            .add_relation_type(
16                RelationType::new("serves")
17                    .from_kind("task")
18                    .to_kind("goal"),
19            ),
20    );
21
22    runtime
23        .create_typed_node(
24            ActorRef::agent("demo"),
25            NodeId::new("goal_1"),
26            "goal",
27            json!({ "title": "Improve retry reliability" }),
28        )
29        .await?;
30    runtime
31        .create_typed_node(
32            ActorRef::agent("demo"),
33            NodeId::new("task_1"),
34            "task",
35            json!({ "title": "Investigate timeout" }),
36        )
37        .await?;
38    runtime
39        .create_typed_relation(
40            ActorRef::agent("demo"),
41            NodeId::new("task_1"),
42            "serves",
43            NodeId::new("goal_1"),
44            json!({}),
45        )
46        .await?;
47
48    println!("{}", serde_json::to_string_pretty(&state.graph().await)?);
49    Ok(())
50}
Source

pub fn add_object_type(self, object_type: ObjectType) -> Self

Examples found in repository?
examples/typed_pack.rs (line 13)
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_pack(
12        Pack::new(PackId::new("pack_lineage"), "lineage", "0.1.0")
13            .add_object_type(ObjectType::new("goal").require("title"))
14            .add_object_type(ObjectType::new("task").require("title"))
15            .add_relation_type(
16                RelationType::new("serves")
17                    .from_kind("task")
18                    .to_kind("goal"),
19            ),
20    );
21
22    runtime
23        .create_typed_node(
24            ActorRef::agent("demo"),
25            NodeId::new("goal_1"),
26            "goal",
27            json!({ "title": "Improve retry reliability" }),
28        )
29        .await?;
30    runtime
31        .create_typed_node(
32            ActorRef::agent("demo"),
33            NodeId::new("task_1"),
34            "task",
35            json!({ "title": "Investigate timeout" }),
36        )
37        .await?;
38    runtime
39        .create_typed_relation(
40            ActorRef::agent("demo"),
41            NodeId::new("task_1"),
42            "serves",
43            NodeId::new("goal_1"),
44            json!({}),
45        )
46        .await?;
47
48    println!("{}", serde_json::to_string_pretty(&state.graph().await)?);
49    Ok(())
50}
Source

pub fn add_relation_type(self, relation_type: RelationType) -> Self

Examples found in repository?
examples/typed_pack.rs (lines 15-19)
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_pack(
12        Pack::new(PackId::new("pack_lineage"), "lineage", "0.1.0")
13            .add_object_type(ObjectType::new("goal").require("title"))
14            .add_object_type(ObjectType::new("task").require("title"))
15            .add_relation_type(
16                RelationType::new("serves")
17                    .from_kind("task")
18                    .to_kind("goal"),
19            ),
20    );
21
22    runtime
23        .create_typed_node(
24            ActorRef::agent("demo"),
25            NodeId::new("goal_1"),
26            "goal",
27            json!({ "title": "Improve retry reliability" }),
28        )
29        .await?;
30    runtime
31        .create_typed_node(
32            ActorRef::agent("demo"),
33            NodeId::new("task_1"),
34            "task",
35            json!({ "title": "Investigate timeout" }),
36        )
37        .await?;
38    runtime
39        .create_typed_relation(
40            ActorRef::agent("demo"),
41            NodeId::new("task_1"),
42            "serves",
43            NodeId::new("goal_1"),
44            json!({}),
45        )
46        .await?;
47
48    println!("{}", serde_json::to_string_pretty(&state.graph().await)?);
49    Ok(())
50}
Source

pub fn validate_node(&self, node: &Node) -> Result<(), StateError>

Source

pub fn validate_relation( &self, relation: &Relation, from: &Node, to: &Node, ) -> Result<(), StateError>

Trait Implementations§

Source§

impl Clone for Pack

Source§

fn clone(&self) -> Pack

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

impl Debug for Pack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Pack

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Pack

Source§

fn eq(&self, other: &Pack) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Pack

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Pack

Auto Trait Implementations§

§

impl Freeze for Pack

§

impl RefUnwindSafe for Pack

§

impl Send for Pack

§

impl Sync for Pack

§

impl Unpin for Pack

§

impl UnsafeUnpin for Pack

§

impl UnwindSafe for Pack

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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.