Skip to main content

gadk_engine/workflow/
run_node.rs

1// Copyright 2026 Chris Olson
2// Portions derived from ADK-Go (https://github.com/google/adk-go), Copyright 2026 Google LLC.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! `run_node`: scheduling a child node from a dynamic node's body.
17
18use std::sync::Arc;
19
20use gadk_agent::{AgentError, Context};
21use serde_json::Value;
22
23use crate::error::WorkflowErrorKind;
24use crate::workflow::Node;
25use crate::workflow::scheduler::wf_error;
26
27/// The options of [`run_node`].
28#[derive(Clone, Default)]
29pub struct RunNodeOptions {
30    /// A stable run id instead of the per-child auto-counter; a repeated id
31    /// replays the cached output, and concurrent callers share one run.
32    pub run_id: Option<String>,
33    /// Runs the child on `<branch>.<name>@<run_id>`.
34    pub use_sub_branch: bool,
35    /// The child's output becomes the parent's output.
36    pub use_as_output: bool,
37    /// Replaces the base branch (empty = no override).
38    pub override_branch: Option<String>,
39    /// The child's isolation scope (empty = none).
40    pub isolation_scope: Option<String>,
41    /// The child's isolation scope is its node path.
42    pub isolation_scope_from_node_path: bool,
43    /// An unresolved long-running call pauses the parent.
44    pub raise_on_wait: bool,
45}
46
47/// Schedules `child` under the dynamic node whose context `ctx` is, and returns its output
48/// (`Value::Null` for none). Callers convert the value to their type.
49pub async fn run_node(
50    ctx: &Context,
51    child: Arc<dyn Node>,
52    input: Value,
53    opts: RunNodeOptions,
54) -> Result<Value, AgentError> {
55    let Some(ss) = ctx.sub_scheduler() else {
56        return Err(wf_error(WorkflowErrorKind::InvalidRunNodeContext, ""));
57    };
58    ss.run_node(Arc::new(child), input, Some(Arc::new(opts)))
59        .await
60}