windlass.agent.graph¶
graph
¶
LangGraph-backed agent runtime.
When you need more than a loop — conditional routing, subgraphs, explicit state
machines, LangGraph's own checkpointers — build the agent with .graph().
This runtime compiles the same configuration into a real StateGraph and
hands it to you via :meth:LangGraphRuntime.native_graph.
Install with::
pip install "windlass[agent]"
The Level 3 promise in full::
agent = Windlass.agent().llm("openai").tool(search).graph()
graph = agent.native_graph() # the uncompiled StateGraph
graph.add_node("review", review_fn)
graph.add_edge("tools", "review")
graph.add_conditional_edges("review", route_fn, {"retry": "agent", "done": END})
agent.recompile() # pick up the changes
Example
from windlass import Windlass # doctest: +SKIP agent = Windlass.agent().llm("openai").graph() # doctest: +SKIP agent.run("hello").output # doctest: +SKIP
LangGraphRuntime
¶
Bases: AgentRuntime
An agent whose execution is a compiled LangGraph state machine.
Behaves exactly like :class:~windlass.agent.runtime.AgentRuntime — same
constructor, same run/stream/resume — but the loop is a graph you
can inspect, extend and visualise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Everything :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
Note
Passing checkpointer enables both savers: LangGraph's own keeps the
graph state, and the Windlass one keeps the snapshot that makes
:meth:~windlass.agent.runtime.AgentRuntime.resume behave identically
across the two runtimes.
Note
The graph is compiled lazily on first run. After mutating the graph
returned by :meth:native_graph, call :meth:recompile so the change
takes effect.
Source code in src\windlass\agent\graph.py
native_graph
¶
Return the uncompiled StateGraph for direct manipulation.
Returns:
| Type | Description |
|---|---|
Any
|
The LangGraph |
Any
|
already wired. |
Example
graph = agent.native_graph() # doctest: +SKIP graph.add_node("audit", audit_fn) # doctest: +SKIP agent.recompile() # doctest: +SKIP
Source code in src\windlass\agent\graph.py
compiled_graph
¶
recompile
¶
Recompile after mutating the graph.
Returns:
| Type | Description |
|---|---|
Any
|
The freshly compiled graph. |
arun
async
¶
arun(
prompt: Any,
*,
thread_id: str | None = None,
max_iterations: int | None = None,
**llm_kwargs: Any
) -> AgentResponse
Run the compiled graph to completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
Any
|
A string, a message, or a full transcript. |
required |
thread_id
|
str | None
|
Conversation thread, also used as LangGraph's thread key. |
None
|
max_iterations
|
int | None
|
Override for the recursion limit. |
None
|
**llm_kwargs
|
Any
|
Accepted for signature parity; graph nodes use the model's configured defaults. |
{}
|
Returns:
| Type | Description |
|---|---|
AgentResponse
|
The answer, transcript, per-step trace and aggregate usage. |
Raises:
| Type | Description |
|---|---|
MaxIterationsExceeded
|
When the recursion limit is hit. |
InterruptedError_
|
When execution paused before a tool node. |
AgentError
|
When graph execution fails. |
Source code in src\windlass\agent\graph.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
astream
async
¶
astream(
prompt: Any, *, thread_id: str | None = None, **llm_kwargs: Any
) -> AsyncIterator[StreamEvent]
Stream graph execution.
LangGraph streams at node granularity rather than token granularity, so you receive one text event per completed assistant turn plus tool-call events. For token-level streaming use the built-in runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
Any
|
A string, a message, or a full transcript. |
required |
thread_id
|
str | None
|
Conversation thread. |
None
|
**llm_kwargs
|
Any
|
Accepted for signature parity. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[StreamEvent]
|
class: |
Source code in src\windlass\agent\graph.py
describe
¶
Return a JSON-safe description, including the graph's node names.
Source code in src\windlass\agent\graph.py
draw
¶
Return a Mermaid diagram of the compiled graph.
Returns:
| Type | Description |
|---|---|
str
|
Mermaid source, ready to paste into documentation. |
Raises:
| Type | Description |
|---|---|
AgentError
|
When the installed LangGraph cannot render diagrams. |