commandagi 0.6.10

The CommandAGI SDK for Rust: the platform client (agent threads, live sessions on a simulated world) and CommandAGI documents (a schematic, a 3D part …) declared as code. No dependencies.
Documentation
// An agent's skill in Rust against the document the TypeScript SDK's skills.ts gives for the same elements: its steps
// and reply; a literal script's result; a skill that does not read is refused with why, and what the vocabulary has no
// words for (a phrase, an example, a rule, a fact) is refused by name.

use commandagi::design::skills::*;
use commandagi::design::{declare, Declared};
use commandagi::design::El;

fn document(root: El) -> (String, Json) {
    match declare(root).unwrap() {
        Declared::Document { format, document, .. } => (format, document),
        Declared::Graph(_) => panic!("a skill is a document"),
    }
}

#[test]
fn the_example_is_its_document() {
    let (format, doc) = document(
        skill([
            step().expr("mul(x, 3)").as_("out"),
            step().tool("read_file").args(json(r#"{"path": "{file}"}"#)).as_("read").always(true),
            reply().text("{out}"),
        ])
        .about("Three times a number.")
        .origin("frozen:cua"),
    );
    assert_eq!(format, "skill");
    assert_eq!(
        doc,
        Json::parse(
            r#"{"about": "Three times a number.", "origin": "frozen:cua",
                "steps": [{"expr": "mul(x, 3)", "as": "out"}, {"tool": "read_file", "args": {"path": "{file}"}, "as": "read", "always": true}],
                "reply": "{out}"}"#
        )
        .unwrap()
    );
    assert_eq!(document(result().value(2)), ("result".to_string(), Json::parse(r#"{"value": 2}"#).unwrap()));
}

#[test]
fn a_skill_that_does_not_read_is_refused_with_why() {
    for (s, why) in [
        (skill([step().expr("1").tool("read_file")]), "is exactly one of expr, tool, script, skill, see (it has expr and tool)"),
        (skill([step().as_("x")]), "is exactly one of"),
        (skill([step().expr("1").always("yes")]), "always is true or false"),
        (skill([step().tool("read_file").args(["a"])]), "args is an object"),
        (skill([]).attr("gives", json(r#"["at(arm, home)"]"#)), "gives"),
    ] {
        let said = declare(s).unwrap_err();
        assert!(said.contains(why), "{why}: {said}");
    }
}

#[test]
fn a_phrase_an_example_a_rule_or_a_fact_is_refused_by_name() {
    // Free text is read only by a model agent: a skill has no phrase to match or example utterance to check.
    for tag in ["phrase", "example", "rule", "fact"] {
        let said = declare(skill([El::new(tag).attr("is", "a")])).unwrap_err();
        assert!(said.contains(tag), "{tag}: {said}");
    }
}