pub struct SharedState { /* private fields */ }Expand description
Thread-safe key-value store for parallel agent coordination.
Scoped to a single ParallelAgent::run() invocation. All sub-agents
share the same Arc<SharedState> instance.
§Example
use adk_core::SharedState;
use std::sync::Arc;
use std::time::Duration;
let state = Arc::new(SharedState::new());
// Agent A publishes a workbook handle
state.set_shared("workbook_id", serde_json::json!("wb-123")).await?;
// Agent B waits for the handle
let handle = state.wait_for_key("workbook_id", Duration::from_secs(30)).await?;Implementations§
Inserts a key-value pair. Notifies all waiters on that key.
§Errors
Returns SharedStateError::EmptyKey if key is empty.
Returns SharedStateError::KeyTooLong if key exceeds 256 bytes.
Returns the value for a key, or None if not present.
Sourcepub async fn wait_for_key(
&self,
key: &str,
timeout: Duration,
) -> Result<Value, SharedStateError>
pub async fn wait_for_key( &self, key: &str, timeout: Duration, ) -> Result<Value, SharedStateError>
Blocks until the key appears, or the timeout expires.
If the key already exists, returns immediately. A SharedState::set_shared
for the key that runs concurrently with this call is never missed: the waiter
registers for notification before each read of the key.
§Errors
Returns SharedStateError::Timeout if the timeout expires.
Returns SharedStateError::InvalidTimeout if timeout is outside [1ms, 300s].