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.
§Errors
Returns SharedStateError::Timeout if the timeout expires.
Returns SharedStateError::InvalidTimeout if timeout is outside [1ms, 300s].
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more