Skip to main content

coral_rs/
lib.rs

1pub mod agent;
2pub mod agent_loop;
3pub mod api;
4pub mod claim_manager;
5pub mod codegen;
6pub mod completion_evaluated_prompt;
7pub mod error;
8pub mod mcp_server;
9pub mod repeating_prompt_stream;
10
11pub use rig;
12pub use rmcp;
13pub use serde;
14use std::io;
15use tracing::Level;
16use tracing_subscriber::fmt::writer::MakeWriterExt;
17use tracing_subscriber::layer::SubscriberExt;
18use tracing_subscriber::util::{SubscriberInitExt, TryInitError};
19
20///
21/// Helper function that omits verbose logging information when CORAL_RUNTIME_ID is set.
22/// This is useful for developing Coral agents because during dev-mode development, extra logging
23/// information is desired, but when the agents are being orchestrated (during application
24/// development), the extra information is duplicated with the server's logging information
25pub fn init_tracing() -> Result<(), TryInitError> {
26    if std::env::var("CORAL_RUNTIME_ID").is_ok() {
27        let stderr = tracing_subscriber::fmt::layer()
28            .with_target(false)
29            .with_level(false)
30            .without_time()
31            .with_writer(
32                io::stderr
33                    .with_min_level(Level::ERROR)
34                    .with_max_level(Level::WARN),
35            );
36
37        let stdout = tracing_subscriber::fmt::layer()
38            .with_target(false)
39            .with_level(false)
40            .without_time()
41            .with_writer(
42                io::stdout
43                    .with_min_level(Level::INFO)
44                    .with_max_level(Level::INFO),
45            );
46
47        tracing_subscriber::registry()
48            .with(stdout)
49            .with(stderr)
50            .try_init()
51    } else {
52        let stderr = tracing_subscriber::fmt::layer().with_writer(
53            io::stderr
54                .with_min_level(Level::ERROR)
55                .with_max_level(Level::WARN),
56        );
57
58        let stdout = tracing_subscriber::fmt::layer().with_writer(
59            io::stdout
60                .with_min_level(Level::INFO)
61                .with_max_level(Level::INFO),
62        );
63
64        tracing_subscriber::registry()
65            .with(stdout)
66            .with(stderr)
67            .try_init()
68    }
69}