antigravity_sdk_rust/lib.rs
1//! # Google Antigravity Rust SDK
2//!
3//! The Google Antigravity SDK is a Rust library for building AI agents powered by Antigravity and Gemini.
4//! It provides a secure, scalable, and stateful infrastructure layer that abstracts the agentic loop,
5//! letting you focus on what your agent *does* rather than how it runs.
6//!
7//! ## Core Architecture Components
8//!
9//! - **[`Agent`](crate::agent::Agent)**: High-level manager of the agent lifecycle. It handles process discovery,
10//! tool registration, hook dispatch, and starts the communication backend.
11//! - **[`Conversation`](crate::conversation::Conversation)**: Stateful wrapper around a connection that
12//! tracks full step history, accumulates token usage metadata, and processes stream chunks.
13//! - **[`Connection`](crate::connection::Connection)**: Core trait abstracted to communicate with the
14//! underlying harness (e.g. standard subprocess IPC or `WebSockets`).
15//! - **[`Hook`](crate::hooks::Hook)**: Lifecycle hooks allowing you to observe or modify agent transitions
16//! and execute custom policies.
17//! - **[`Policy`](crate::policy::Policy)**: Middleware structures enforcing security rules (e.g. restricting files inside workspace
18//! via `workspace_only` or prompting command runs via `confirm_run_command`).
19//! - **[`Tool`](crate::tools::Tool)**: Custom function capabilities written in Rust and exposed to the model.
20//! - **[`Trigger`](crate::triggers::Trigger)**: Asynchronous workers triggered at agent start.
21//!
22//! ## Quickstart Example
23//!
24//! ```no_run
25//! use antigravity_sdk_rust::agent::{Agent, AgentConfig};
26//! use antigravity_sdk_rust::policy;
27//!
28//! #[tokio::main]
29//! async fn main() -> Result<(), anyhow::Error> {
30//! let mut config = AgentConfig::default();
31//! // Allow all tools (e.g., file system, shell access)
32//! config.policies = Some(vec![policy::allow_all()]);
33//!
34//! let mut agent = Agent::new(config);
35//! agent.start().await?;
36//!
37//! let response = agent.chat("Say hello").await?;
38//! println!("Agent: {}", response.text);
39//!
40//! agent.stop().await?;
41//! Ok(())
42//! }
43//! ```
44
45pub mod proto {
46 #[allow(
47 warnings,
48 clippy::all,
49 clippy::pedantic,
50 clippy::nursery,
51 clippy::unwrap_used,
52 clippy::expect_used
53 )]
54 pub mod localharness {
55 // Include the prost-generated code
56 include!(concat!(env!("OUT_DIR"), "/antigravity.localharness.rs"));
57 // Include the pbjson-generated serde implementations
58 include!(concat!(
59 env!("OUT_DIR"),
60 "/antigravity.localharness.serde.rs"
61 ));
62 }
63}
64
65pub mod agent;
66pub mod connection;
67pub mod conversation;
68pub mod hooks;
69#[cfg(not(target_arch = "wasm32"))]
70pub mod local;
71#[cfg(any(target_arch = "wasm32", test))]
72pub mod wasm;
73
74pub mod policy;
75pub mod tools;
76pub mod triggers;
77pub mod types;
78
79/// Helper to spawn asynchronous tasks in a target-agnostic manner.
80pub fn spawn_task<F>(future: F)
81where
82 F: std::future::Future<Output = ()> + Send + 'static,
83{
84 #[cfg(not(target_arch = "wasm32"))]
85 {
86 tokio::spawn(future);
87 }
88 #[cfg(target_arch = "wasm32")]
89 {
90 any_spawner::Executor::spawn_local(future);
91 }
92}