Value Declarations
In AI JSON, inputs to actions can be:
- links to other actions’ outputs (
link
) - external variables (
var
) - jinja templates (
text
) - lambda functions (
lambda
) - environment variables (
env
)
Link: link
A way to reference the output of another action.
Linked actions will always run before the action that references them.
my_action: action: some_action an_input: "foo"another_action: action: some_action an_input: link: my_action
If the output of an action is a pydantic model, you can reference its attributes:
my_action: action: some_action an_input: "foo"another_action: action: some_action an_input: link: my_action.an_output_attribute
Variable: var
A way to pass external values directly to action inputs.
my_action: action: some_action an_input: var: my_variable
When running the flow in code, you can pass the value of my_variable
as a keyword argument:
from aijson import Flow
async def main(): flow = Flow.from_file("flow.ai.yaml") flow = flow.set_vars(my_variable="foo") await flow.run()
Text: text
A way to evaluate jinja templates.
my_action: action: some_action an_input: text: "Hello, {{ name }}"
If a template variable ({{ name }}
above) corresponds to another action’s output, it is treated as a link. Otherwise, it is treated as a variable.
If an action’s input is a string, you may omit the text
declaration; it will be evaluated as a jinja string by default:
my_action: action: some_action a_string_input: "Hello, {{ name }}"
Note, AI JSON jinja templates are evaluated in a native jinja environment.
Lambda: lambda
A way to evaluate a python expression.
my_action: action: some_action an_input: lambda: "x + 1"
If a variable (x
above) corresponds to another action’s output, it is treated as a link. Otherwise, it is treated as a variable.
Environment: env
A way to reference environment variable values.
my_action: action: some_action an_input: env: MY_ENV_VAR