pub trait RunnableChild: Child {
// Required method
fn run(&mut self, input: Value) -> ChildResult;
}Expand description
A Child that can actively execute work.
Extends Child with the ability to run tasks.
Used for SubAgents, Workers, and Skills that need to
perform actual work rather than just respond to signals.
§Architecture
Component (Manager)
│
│ spawn_child()
▼
RunnableChild (Worker)
│
│ run(input)
▼
ChildResult§Signal Handling
During run(), the child should periodically check for
signals and return ChildResult::Aborted if a Veto/Cancel
is received.
§Example
use orcs_component::{Child, RunnableChild, ChildResult, Identifiable, SignalReceiver, Statusable, Status};
use orcs_event::{Signal, SignalResponse};
use serde_json::{json, Value};
struct Worker {
id: String,
status: Status,
}
impl Identifiable for Worker {
fn id(&self) -> &str { &self.id }
}
impl SignalReceiver for Worker {
fn on_signal(&mut self, signal: &Signal) -> SignalResponse {
if signal.is_veto() {
self.status = Status::Aborted;
SignalResponse::Abort
} else {
SignalResponse::Handled
}
}
fn abort(&mut self) { self.status = Status::Aborted; }
}
impl Statusable for Worker {
fn status(&self) -> Status { self.status }
}
impl Child for Worker {}
impl RunnableChild for Worker {
fn run(&mut self, input: Value) -> ChildResult {
self.status = Status::Running;
// Do work...
let result = json!({"input": input, "processed": true});
self.status = Status::Idle;
ChildResult::Ok(result)
}
}Required Methods§
Sourcefn run(&mut self, input: Value) -> ChildResult
fn run(&mut self, input: Value) -> ChildResult
Execute work with the given input (synchronous).
§Arguments
input- Input data for the work (JSON value)
§Returns
ChildResult::Ok(value)on successChildResult::Err(error)on failureChildResult::Abortedif interrupted by signal
§Contract
- Should update status to
Runningat start - Should update status to
IdleorCompletedon success - Should periodically check for signals during long operations