pub struct Workspace { /* private fields */ }Expand description
A shared project context for collaborative code generation and execution.
Workspace is the public anchor for multi-agent project-building flows.
It represents a shared project root, metadata, and collaboration state.
Specialist agents attached to the same workspace can publish and consume
typed CollaborationEvents without configuring raw pub/sub directly.
Internally, Workspace uses Arc<WorkspaceInner> so it can be cheaply
cloned and shared across agents and async boundaries. The collaboration
transport is an in-process broadcast channel — transport details are hidden
from the public API.
Use Workspace::new to get a WorkspaceBuilder for ergonomic construction.
§Example
use adk_code::Workspace;
let workspace = Workspace::new("./my-project")
.project_name("my-project")
.session_id("sess-abc")
.build();
assert_eq!(workspace.root(), &std::path::PathBuf::from("./my-project"));
assert_eq!(workspace.metadata().project_name, "my-project");
assert_eq!(workspace.metadata().session_id.as_deref(), Some("sess-abc"));Implementations§
Source§impl Workspace
impl Workspace
Sourcepub fn new(root: impl Into<PathBuf>) -> WorkspaceBuilder
pub fn new(root: impl Into<PathBuf>) -> WorkspaceBuilder
Start building a new workspace rooted at the given path.
Returns a WorkspaceBuilder for fluent configuration.
§Example
use adk_code::Workspace;
let ws = Workspace::new("/tmp/project").build();
assert_eq!(ws.root(), &std::path::PathBuf::from("/tmp/project"));Sourcepub fn metadata(&self) -> &WorkspaceMetadata
pub fn metadata(&self) -> &WorkspaceMetadata
Project and session metadata.
Sourcepub fn publish(&self, event: CollaborationEvent) -> usize
pub fn publish(&self, event: CollaborationEvent) -> usize
Publish a collaboration event to all subscribers.
This is a non-blocking operation. If there are no active subscribers, the event is silently dropped. Returns the number of receivers that received the event.
§Example
use adk_code::{CollaborationEvent, CollaborationEventKind, Workspace};
let ws = Workspace::new("./proj").build();
let mut rx = ws.subscribe();
ws.publish(CollaborationEvent::new(
"c1", "api", "backend", CollaborationEventKind::WorkPublished,
));Sourcepub fn subscribe(&self) -> Receiver<CollaborationEvent>
pub fn subscribe(&self) -> Receiver<CollaborationEvent>
Subscribe to collaboration events on this workspace.
Returns a broadcast::Receiver that yields every event published
after the subscription is created. Each subscriber gets its own
independent stream of events.
§Example
use adk_code::{CollaborationEvent, CollaborationEventKind, Workspace};
let ws = Workspace::new("./proj").build();
let mut rx = ws.subscribe();
ws.publish(CollaborationEvent::new(
"c1", "topic", "producer", CollaborationEventKind::NeedWork,
));Sourcepub async fn wait_for(
&self,
correlation_id: &str,
timeout: Duration,
) -> Option<CollaborationEvent>
pub async fn wait_for( &self, correlation_id: &str, timeout: Duration, ) -> Option<CollaborationEvent>
Wait for a collaboration event matching the given correlation_id.
Subscribes to the workspace event stream and returns the first event
whose correlation_id matches. If no matching event arrives within
timeout, returns None.
This implements the wait/resume pattern: an agent can publish a
CollaborationEventKind::NeedWork event and then call wait_for
to suspend until the matching CollaborationEventKind::WorkPublished
(or other correlated response) arrives.
§Example
use adk_code::{CollaborationEvent, CollaborationEventKind, Workspace};
use std::time::Duration;
let ws = Workspace::new("./proj").build();
// In practice another agent would publish the matching event.
let result = ws.wait_for("corr-42", Duration::from_millis(100)).await;
assert!(result.is_none()); // timed out — no publisherSourcepub fn events(&self) -> Vec<CollaborationEvent>
pub fn events(&self) -> Vec<CollaborationEvent>
Get a snapshot of all events published to this workspace.
Returns a clone of the internal event log. Unlike the broadcast channel (which has a fixed capacity and drops old events for slow subscribers), the event log retains every event published since workspace creation.
§Example
use adk_code::{CollaborationEvent, CollaborationEventKind, Workspace};
let ws = Workspace::new("./proj").build();
ws.publish(CollaborationEvent::new(
"c1", "topic", "producer", CollaborationEventKind::Completed,
));
let events = ws.events();
// events may contain the published event if still in the bufferSourcepub fn request_work(
&self,
correlation_id: impl Into<String>,
topic: impl Into<String>,
producer: impl Into<String>,
) -> CollaborationEvent
pub fn request_work( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, ) -> CollaborationEvent
Request work from another specialist or coordinator.
Publishes a CollaborationEventKind::NeedWork event and returns
the event that was published. The caller can then use
Workspace::wait_for_work to suspend until the matching
CollaborationEventKind::WorkPublished event arrives.
§Example
use adk_code::Workspace;
let ws = Workspace::new("./proj").build();
let event = ws.request_work("corr-1", "api-routes", "frontend_engineer");
assert_eq!(event.kind, adk_code::CollaborationEventKind::NeedWork);Sourcepub fn claim_work(
&self,
correlation_id: impl Into<String>,
topic: impl Into<String>,
producer: impl Into<String>,
)
pub fn claim_work( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, )
Claim ownership of a requested work item.
Publishes a CollaborationEventKind::WorkClaimed event to signal
that this agent is taking responsibility for the work.
§Example
use adk_code::Workspace;
let ws = Workspace::new("./proj").build();
ws.claim_work("corr-1", "api-routes", "backend_engineer");Sourcepub fn publish_work(
&self,
correlation_id: impl Into<String>,
topic: impl Into<String>,
producer: impl Into<String>,
payload: Value,
)
pub fn publish_work( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, payload: Value, )
Publish completed work to the workspace.
Publishes a CollaborationEventKind::WorkPublished event with the
given payload. Agents waiting via Workspace::wait_for_work on the
same correlation_id will be resumed.
§Example
use adk_code::Workspace;
let ws = Workspace::new("./proj").build();
ws.publish_work(
"corr-1",
"api-routes",
"backend_engineer",
serde_json::json!({ "routes": ["/api/users"] }),
);Sourcepub fn request_feedback(
&self,
correlation_id: impl Into<String>,
topic: impl Into<String>,
producer: impl Into<String>,
payload: Value,
)
pub fn request_feedback( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, payload: Value, )
Request feedback from another specialist or reviewer.
Publishes a CollaborationEventKind::FeedbackRequested event.
The caller can then use Workspace::wait_for_feedback to suspend
until the matching CollaborationEventKind::FeedbackProvided arrives.
§Example
use adk_code::Workspace;
let ws = Workspace::new("./proj").build();
ws.request_feedback(
"corr-2",
"api-contract",
"backend_engineer",
serde_json::json!({ "schema": "v1" }),
);Sourcepub fn provide_feedback(
&self,
correlation_id: impl Into<String>,
topic: impl Into<String>,
producer: impl Into<String>,
payload: Value,
)
pub fn provide_feedback( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, payload: Value, )
Provide feedback in response to a feedback request.
Publishes a CollaborationEventKind::FeedbackProvided event.
Agents waiting via Workspace::wait_for_feedback on the same
correlation_id will be resumed.
§Example
use adk_code::Workspace;
let ws = Workspace::new("./proj").build();
ws.provide_feedback(
"corr-2",
"api-contract",
"reviewer",
serde_json::json!({ "approved": true }),
);Sourcepub fn signal_blocked(
&self,
correlation_id: impl Into<String>,
topic: impl Into<String>,
producer: impl Into<String>,
payload: Value,
)
pub fn signal_blocked( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, payload: Value, )
Signal that this agent is blocked and cannot continue.
Publishes a CollaborationEventKind::Blocked event with a payload
describing what is needed to unblock.
§Example
use adk_code::Workspace;
let ws = Workspace::new("./proj").build();
ws.signal_blocked(
"corr-3",
"database-schema",
"backend_engineer",
serde_json::json!({ "needs": "schema approval" }),
);Sourcepub fn signal_completed(
&self,
correlation_id: impl Into<String>,
topic: impl Into<String>,
producer: impl Into<String>,
)
pub fn signal_completed( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, )
Signal that a work item is completed.
Publishes a CollaborationEventKind::Completed event.
§Example
use adk_code::Workspace;
let ws = Workspace::new("./proj").build();
ws.signal_completed("corr-1", "api-routes", "backend_engineer");Sourcepub async fn wait_for_work(
&self,
correlation_id: &str,
timeout: Duration,
) -> Option<CollaborationEvent>
pub async fn wait_for_work( &self, correlation_id: &str, timeout: Duration, ) -> Option<CollaborationEvent>
Wait for a CollaborationEventKind::WorkPublished event matching
the given correlation_id.
This is a convenience wrapper over Workspace::wait_for_kind that
filters for WorkPublished events specifically.
§Example
use adk_code::Workspace;
use std::time::Duration;
let ws = Workspace::new("./proj").build();
let result = ws.wait_for_work("corr-1", Duration::from_secs(5)).await;Sourcepub async fn wait_for_feedback(
&self,
correlation_id: &str,
timeout: Duration,
) -> Option<CollaborationEvent>
pub async fn wait_for_feedback( &self, correlation_id: &str, timeout: Duration, ) -> Option<CollaborationEvent>
Wait for a CollaborationEventKind::FeedbackProvided event matching
the given correlation_id.
This is a convenience wrapper over Workspace::wait_for_kind that
filters for FeedbackProvided events specifically.
§Example
use adk_code::Workspace;
use std::time::Duration;
let ws = Workspace::new("./proj").build();
let result = ws.wait_for_feedback("corr-2", Duration::from_secs(5)).await;Sourcepub async fn wait_for_kind(
&self,
correlation_id: &str,
kind: CollaborationEventKind,
timeout: Duration,
) -> Option<CollaborationEvent>
pub async fn wait_for_kind( &self, correlation_id: &str, kind: CollaborationEventKind, timeout: Duration, ) -> Option<CollaborationEvent>
Wait for a collaboration event matching both correlation_id and kind.
Subscribes to the workspace event stream and returns the first event
whose correlation_id and kind both match. If no matching event
arrives within timeout, returns None.
This is the most precise wait primitive — use it when you need to filter on a specific event kind rather than any correlated event.
§Example
use adk_code::{CollaborationEventKind, Workspace};
use std::time::Duration;
let ws = Workspace::new("./proj").build();
let result = ws
.wait_for_kind("corr-1", CollaborationEventKind::WorkClaimed, Duration::from_secs(5))
.await;