-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.rs
More file actions
82 lines (74 loc) · 2.49 KB
/
basic.rs
File metadata and controls
82 lines (74 loc) · 2.49 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
//! Basic example of using the Everruns SDK
use everruns_sdk::{
AgentCapabilityConfig, CreateAgentRequest, CreateSessionRequest, Error, Everruns,
};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Error> {
// Initialize client from environment
let client = Everruns::from_env()?;
// Create an agent with current_time capability
let agent = client
.agents()
.create_with_options(
CreateAgentRequest::new(
"example-assistant-rs",
"You are a helpful assistant for examples.",
)
.capabilities(vec![AgentCapabilityConfig::new("current_time")]),
)
.await?;
println!("Created agent:");
println!(" Name: {}", agent.name);
println!(" ID: {}", agent.id);
println!(" Status: {:?}", agent.status);
println!(" Capabilities: {:?}", agent.capabilities);
println!(" Created: {}", agent.created_at);
// Create a session (agent is optional)
let session = client
.sessions()
.create_with_options(
CreateSessionRequest::new()
.agent_id(&agent.id)
.capabilities(vec![AgentCapabilityConfig::new("current_time")]),
)
.await?;
println!("Created session:");
println!(" ID: {}", session.id);
println!(" Harness: {}", session.harness_id);
println!(" Agent: {:?}", session.agent_id);
println!(" Status: {:?}", session.status);
println!(" Created: {}", session.created_at);
// Send a message that uses the current_time capability
let _message = client
.messages()
.create(
&session.id,
"What time is it right now? Generate a short joke about the current time.",
)
.await?;
println!("Sent message");
// Stream events
let mut stream = client.events().stream(&session.id);
while let Some(event) = stream.next().await {
match event {
Ok(e) => {
println!("Event: {} - {}", e.event_type, e.id);
if matches!(
e.event_type.as_str(),
"output.message.completed" | "turn.completed" | "turn.failed"
) {
break;
}
}
Err(e) => {
eprintln!("Error: {}", e);
break;
}
}
}
// Clean up
client.sessions().delete(&session.id).await?;
client.agents().delete(&agent.id).await?;
Ok(())
}