Expand description
§llm-toolkit-expertise
Agent as Code v2: Graph-based composition system for LLM agent capabilities.
This library provides a flexible, composition-based approach to defining agent expertise through weighted knowledge fragments. Instead of inheritance hierarchies, expertise is built by composing independent fragments with priorities and contextual activation rules.
§Core Concepts
- Composition over Inheritance: Build agents like RPG equipment sets
- Weighted Fragments: Knowledge with priority levels (Critical/High/Normal/Low)
- Context-Driven: Dynamic behavior based on TaskHealth and context
§Example
use llm_toolkit_expertise::{
Expertise, WeightedFragment, KnowledgeFragment,
Priority, ContextProfile, TaskHealth,
};
let expertise = Expertise::new("code-reviewer", "1.0")
.with_tag("lang:rust")
.with_tag("role:reviewer")
.with_fragment(
WeightedFragment::new(KnowledgeFragment::Text(
"Always verify code compiles before review".to_string()
))
.with_priority(Priority::Critical)
)
.with_fragment(
WeightedFragment::new(KnowledgeFragment::Logic {
instruction: "Check for security issues".to_string(),
steps: vec![
"Scan for SQL injection vulnerabilities".to_string(),
"Check input validation".to_string(),
],
})
.with_priority(Priority::High)
.with_context(ContextProfile::Conditional {
task_types: vec!["security-review".to_string()],
user_states: vec![],
task_health: None,
})
);
// Generate prompt
let prompt = expertise.to_prompt();
println!("{}", prompt);
// Generate tree visualization
let tree = expertise.to_tree();
println!("{}", tree);
// Generate Mermaid graph
let mermaid = expertise.to_mermaid();
println!("{}", mermaid);§JSON Schema
This library supports JSON Schema generation for expertise definitions:
use llm_toolkit_expertise::dump_expertise_schema;
let schema = dump_expertise_schema();
println!("{}", serde_json::to_string_pretty(&schema).unwrap());Re-exports§
pub use context::ContextMatcher;pub use context::ContextProfile;pub use context::Priority;pub use context::TaskHealth;pub use fragment::Anchor;pub use fragment::KnowledgeFragment;pub use types::Expertise;pub use types::WeightedFragment;
Modules§
- context
- Context-related types for expertise fragments.
- fragment
- Knowledge fragment types and definitions.
- types
- Core expertise types and structures.
Functions§
- dump_
expertise_ schema - Generate JSON Schema for Expertise type
- save_
expertise_ schema - Save Expertise JSON Schema to a file