Skip to main content

Module node_helpers

Module node_helpers 

Source
Expand description

Helper functions for building graph nodes with minimal boilerplate.

These utilities eliminate the manual JSON ↔ typed conversion that makes Rust examples verbose compared to Python’s langchain-core.

Functions§

ask_json
Ask the LLM a single prompt and get back a parsed JSON value.
extract_messages
Extract typed messages from a graph state JSON, with an optional system prompt prepended.
get_i64
Get a field from state as i64, defaulting to 0.
get_str
Get a field from state as a string, defaulting to “”.
invoke_llm
Invoke an LLM and return a state update.
invoke_llm_with_config
Invoke an LLM with a custom config and return a state update.
llm_response_to_json
Convert a model response into a state update JSON.
parse_json_response
Strip markdown code fences (```json … ```) and parse the inner JSON.
print_result
Print the last AI message from an invoke / ainvoke result.
print_result_with_options
Like print_result but with explicit control over thinking display.
print_stream
Stream graph execution and print tokens to stdout in real-time.
print_stream_with_options
Like print_stream but with explicit control over thinking display.
response_text
Extract the assistant’s text reply from an invoke_llm / stream_llm result.
stream_llm
Stream LLM tokens via StreamWriter and return the final state update.