Skip to main content

SubgraphSpec

Struct SubgraphSpec 

Source
pub struct SubgraphSpec<Outer: WorkflowState, Inner: WorkflowState, M: MergeStrategy<Inner>, L: StateLens<Outer, Inner>> {
    pub graph: Arc<Graph<Inner, M>>,
    pub lens: L,
    pub max_steps: usize,
    /* private fields */
}
Expand description

Subgraph Builder 描述 — 强类型,包含 Graph + Lens。

§泛型参数

  • Outer — 外层 State 类型(如 WorkflowState)
  • Inner — 内层 State 类型(如 AgentState)
  • M — MergeStrategy 实现(用于 Graph)
  • L — StateLens 实现,用于状态投影

§使用方式

let spec = SubgraphSpec::new(agent_graph, AgentLens);
let compiled: CompiledSubgraph<WorkflowState> = spec.compile();

Fields§

§graph: Arc<Graph<Inner, M>>

内层 Graph — Arc 共享,与 AgentBuilder::build() 返回类型一致(D10)。

§lens: L

状态投影器

§max_steps: usize

最大执行步数

Implementations§

Source§

impl<Outer, Inner, M, L> SubgraphSpec<Outer, Inner, M, L>
where Outer: 'static + WorkflowState, Inner: 'static + WorkflowState, M: 'static + MergeStrategy<Inner>, L: 'static + StateLens<Outer, Inner>,

Source

pub fn new(graph: Arc<Graph<Inner, M>>, lens: L) -> Self

创建新的 SubgraphSpec。

§参数
  • graph — 内层 Graph(Arc 共享,与 AgentBuilder::build() 返回类型一致)
  • lens — 状态投影器
§示例
let agent_graph = AgentBuilder::new(model).tools([...]).build();
let spec = SubgraphSpec::new(agent_graph, AgentLens);
// agent_graph 仍然是 Arc<Graph<...>>,可直接传入,无需 clone
Source

pub fn max_steps(self, max: usize) -> Self

设置最大执行步数。

Source

pub fn project<'a>(&self, outer: &'a mut Outer) -> &'a mut Inner

通过 Lens 投影状态。

从外层 State 投影出内层 State 的可变引用。

Source

pub fn compile(self) -> CompiledSubgraph<Outer>

编译为 CompiledSubgraph — 类型擦除 Inner/Lens/M。

Trait Implementations§

Source§

impl<Outer: WorkflowState, Inner, M, L> StateProjector<Outer> for SubgraphSpec<Outer, Inner, M, L>
where Inner: 'static + WorkflowState, M: 'static + MergeStrategy<Inner>, L: 'static + StateLens<Outer, Inner>,

Source§

fn execute<'a>( &'a self, outer: &'a mut Outer, stream: Option<Arc<dyn StreamSink>>, cancel: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<(), GraphError>> + Send + 'a>>

执行 Subgraph — 投影状态 + 递归执行内层 Graph。

§执行流程
  1. 通过 Lens 投影出内层 State(&mut Inner
  2. 创建内层 ExecutionEngine(借用 &mut Inner
  3. 调用 graph.run_inline()
  4. inner_engine drop → 借用释放 → outer 可继续使用
Source§

fn graph_name(&self) -> &str

内层 Graph 的名称。
Source§

fn node_count(&self) -> usize

内层 Graph 的节点数(用于评估是否值得内联)。

Auto Trait Implementations§

§

impl<Outer, Inner, M, L> !RefUnwindSafe for SubgraphSpec<Outer, Inner, M, L>

§

impl<Outer, Inner, M, L> !UnwindSafe for SubgraphSpec<Outer, Inner, M, L>

§

impl<Outer, Inner, M, L> Freeze for SubgraphSpec<Outer, Inner, M, L>
where L: Freeze,

§

impl<Outer, Inner, M, L> Send for SubgraphSpec<Outer, Inner, M, L>

§

impl<Outer, Inner, M, L> Sync for SubgraphSpec<Outer, Inner, M, L>

§

impl<Outer, Inner, M, L> Unpin for SubgraphSpec<Outer, Inner, M, L>
where L: Unpin, Outer: Unpin,

§

impl<Outer, Inner, M, L> UnsafeUnpin for SubgraphSpec<Outer, Inner, M, L>
where L: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more