Skip to content
Blog

Parameter Resolution in Workflow Nodes: ctx, node_input, and State Injection

How ADK resolves a workflow node's function arguments from node_input, ctx, and session state, including parameter_binding modes and coercion rules.

Published on • November 30, 2026

AI Assistant

A workflow node is usually a plain Python function, and that is the appeal: no framework base class, no callback protocol, just def lookup(node_input: str): .... The appeal hides a question the framework still has to answer — when your function declares def charge_card(node_input: Order, attempts: int, ctx: Context), where does each argument come from? Guess wrong and you get a WorkflowDataError in production, a silently defaulted attempts, or a value read from state that a previous turn left behind.

ADK resolves node parameters with a small, explicit set of rules: the incoming edge payload (node_input), the execution context (ctx), and session state — selected by the node’s parameter_binding mode and validated by type coercion. This post walks through that resolution pipeline so you can predict exactly what your function receives.

1. The three data channels of a workflow node

Inside a graph-based workflow, nodes pass data through events, and ADK distinguishes three fields:

ChannelPurposeReaches the next node?
outputThe value handed to the successor nodeYes — becomes its node_input
message / contentA user-facing responseNo — rendered for the user only
stateData persisted across nodes in the sessionReadable anywhere, not edge-bound

The design rule that follows is simple: if only the next node needs the value, pass it along the edge as output. Use state when a value must outlive the run — or be read by a tool, a callback, or an {instruction} template.

from google.adk import Event

def my_function_node(node_input: str):
    output_value = node_input.upper()
    return Event(output=output_value)   # next node receives "THE RESULT"

A node may yield multiple events for progress, but only one event per execution may carry output — that single value is what the successor gets. yield (or return) without a parameter forwards None.

2. node_input: the edge payload

node_input is the argument carrying the predecessor’s output. For a function node it is passed through directly, then coerced to the type hint you declared:

class CityTime(BaseModel):
    time_info: str
    city: str

def lookup_time_function(node_input: str) -> CityTime:
    """Returns structured data; the successor sees a dict/model, not a string."""
    return CityTime(time_info="10:10 AM", city=node_input)

Coercion runs through Pydantic’s TypeAdapter, so the practical conversions are:

  • dict → BaseModel when the annotation is a Pydantic model
  • list[dict] → list[BaseModel], dict[K, dict] → dict[K, BaseModel]
  • types.Content → str when the annotation expects str
  • anything else is validated against the annotation

You can make the contract explicit rather than inferred by attaching schemas: input_schema on the node validates what arrives, output_schema validates what leaves. On a FunctionNode, both are inferred from your type hints when possible — node_input’s annotation becomes the input schema, the return annotation the output schema.

3. ctx: the context parameter

Declare a Context parameter and the framework injects the live execution context instead of looking it up anywhere:

from google.adk import Context, Event

async def task_attempt_node(node_input, attempts: int):
    yield Event(state={"attempts": attempts + 1})

def audit_step(node_input: str, ctx: Context):
    print(ctx.node_path)          # where am I in the graph
    ctx.state["last_step"] = "audit"
    return Event(output=node_input)

ctx is detected by the function’s signature — the parameter typed as Context is bound to the context object and is exempt from every other lookup rule. Two consequences matter:

  • State writes through ctx.state are tracked. Changes made while the function runs are captured in ctx.actions.state_delta and attached to the emitted event, so the mutation is committed with the event rather than silently lost.
  • ctx never collides with data. A state key literally named ctx will not shadow the injected parameter, because the context parameter is resolved first and skipped during value lookup.

4. parameter_binding: state mode vs. node_input mode

This is the part most tutorials skip, and it is where surprises come from. Every FunctionNode has a parameter_binding field with exactly two values:

from google.adk.workflow import node

@node(parameter_binding="state")        # the default
def audit_step(node_input, attempts: int):   # attempts is read from ctx.state
    ...
  • 'state' (default): the node_input parameter (if declared) is passed the edge payload directly; every other non-context parameter is looked up in ctx.state by name.
  • 'node_input': all non-context parameters are looked up in the node_input dict, and input_schema / output_schema are inferred from the function signature. This is the mode used when the node acts as an agent’s tool.

The default mode explains a class of otherwise inexplicable errors. Given:

def charge_card(node_input: Order, attempts: int):
    ...

attempts is not the number of attempts on the edge — it is state["attempts"]. And if that key is missing and the parameter has no default, resolution raises:

WorkflowDataError: Missing value for parameter "attempts" of function
"charge_card". It was not found in state and has no default value.

Three practical rules follow:

  1. Give injected parameters defaults (attempts: int = 0) unless a missing value should genuinely fail the run.
  2. Write the state key before you read it — typically in an earlier node with Event(state={...}), or via ctx.state.
  3. Declare node_input explicitly when you want the edge payload, and use other parameter names only when you intend a state lookup.

Resolution is followed by coercion: each resolved value is adapted to its type annotation (dict → model, Content → str, and so on) before your function body runs, so annotations are load-bearing in both directions.

5. State scopes and validation

Session state is a lightweight key-value store, and its key prefixes decide lifetime:

PrefixScope
app:Shared across all users and sessions of the app
user:Tied to the user, shared across their sessions
temp:Discarded after the current invocation ends
(none)Persists for the lifetime of the session

You can declare a state_schema on the node — a Pydantic model of expected keys and types. When set, ctx.state mutations are validated at runtime against it; child nodes inherit the parent’s schema unless they declare their own, and prefixed keys (app:, user:, temp:) bypass validation.

Two limits worth respecting: state should not carry large payloads (use artifacts or a database tool for those), and Event.state deltas are the tracked way to write — mutating a Session object fetched from the SessionService bypasses event tracking.

6. Agent nodes: resolution moves to the instruction

When the successor is an Agent, the struct arrives as its input and the agent reads fields through its input_schema:

city_report_agent = Agent(
    name="city_report_agent",
    model="gemini-flash-latest",
    input_schema=CityTime,
    instruction="You receive a CityTime with time_info and city fields. "
                "State the time in that city in one sentence.",
)

Two templating syntaxes exist here, and conflating them is the classic bug:

  • {Class.field} reads a field from this node’s input.
  • <Class.field from source_node> reads a field from a named predecessor’s output.
  • {state_key} reads session state — a plain {CityTime.time_info} placeholder is left in the prompt verbatim if you expected it to reach into the input object.

To template a value into an instruction as state, write it first (output_key or Event(state=...)) and reference it as {time_info}.

7. Checklist

  • Every parameter’s source is intentional: node_input for edge data, ctx for the runtime, named parameters for state keys.
  • State-sourced parameters have defaults, or you have proven the key is written earlier.
  • You know your node’s parameter_binding mode — the default is 'state', not 'node_input'.
  • Type annotations are accurate; they drive TypeAdapter coercion and schema inference.
  • Edge payloads travel as output; only cross-node concerns go to state.
  • Agent instructions use {Class.field} for input fields and {state_key} for state — never interchangeably.
  • Large data lives in artifacts or a database, not in session state.

Parameter resolution is where a declarative graph meets real Python. Once you can name the source of every argument — edge, context, or state — node functions stop being magic and become ordinary, testable functions with a documented contract.

References