Skip to content

[FEATURE] Pass invocation_state to edge condition call #1354

@afarntrog

Description

@afarntrog

Problem Statement

At this moment, condition function for edges has access to the graph state only, but can't access invocation state. This makes it very difficult to conditionally enable some nodes based on the invocation_state received in the graph invocation

Proposed Solution

Change the add_edge from:

def add_edge(
        self,
        from_node: str | GraphNode,
        to_node: str | GraphNode,
        condition: Callable[[GraphState], bool] | None = None,
    ) -> GraphEdge:

To:

def add_edge(
        self,
        from_node: str | GraphNode,
        to_node: str | GraphNode,
        condition: Callable[[GraphState, dict[str, Any] | None], bool] | None = None,
    ) -> GraphEdge:

To condition functions to look like:

def should_generate_first(state: GraphState,  invocation_state: dict[str, Any] | None = None) -> bool:

Use Case

This allow some nodes to be executed based on some input from the graph invocation.

Alternatives Solutions

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions