Variables

ReasonChip supports dynamic variables that you can define, reuse, and resolve across your entire pipeline. These variables help make workflows clean, reusable, and data-driven.

Defining Variables

You can define variables in two main ways: A DeclareTask, or directly in a task.


- name: "Declare example"
  declare:
    greeting: "Hello"
    is_active: True

- name: "Prepare message"
  variables:
    text: "Welcome, {{ user_name }}"
  chip: chatbot.say
  params:
    message: text
	

Referencing Variables

You can use variables in two ways:

  • Bare namesgreeting
  • Interpolated strings{{ user.name }}

Bare variables are supported in most task fields: params, loop, when, etc.

Example using bare name:


	- name: "Send greeting"
	method_name: chatbot.say
	params:
	message: greeting
	

Example using interpolation inside a string:


	- name: "Compose greeting"
	vars:
	greeting: "Hello, {{ user.name }}!"
	

Recursive Resolution

Variables can reference other variables, and ReasonChip will resolve them recursively:


variables:
  a: b
  b: c
  c: 42
  # Result: a == 42
	

Full Variable Flow Example


- name: "Declare context"
  declare:
    name: Elvis
    greeting: "Hello, {{ name }}"

- name: "Send message"
  chip: chatbot.send
  params:
    message: greeting

Advanced Access

ReasonChip supports nested resolution across dicts, objects, and attributes:

  • user.email – nested object
  • data['status'] – dict-style access
  • profile.age – object attribute access

Python Expressions in {{ ... }}

Expressions inside {{ ... }} are evaluated using standard Python syntax, with access to the current variable context. This means you can use methods, arithmetic, and indexing:


- name: "Custom message"
vars:
user: { name: "Elvis", age: 42 }

- name: "Say message"
method_name: chatbot.say
params:
message: "User {{ user.name.upper() }} is {{ user.age + 1 }} years old"
	

You can use any valid Python operation that works within the safe vobj context (your variables, safely exposed).

Examples:

  • {{ name.upper() }} → "ELVIS"
  • {{ price * quantity }} → numeric calculation
  • {{ user.get('email', 'not set') }} → dict fallback

Built-ins and external libraries are not available—only your variables are exposed to keep evaluation secure and deterministic.

Notes

  • Bare names are preferred in structured fields (e.g. params, when).
  • {{ ... }} is best used for inline string construction or complex expressions.
  • Variables are scoped: task-scoped variables override inherited ones.
  • Recursive resolution prevents loops and supports complex dependency chains.
  • Missing or invalid references are handled gracefully with clear errors.

© 2025 South Patron LLC. All rights reserved.

AI everywhere.