An existing application embeds Gesang behind its own authenticated routes. The application verifies the current session and maps its stable issuer and subject to a Gesang owner. The host supplies resource policy, provisioning, and custody. Chopin owns execution, goals, conversations, and command output.
Use Rust 1.100 or later and commit the consuming application's lockfile. Pin the crates used by the host to the same release tag.
[dependencies]
gesang-api = { git = "https://github.com/CodePrometheus/gesang.git", tag = "v0.1.0-rc1" }
gesang-core = { git = "https://github.com/CodePrometheus/gesang.git", tag = "v0.1.0-rc1" }
gesang-host = { git = "https://github.com/CodePrometheus/gesang.git", tag = "v0.1.0-rc1" }
uuid = "1.29.2"Gesang pins both Chopin Rust dependencies to
91251b63ed9beb2842b0d8bdaa7a07b792401902 from v0.7.0-rc2. If your host
uses a Chopin Rust crate directly, use the same Git URL and revision so Cargo
resolves shared types from one source. The Chopin host guide
covers the native storage binding and execution service.
Cargo can use the committed SQLx metadata. Set SQLX_OFFLINE=true for the
Gesang build if your environment provides an unrelated DATABASE_URL.
- Create a
gesang_core::Storefrom a PostgreSQL pool and a protectedPayloadKey. RunStore::migratebefore accepting work. The store checks PostgreSQL durability settings before applying its embedded migrations. - Implement
InstanceProvideragainst the host's resource backend andEngineConnectoragainst its trusted Chopin endpoint. The provider reconciles the actual instance and workspace. Before a replacement writer starts, it must independently confirm that the previous writer stopped or lost storage access. - Construct the shared
EngineAdapterandKernel. Configure the operation timeouts and recovery intervals for your deployment. Run the host's delivery, wake, and retirement loops throughdispatch_one,wake_one, andretire_one. - Mount
ControlPlane::routeron the protected runtime callback listener. Supply the actualControlPolicyand separate credential material. First-store initialization and execution key release are explicitly enabled throughwith_initialization_custodyandwith_execution_custody. For protected commands, useJobAuthoritywith the host'sJobPolicyand the Chopin worker. See the custody protocol.
use std::sync::Arc;
use gesang_core::{InstanceProvider, Kernel, RuntimePolicy, Store};
use gesang_host::{EngineAdapter, EngineConnectionPolicy, EngineConnector};
fn assemble(
store: Store,
instances: Arc<dyn InstanceProvider>,
connector: Arc<dyn EngineConnector>,
runtime_policy: RuntimePolicy,
connection_policy: EngineConnectionPolicy,
) -> gesang_core::Result<(Kernel, Arc<EngineAdapter>)> {
let engine = Arc::new(EngineAdapter::new(
store.clone(),
connector,
connection_policy,
)?);
let kernel = Kernel::new(store, instances, engine.clone(), runtime_policy)?;
Ok((kernel, engine))
}Derive VerifiedIdentity from the verified session on the server, and use
Store::bind_owner only in the application's authorized enrollment flow.
For ordinary requests, look up the existing owner with Store::find_owner.
The application's permission checks should limit the agent and the available
workspace capabilities before a command is submitted. Use the scoped task
grant for tool execution.
use gesang_api::{CommandReceipt, CommandSubmission};
use gesang_core::{Error, Kernel, VerifiedIdentity};
use uuid::Uuid;
async fn submit_for_owner(
kernel: &Kernel,
identity: &VerifiedIdentity,
agent_id: Uuid,
submission: &CommandSubmission,
) -> gesang_core::Result<CommandReceipt> {
let owner = kernel
.store()
.find_owner(identity)
.await?
.ok_or(Error::Forbidden)?;
kernel.submit(&owner, agent_id, submission).await
}Generate the submission's request_id before sending it and retain it across
reconnections. Use Store::receipt with the same owner and request ID if the
submission response is lost. The receipt records delivery state. For the result,
use Kernel::snapshot with the original owner, agent, and goal ID. For a live
view, use EngineAdapter::observe_goal with the host-verified runtime. Retain
Chopin's original operation IDs and output cursors when reading command output.
Use the API contracts to map these calls to your application's routes. Run the deployment checks in the target environment before enabling live model and workspace access.