aixplain.v2.graph
from aixplain import AgentNode, Condition, ConditionDict, ConditionalNode, Edge, EdgeDict, Graph, GraphDict, InspectorNode, LLMNode, Node, RawNode, RetryPolicy, RetryPolicyDict, ScriptNode, StaticGraphStrategy, StaticGraphStrategyDict, ToolNode
Portable static graph definitions for aiXplain v2 agents.
Copyright 2022 The aiXplain SDK authors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
RetryPolicyDict Objects
class RetryPolicyDict(TypedDict)
The dict form of RetryPolicy.
ConditionDict Objects
class ConditionDict(TypedDict)
The dict form of Condition.
EdgeDict Objects
class EdgeDict(_EdgeRequired)
The dict form of Edge.
StaticGraphStrategyDict Objects
class StaticGraphStrategyDict(TypedDict)
The dict form of StaticGraphStrategy.
GraphDict Objects
class GraphDict(_GraphRequired)
The dict form of Graph; nodes is a list of nodes or the wire map of id to node dict.
RetryPolicy Objects
@dataclass
class RetryPolicy()
Retry settings applied by the static graph executor.
validate
def validate() -> None
Validate retry limits accepted by the backend.
to_dict
def to_dict(validate: bool = True) -> Dict[str, Any]
Serialize using the engine's canonical snake_case contract.
from_dict
@classmethod
def from_dict(cls,
value: Union["RetryPolicy", RetryPolicyDict],
strict: bool = True) -> "RetryPolicy"
Deserialize a retry policy; strict=False ignores unknown keys.
Condition Objects
@dataclass(frozen=True)
class Condition()
A portable edge condition evaluated against graph state.
__post_init__
def __post_init__() -> None
Validate the backend's structured edge-condition contract.
equals
@classmethod
def equals(cls, key: str, value: Any) -> "Condition"
Match when a state value equals value.
not_equals
@classmethod
def not_equals(cls, key: str, value: Any) -> "Condition"
Match when a state value does not equal value.
greater_than
@classmethod
def greater_than(cls, key: str, value: Any) -> "Condition"
Match when a state value is greater than value.
greater_than_or_equal
@classmethod
def greater_than_or_equal(cls, key: str, value: Any) -> "Condition"
Match when a state value is greater than or equal to value.
less_than
@classmethod
def less_than(cls, key: str, value: Any) -> "Condition"
Match when a state value is less than value.
less_than_or_equal
@classmethod
def less_than_or_equal(cls, key: str, value: Any) -> "Condition"
Match when a state value is less than or equal to value.
is_true
@classmethod
def is_true(cls, key: str) -> "Condition"
Match a boolean true state value.
is_false
@classmethod
def is_false(cls, key: str) -> "Condition"
Match a boolean false state value.
to_dict
def to_dict() -> Dict[str, Any]
Serialize the condition to the backend/engine contract.
from_dict
@classmethod
def from_dict(cls,
value: Union["Condition", ConditionDict],
strict: bool = True) -> "Condition"
Deserialize a structured edge condition; strict=False keeps one the SDK cannot validate.
Node Objects
@dataclass
class Node()
Common configuration shared by all portable graph nodes.
__post_init__
def __post_init__() -> None
Assign and validate the graph-local identifier.
id
@property
def id() -> str
Return the graph-local node ID.
validate
def validate() -> None
Validate node-specific configuration.
to_dict
def to_dict(validate: bool = True) -> Dict[str, Any]
Serialize the node to the engine's canonical contract.
from_dict
@classmethod
def from_dict(cls,
value: Mapping[str, Any],
node_id: Optional[str] = None,
strict: bool = True) -> "Node"
Build the typed node named by value["type"].
With strict=False a node the SDK cannot model or validate comes back as a RawNode.
LLMNode Objects
@dataclass
class LLMNode(Node)
A single model call in a static graph.
validate
def validate() -> None
Validate model generation settings.
ToolNode Objects
@dataclass
class ToolNode(Node)
A registered tool invocation.
validate
def validate() -> None
Require the engine registry name for the tool.
AgentNode Objects
@dataclass
class AgentNode(Node)
A registered sub-agent invocation.
validate
def validate() -> None
Require the engine registry name for the sub-agent.
ScriptNode Objects
@dataclass
class ScriptNode(Node)
Sandboxed Python source executed as a graph step.
validate
def validate() -> None
Require source and sandboxing for backend-authored graphs.
InspectorNode Objects
@dataclass
class InspectorNode(Node)
A registered inspector check.
validate
def validate() -> None
Validate inspector configuration.
ConditionalNode Objects
@dataclass
class ConditionalNode(Node)
A sandboxed expression that writes a boolean routing value.
validate
def validate() -> None
Require a sandboxed expression.
RawNode Objects
@dataclass
class RawNode(Node)
A fetched node the SDK does not model, kept verbatim so the graph saves back unchanged.
to_dict
def to_dict(validate: bool = True) -> Dict[str, Any]
Return the node exactly as the backend sent it.
Edge Objects
@dataclass
class Edge()
A directed graph edge with an optional portable condition.
__post_init__
def __post_init__() -> None
Coerce a dict condition and check the endpoints.
source_id
@property
def source_id() -> str
Return the source node ID.
target_id
@property
def target_id() -> str
Return the target node ID.
to_dict
def to_dict() -> Dict[str, Any]
Serialize the edge.
from_dict
@classmethod
def from_dict(cls,
value: Union["Edge", EdgeDict],
strict: bool = True) -> "Edge"
Deserialize an edge; strict=False ignores unknown keys and keeps unvalidated conditions.
StaticGraphStrategy Objects
@dataclass
class StaticGraphStrategy()
Execution settings stored alongside an agent graph.
validate
def validate() -> None
Validate strategy settings accepted by the platform backend.
to_dict
def to_dict(validate: bool = True) -> Dict[str, Any]
Serialize static graph strategy settings.
from_dict
@classmethod
def from_dict(cls,
value: Union["StaticGraphStrategy", StaticGraphStrategyDict],
strict: bool = True) -> "StaticGraphStrategy"
Deserialize strategy settings; strict=False ignores unknown keys and skips validation.
Graph Objects
@dataclass
class Graph()
A validated, portable static execution graph.
__post_init__
def __post_init__() -> None
Coerce dict nodes and edges into their typed forms.
entry_point_id
@property
def entry_point_id() -> str
Return the entry-point node ID.
validate
def validate() -> None
Validate graph structure before it is sent to the platform.
to_dict
def to_dict(validate: bool = True) -> Dict[str, Any]
Serialize the graph to the backend/engine wire contract.
from_dict
@classmethod
def from_dict(cls,
value: Union["Graph", GraphDict],
strict: bool = True) -> "Graph"
Build a graph from its dict form.
strict=True (caller input) rejects unknown keys and validates. strict=False (a backend
response) ignores unknown keys, keeps unmodeled nodes as RawNode, and skips validation:
the backend is authoritative for what it already stored.