-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathspecialized_agents.rs
More file actions
147 lines (127 loc) Β· 5.9 KB
/
Copy pathspecialized_agents.rs
File metadata and controls
147 lines (127 loc) Β· 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! Specialized Agents Example
//!
//! This example demonstrates how to use the new SummarizationAgent and ChatAgent
//! that leverage the generic LLM interface instead of OpenRouter-specific code.
use terraphim_multi_agent::{
test_utils, ChatAgent, ChatConfig, SummarizationAgent, SummarizationConfig, SummaryStyle,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("π€ Specialized Agents Example - Generic LLM Interface");
println!("====================================================");
// Example 1: SummarizationAgent
println!("\nπ Example 1: SummarizationAgent");
println!("=================================");
let base_agent = test_utils::create_test_agent().await?;
let config = SummarizationConfig {
max_summary_words: 100,
summary_style: SummaryStyle::Brief,
include_quotes: false,
focus_areas: vec!["technology".to_string(), "innovation".to_string()],
};
let summarization_agent = SummarizationAgent::new(base_agent, Some(config)).await?;
println!(
"β
Created SummarizationAgent with provider: {}",
summarization_agent.llm_client().provider()
);
let sample_article = r#"
Artificial Intelligence (AI) has revolutionized numerous industries over the past decade.
From healthcare to finance, AI technologies are being deployed to automate processes,
enhance decision-making, and improve efficiency. Machine learning algorithms can now
diagnose diseases with remarkable accuracy, while natural language processing has enabled
sophisticated chatbots and virtual assistants. The rapid advancement in AI has also
raised important questions about ethics, privacy, and the future of work. As we move
forward, it's crucial to develop AI systems that are not only powerful but also
responsible and aligned with human values.
"#;
println!(
"π Original article length: {} characters",
sample_article.len()
);
match summarization_agent.summarize(sample_article).await {
Ok(summary) => {
println!("β
Generated summary ({} characters):", summary.len());
println!(" {}", summary);
}
Err(e) => {
println!("β Summarization failed: {}", e);
println!("π‘ Note: This requires Ollama to be running with gemma3:270m model");
}
}
// Example 2: ChatAgent
println!("\n㪠Example 2: ChatAgent");
println!("========================");
let base_agent2 = test_utils::create_test_agent().await?;
let chat_config = ChatConfig {
max_context_messages: 10,
system_prompt: Some(
"You are a helpful AI assistant specialized in technology topics.".to_string(),
),
temperature: 0.7,
max_response_tokens: 200,
enable_context_summarization: true,
};
let mut chat_agent = ChatAgent::new(base_agent2, Some(chat_config)).await?;
println!(
"β
Created ChatAgent with provider: {}",
chat_agent.llm_client().provider()
);
// Start a conversation
let session_id = chat_agent.start_new_session();
println!("π Started new chat session: {}", session_id);
let questions = [
"What is Rust programming language?",
"How does Rust compare to Python for system programming?",
"What are the main benefits of using Rust?",
];
for question in questions.iter() {
println!("\nπ€ User: {}", question);
match chat_agent.chat(question.to_string()).await {
Ok(response) => {
println!("π€ Assistant: {}", response);
if let Some(session) = chat_agent.get_chat_history() {
println!(" πΎ Session has {} messages", session.messages.len());
}
}
Err(e) => {
println!("β Chat failed: {}", e);
println!("π‘ Note: This requires Ollama to be running with gemma3:270m model");
break;
}
}
}
// Example 3: Multi-document summarization
println!("\nπ Example 3: Multi-Document Summarization");
println!("==========================================");
let documents = vec![
(
"AI in Healthcare",
"AI is transforming healthcare through improved diagnostics, personalized treatment plans, and drug discovery. Machine learning models can analyze medical images with high accuracy and identify patterns that human doctors might miss.",
),
(
"AI in Finance",
"The financial sector leverages AI for fraud detection, algorithmic trading, risk assessment, and customer service automation. AI systems can process vast amounts of financial data in real-time to make split-second decisions.",
),
(
"AI Ethics",
"As AI becomes more prevalent, questions about bias, fairness, transparency, and accountability become increasingly important. Developing ethical AI requires careful consideration of how these systems impact different groups of people.",
),
];
match summarization_agent.summarize_multiple(&documents).await {
Ok(consolidated_summary) => {
println!("β
Consolidated summary:");
println!(" {}", consolidated_summary);
}
Err(e) => {
println!("β Multi-document summarization failed: {}", e);
println!("π‘ Note: This requires Ollama to be running with gemma3:270m model");
}
}
println!("\nπ Specialized agents example completed!");
println!("π‘ All agents use the generic LLM interface, supporting multiple providers:");
println!(" - Ollama (local models like gemma3:270m)");
println!(" - OpenAI (with API key)");
println!(" - Anthropic (with API key)");
println!(" - Future providers can be easily added");
Ok(())
}