Skip to main content

agent_id_for

Function agent_id_for 

Source
pub fn agent_id_for(display_name: &str, taken: impl Fn(&str) -> bool) -> String
Expand description

The id an agent named display_name gets (spec 3.3 §5.7, S-I14): its name in lowercase ASCII letters and digits joined by -, at most MAX_AGENT_ID_LEN characters, or FALLBACK_AGENT_ID when it has no letter or digit; then -2, -3, … while taken says the id was ever used or is reserved.

§Example

use adk_kernel::agents::agent_id_for;

assert_eq!(agent_id_for("Finance", |_| false), "finance");
assert_eq!(agent_id_for("Finance", |id| id == "finance"), "finance-2");
assert_eq!(agent_id_for("Bills & Taxes!", |_| false), "bills-taxes");
assert_eq!(agent_id_for("日本", |_| false), "agent");
assert_eq!(agent_id_for("…", |id| id == "agent"), "agent-2");