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/ainvokeresult. - print_
result_ with_ options - Like
print_resultbut 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_streambut with explicit control over thinking display. - response_
text - Extract the assistant’s text reply from an
invoke_llm/stream_llmresult. - stream_
llm - Stream LLM tokens via StreamWriter and return the final state update.