-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path10-permissions.rs
More file actions
51 lines (45 loc) · 1.37 KB
/
10-permissions.rs
File metadata and controls
51 lines (45 loc) · 1.37 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
// Example 10: Permissions
//
// Read-only agent with AllowedTools restriction.
// Can only use Read, Glob, Grep — no write or execute.
//
// Run: cargo run --example 10-permissions
use open_agent_sdk::{Agent, AgentOptions, SDKMessage};
use open_agent_sdk::types;
#[tokio::main]
async fn main() {
println!("--- Example 10: Permissions ---");
let mut agent = Agent::new(AgentOptions {
max_turns: Some(10),
allowed_tools: Some(vec![
"Read".to_string(),
"Glob".to_string(),
"Grep".to_string(),
]),
..Default::default()
})
.await
.unwrap();
let (mut rx, handle) = agent
.query("Review the code in src/lib.rs for best practices and potential improvements.")
.await;
while let Some(event) = rx.recv().await {
match event {
SDKMessage::Assistant { message, .. } => {
let text = types::extract_text(&message);
if !text.is_empty() {
print!("{}", text);
}
}
SDKMessage::Result { cost_usd, .. } => {
println!("\n\n--- Done (${:.4}) ---", cost_usd);
}
SDKMessage::Error { message } => {
eprintln!("Error: {}", message);
}
_ => {}
}
}
handle.await.unwrap();
agent.close().await;
}