# Actions An action is a system command or custom code run. It is used to retrieve or process data. An action can be: - A system command - A Python script - A Javascript script Note: actions are not listed as independent commands. They are used in workflows and custom commands. ## System actions To define an action that runs a system command we use the YAML format: ```yaml cmd: ls ``` The action's output will be the result of the command. To use parameters: ```yaml name: ocr cmd: /home/ggg/me/path/to/some/app/.venv/bin/python args: - "/home/ggg/me/path/to/some/app/ocr.py" - "-x" - "--a-param" - "0" ``` All the parameters are strings. It is possible to run an action with some additional command line parameters. To run the above action with parameters: ```bash lm ocr some_img.jpg ``` ## Python actions To declare a `hello.py` action: ```python import sys print("args:", sys.argv) print("Hello world") ``` Run the action: ```bash lm hello param1 "params two" ``` The output of the action will be the printed statements. For example for an OCR agent just print the output to pass the result to the eventual next step of a workflow. ## Javascript actions To create a quick action in a `dist/actions` folder use a `.js` extension for your action: ```js async function action(args, options) { const data = doSomething(); if (somethingIsWrong) { throw new Error("something went wrong") } // pass the result data for the next node return data } export { action } ``` System commands can be used in Javascript actions. Import `execute` from `@agent-smith/core`: ```js import { execute } from "@agent-smith/core"; async function action(args, options) { const data = await execute("cat", args); return { fileContent: data }; } export { action }; ``` Next: Workflows