Skip to main content

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;
26//!
27//! #[tokio::main]
28//! async fn main() -> Result<(), anyhow::Error> {
29//!     let agent = Agent::builder()
30//!         .allow_all()
31//!         .build();
32//!     let agent = agent.start().await?;
33//!
34//!     let response = agent.chat("Say hello").await?;
35//!     println!("Agent: {}", response.text);
36//!
37//!     agent.stop().await?;
38//!     Ok(())
39//! }
40//! ```
41
42pub mod proto {
43    #[allow(
44        warnings,
45        clippy::all,
46        clippy::pedantic,
47        clippy::nursery,
48        clippy::unwrap_used,
49        clippy::expect_used
50    )]
51    pub mod localharness {
52        // Include the prost-generated code
53        include!(concat!(env!("OUT_DIR"), "/antigravity.localharness.rs"));
54        // Include the pbjson-generated serde implementations
55        include!(concat!(
56            env!("OUT_DIR"),
57            "/antigravity.localharness.serde.rs"
58        ));
59    }
60}
61
62pub mod agent;
63pub mod connection;
64pub mod conversation;
65pub mod hooks;
66#[cfg(not(target_arch = "wasm32"))]
67pub mod local;
68#[cfg(any(target_arch = "wasm32", test))]
69pub mod wasm;
70
71pub mod policy;
72pub mod tools;
73pub mod triggers;
74pub mod types;
75
76/// Helper to spawn asynchronous tasks in a target-agnostic manner.
77pub fn spawn_task<F>(future: F)
78where
79    F: std::future::Future<Output = ()> + Send + 'static,
80{
81    #[cfg(not(target_arch = "wasm32"))]
82    {
83        tokio::spawn(future);
84    }
85    #[cfg(target_arch = "wasm32")]
86    {
87        any_spawner::Executor::spawn_local(future);
88    }
89}