AgenticGraph
nae.AgenticGraph ¶
AgenticGraph(state: type | None = None, start_node: Node | None = None, end_nodes: Node | set | list | tuple | None = None, name: str | None = None, checkpointer: Any = None, cache: Any = None, validate: bool = True, inputs: list | set | None = None, prompt_cache: bool = False, prompt_cache_key: str | None = None)
Bases: StateGraph
Compile nodes wired with the > DSL into a runnable LangGraph graph.
Hand it the start_node and end_nodes of a graph you built with the
> operator and it materializes and compiles a native LangGraph
StateGraph. The DSL it understands:
a > b > c— sequential chain (each node appends to the shared state).a > fanout(b, c) > d(ora > [b, c] > d) — parallel fan-out; the join nodedis deferred and runs once after both branches finish.worker.map("items") > collector— map-reduce:workerruns once per item ofstate["items"]via LangGraphSend, replies join intocollector.decision["choice"] > handler— conditional routing off aDecisionNode/ConditionNode.- subgraph composition — an
AgenticGraphmay itself be a node in a largerAgenticGraph(graph_0 > graph_1).
Build-time behavior: the schema is inferred (undeclared keys a node reads/writes
are auto-registered) so you rarely pass state=, and a forward dataflow
validator FAILS the build (GraphValidationError) if a node reads a key nothing
produces upstream. Run it with invoke / stream / ainvoke / astream.
Examples:
from nae import AgentNode, AgenticGraph
outline = AgentNode(llm=llm, node_prompt="Outline the answer.")
draft = AgentNode(llm=llm, node_prompt="Write a draft from the outline.")
polish = AgentNode(llm=llm, node_prompt="Polish the draft.")
outline > draft > polish
graph = AgenticGraph(start_node=outline, end_nodes={polish})
graph.invoke("Explain what a monad is.")
Initialize the AgenticGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
type | None
|
The state schema (a TypedDict). OPTIONAL — defaults to the
standard |
None
|
start_node
|
Node | None
|
The initial node in the graph |
None
|
end_nodes
|
Node | set | list | tuple | None
|
Set of nodes that represent terminal states |
None
|
checkpointer
|
Any
|
Optional LangGraph checkpointer (e.g. InMemorySaver).
Required for HumanNode interrupt/resume. When set, every invoke
must pass a config with a |
None
|
cache
|
Any
|
Optional LangGraph cache backend. Defaults to an InMemoryCache
when any node sets |
None
|
inputs
|
list | set | None
|
Keys you pass at |
None
|
validate
|
bool
|
When True (default), statically check that every key each
node reads is produced upstream/in the schema and every key it
writes is declared, FAILING the build (GraphValidationError) on a
hard error. Set False to skip (escape hatch). See |
True
|
prompt_cache
|
bool
|
Opt-in (default False). When True AND a node's model is
OpenAI, every model call passes a |
False
|
prompt_cache_key
|
str | None
|
The cache key to use verbatim for the whole run. When omitted, one key is generated per graph build and shared by every node, so all sibling/sequential calls land on the same cache. |
None
|
__call__ ¶
Process the current state through the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
AgenticState
|
Initial state, or a |
required |
config
|
dict | None
|
Optional LangGraph config, e.g.
|
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Updated state after processing through the graph |
__gt__ ¶
Wire this graph forward to one child, or fan out to several.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Node | list | Branch
|
A single node (sequential edge), or a list of nodes (parallel fan-out — each becomes a child). |
required |
Returns:
| Type | Description |
|---|---|
Node | Branch
|
The single child (chain building), or a |
Node | Branch
|
fan-out heads whose own |
ainvoke
async
¶
Async variant of invoke. Sync nodes run in LangGraph's threadpool.
See invoke for the full input/config contract.
compile ¶
compile(checkpointer=None, *, cache=None, store=None, interrupt_before=None, interrupt_after=None, debug=False)
Compile the built graph into a runnable LangGraph CompiledStateGraph.
Thin override of StateGraph.compile that keeps checkpointer as the
first positional argument for convenience; all other options
(cache, store, interrupt_before, interrupt_after, debug) pass
through unchanged. AgenticGraph.__init__ calls this for you, so you
rarely invoke it directly — the compiled result is stored on
self.compiled_graph and used by invoke / stream / ainvoke / astream.
invoke ¶
invoke(input: Any = _UNSET, /, *, message: str | list | None = None, config: dict | None = None, durability=None, **extra: Any) -> dict
Process an input through the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Any
|
A plain |
_UNSET
|
message
|
str | list | None
|
Keyword form of the str/list shorthand, e.g.
|
None
|
config
|
dict | None
|
Optional LangGraph config, e.g.
|
None
|
**extra
|
Any
|
Additional state keys to seed alongside the shorthand input,
e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
dict
|
Updated state after processing through the graph |
stream ¶
Stream graph execution, yielding updates as nodes complete.
Normalizes input/message like invoke (str/list/dict/Command +
**extra state keys), then passes through to the compiled graph's stream.
See invoke for the full input/config contract.
summary ¶
Print a Keras-model.summary()-style table of every node's reads,
writes, and available (must) keys (may`mustkeys suffixed?`).
validate ¶
Statically check state availability; returns a ValidationReport.
Raises nothing itself (the build path raises on errors). With
strict=True the returned report has its warnings promoted to errors.