Nodes: Write Conversation Steps
A node is a function that represents one step in the conversation. Nodes can be sync or async - the graph engine handles both.
Signature
Every node function takes two arguments - state and ctx. The state object gives you attribute-style access to all collected values, while ctx provides communication helpers like ask(), say(), and the Extractor for data collection. Nodes can return an action (like Route, END, or Interrupt) to control what happens next.
# Async node
async def my_node(state: MyState, ctx: Context):
# state : attribute-style access to collected values
# ctx : context object for communication, extraction helpers, etc.
...
# Sync node
def greet(state: MyState, ctx: Context):
return Route("next")
state- AStateproxy over collected values. Access fields as attributes:state.name,state.income.ctx- TheContextobject. Providesask(),say(),Extractorand state access.
Accessing State
You can read and write state values inside any node using either direct attribute access on the state object or helper methods on ctx. Both approaches update the same underlying global state.
async def my_node(state: MyState, ctx: Context):
# Read a value
name = state.name # Returns None if not yet collected
# Write a value
state.income = 500000 # Directly set a state value
# Via context
ctx.get_state("name")
ctx.set_state("name", "Alice")
ctx.update_states({"name": "Alice", "income": 500000})
Got a Question? Ask us on discord

