Hello World - Save Output
Now that we have our first Hello World agent, we can add an # Output
stage to save the AI's output to a file.
Agent
We don't have to quit the terminal; we can just edit the hello.aip
file as follows:
# Instruction
Can you say "Hello World" in 5 different languages?
# Output
```lua
local content = ai_response.content
aip.file.save("ai-response.md", content)
return "All good"
```
You can just press r
in the same terminal if you haven't quit.
(Or just run the agent aip run hello
- the .aip
is optional.)
Result
- A new file,
ai-response.md
, with something like this:
Sure! Here is "Hello World" in five different languages:
1. Spanish: Hola Mundo
2. French: Bonjour le monde
3. German: Hallo Welt
4. Japanese: こんにちは世界 (Konnichiwa Sekai)
5. Arabic: مرحبا بالعالم (Marhaban bil 'aalam)
Explanation
- We added an
# Output
stage with a Lua logic code block into ourhello.aip
agent. - The
aip
command line executed this Lua block, and because it was after the AI Execution, it put anai_response
object in the context. - The
ai_response
object has the.content
property with the content of the response. - Then, in the Lua block, we call the aipack utility file save function
aip.file.save
with the file path"ai-response.md"
(relative to the workspace directory) and the content from theai_response
.