This document explains how to pass parameters to Astonish agents, allowing for more automated workflows.
Astonish now supports passing parameters directly to agents, which can be used to pre-populate input fields that would normally require user interaction. This is particularly useful for:
- Automating agent execution in scripts
- Integrating agents into larger workflows
- Running agents with predefined inputs
You can pass parameters to an agent using the -p or --param flag with key=value format. You can use multiple flags for multiple parameters:
astonish agents run simple_question_answer_loop -p get_question="Who was Albert Einstein" -p continue_loop=noYou can use shell expansion to read file content as a parameter value:
astonish agents run simple_question_answer_loop -p get_question="$(<question.txt)" -p continue_loop=noThis reads the content of question.txt and passes it as the value for the get_question parameter.
You can use environment variables as parameter values:
# Set an environment variable
export QUESTION="Who was Albert Einstein"
# Use it in the command
astonish agents run simple_question_answer_loop -p get_question="$QUESTION" -p continue_loop=noParameters are specified in key=value format where:
- Keys are the node names defined in the agent's YAML file
- Values are the values you want to assign to those nodes' output fields
For example, if your agent has an input node with:
- name: get_topic
type: input
prompt: "What topic would you like to write about?"
output_model:
user_request: strYou can pass a parameter with the key get_topic to pre-populate this node's output:
-p get_topic="Artificial Intelligence"
When a parameter is provided for an input node:
- The node will check if there's a parameter with its name in the parameters dictionary
- If there is, it will use that value instead of prompting the user
- The prompt will still be displayed to show what question would have been asked
- The agent will continue execution as if the user had provided the input
If a parameter is not provided for an input node, the agent will prompt the user for input as usual.
Consider this simple agent:
description: Simple Agent to Respond to User Questions in a Loop
nodes:
- name: get_question
type: input
prompt: |
What is your question?
output_model:
question: str
- name: answer_question
type: llm
system: |
You are a helpful assistant.
prompt: |
Answer the following question: "{question}"
output_model:
answer: str
user_message:
- answer
- name: continue_loop
type: input
prompt: |
Do you want to continue asking questions?
output_model:
continue: str
options:
- "yes"
- "no"
flow:
- from: START
to: get_question
- from: get_question
to: answer_question
- from: answer_question
to: continue_loop
- from: continue_loop
edges:
- to: get_question
condition: "lambda x: x['continue'] == 'yes'"
- to: END
condition: "lambda x: x['continue'] == 'no'"You would call it like this:
astonish agents run simple_question_answer_loop -p get_question="Who was Albert Einstein" -p continue_loop=no