Skip to content

Output Modifiers

Default Output

The DefaultOutputOutputs class allows you to set a default value for an action’s output.

If an action is referenced as a link directly, and it has a default output, the output will be used as the value of the link.

For example:

from aijson import DefaultOutputOutputs, register_action
class Outputs(DefaultOutputOutputs):
_default_output = "response"
response: str
name_character_count: int
@register_action
def my_action(name: str) -> Outputs:
return Outputs(
response="Hello, " + name + "!",
name_character_count=len(name),
)

Referencing the action as a link:

version: "0.1"
flow:
greet:
action: my_action
name: world
count:
action: llm
prompt: |
How good of a greeting is {{ greet }}

In the above flow, the prompt will be “How good of a greeting is Hello, world!?“.

greet.response and greet both map to “Hello, world!“.
greet.name_character_count maps to 5.

Cache Control

The CacheControlOutputs class allows you to control whether a specific output should be cached.

To disable caching for a specific run of the action, subclass CacheControlOutputs on the output object:

from aijson import CacheControlOutputs, register_action
class Outputs(CacheControlOutputs):
response: str
@register_action
def my_action(name: str) -> Outputs:
if name == "world":
# will not cache this result
return Outputs(
response="Hello, world!",
_cache=False,
)
# will cache this result
return Outputs(
response="Hello, " + name + "!"
)