use llm_toolkit::agent::Payload;
use llm_toolkit::intent::expandable::{Expandable, Selectable, SelectionRegistry};
#[derive(Debug, Clone)]
enum ToolAction {
FileRead { path: String },
FileWrite { path: String, content: String },
Calculate { expression: String },
WebSearch { query: String },
}
impl Expandable for ToolAction {
fn expand(&self) -> Payload {
match self {
ToolAction::FileRead { path } => Payload::from(format!(
"Read the contents of the file at path: {}\nReturn the file contents.",
path
)),
ToolAction::FileWrite { path, content } => Payload::from(format!(
"Write the following content to file at path: {}\n\nContent:\n{}\n\nConfirm when done.",
path, content
)),
ToolAction::Calculate { expression } => Payload::from(format!(
"Calculate the result of: {}\nReturn only the numeric result.",
expression
)),
ToolAction::WebSearch { query } => Payload::from(format!(
"Search the web for: {}\nReturn a summary of the top 3 results.",
query
)),
}
}
}
impl Selectable for ToolAction {
fn selection_id(&self) -> &str {
match self {
ToolAction::FileRead { .. } => "file_read",
ToolAction::FileWrite { .. } => "file_write",
ToolAction::Calculate { .. } => "calculate",
ToolAction::WebSearch { .. } => "web_search",
}
}
fn description(&self) -> &str {
match self {
ToolAction::FileRead { .. } => "Read contents from a file",
ToolAction::FileWrite { .. } => "Write content to a file",
ToolAction::Calculate { .. } => "Perform mathematical calculations",
ToolAction::WebSearch { .. } => "Search the web for information",
}
}
}
fn main() {
println!("=== Expandable and Selectable Basic Example ===\n");
let mut registry = SelectionRegistry::new();
registry.register(ToolAction::FileRead {
path: "/tmp/example.txt".to_string(),
});
registry.register(ToolAction::FileWrite {
path: "/tmp/output.txt".to_string(),
content: "Hello, World!".to_string(),
});
registry.register(ToolAction::Calculate {
expression: "2 + 2".to_string(),
});
registry.register(ToolAction::WebSearch {
query: "Rust programming".to_string(),
});
println!("Registered {} actions\n", registry.len());
let prompt_section = registry.to_prompt_section();
println!("Prompt section for LLM:");
println!("{}", prompt_section);
println!();
println!("=== Simulating Action Selection ===\n");
let selected_id = "calculate";
println!("LLM selected: {}", selected_id);
if let Some(action) = registry.get(selected_id) {
println!("Action description: {}", action.description());
let expanded = action.expand();
println!("\nExpanded prompt:");
println!("{}", expanded.to_text());
} else {
println!("Action not found!");
}
println!("\n=== Example Complete ===");
}