Expand description
§⚠️ DEPRECATED - llm-toolkit-expertise
This crate has been archived and integrated into llm-toolkit core.
Migration Path:
- Replace
llm_toolkit_expertise::*withllm_toolkit::agent::expertise::* - Context types are now in
llm_toolkit::context::{Priority, TaskHealth, ContextProfile} - All APIs remain the same, only the import paths have changed
Version Support:
- v0.2.0: Final release with deprecation notice
- v0.1.0: Original release
- No further updates will be published
§llm-toolkit-expertise (Archived)
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_description("Rust code review specialist")
.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);§Context-Aware Rendering
Phase 2 adds dynamic prompt rendering based on runtime context:
use llm_toolkit_expertise::{
Expertise, WeightedFragment, KnowledgeFragment,
RenderContext, ContextualPrompt, Priority, ContextProfile, TaskHealth,
};
// Create expertise with conditional fragments
let expertise = Expertise::new("rust-tutor", "1.0")
.with_fragment(
WeightedFragment::new(KnowledgeFragment::Text(
"You are a Rust tutor".to_string()
))
.with_context(ContextProfile::Always)
)
.with_fragment(
WeightedFragment::new(KnowledgeFragment::Text(
"Provide detailed explanations".to_string()
))
.with_context(ContextProfile::Conditional {
task_types: vec![],
user_states: vec!["beginner".to_string()],
task_health: None,
})
);
// Render with context
let beginner_context = RenderContext::new().with_user_state("beginner");
let prompt = expertise.to_prompt_with_render_context(&beginner_context);
// Includes both "Always" and "beginner" fragments
// Or use ContextualPrompt wrapper
let prompt = ContextualPrompt::from_expertise(&expertise, RenderContext::new())
.with_user_state("beginner")
.to_prompt();§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 render::ContextualPrompt;pub use render::RenderContext;pub use types::Expertise;pub use types::WeightedFragment;
Modules§
- context
- Context-related types for expertise fragments.
- fragment
- Knowledge fragment types and definitions.
- render
- Context-aware prompt rendering (Phase 2)
- 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