aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/run-agent.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/run-agent.py')
-rwxr-xr-xscripts/run-agent.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/scripts/run-agent.py b/scripts/run-agent.py
index 1239753..a3f3ec5 100755
--- a/scripts/run-agent.py
+++ b/scripts/run-agent.py
@@ -50,8 +50,8 @@ def parse_argv(this_file_name):
def setup_env(root_dir, agent_name):
- os.environ["LLM_ROOT_DIR"] = root_dir
load_env(os.path.join(root_dir, ".env"))
+ os.environ["LLM_ROOT_DIR"] = root_dir
os.environ["LLM_AGENT_NAME"] = agent_name
os.environ["LLM_AGENT_ROOT_DIR"] = os.path.join(root_dir, "agents", agent_name)
os.environ["LLM_AGENT_CACHE_DIR"] = os.path.join(root_dir, "cache", agent_name)
@@ -85,20 +85,25 @@ def run(agent_path, agent_func, agent_data):
raise Exception(f"Not module function '{agent_func}' at '{agent_path}'")
value = getattr(mod, agent_func)(**agent_data)
- dump_value(value)
+ return_to_llm(value)
-def dump_value(value):
+def return_to_llm(value):
if value is None:
return
+ if "LLM_OUTPUT" in os.environ:
+ writer = open(os.environ["LLM_OUTPUT"], "w")
+ else:
+ writer = sys.stdout
+
value_type = type(value).__name__
if value_type in ("str", "int", "float", "bool"):
- print(value)
+ writer.write(value)
elif value_type == "dict" or value_type == "list":
value_str = json.dumps(value, indent=2)
assert value == json.loads(value_str)
- print(value_str)
+ writer.write(value_str)
if __name__ == "__main__":