# Data

```lua
-- aip run ask-agent.aip
-- NOTE: Replace `ask-agent` with your agent name

-- Compute prompt file path (in ".aipack/.prompt/" by soft convention)
local suffix = input or "prompt"
local prompt_path = ".aipack/.prompt/" .. CTX.AGENT_FILE_STEM .. "-" .. suffix .. ".md"

-- Initialize prompt file if needed
local initial_prompt = '```toml\n#!meta\n# model = "gpt-4.1-mini"\n```'
initial_prompt = initial_prompt .. "\n\nPLACEHOLDER - Remove this line with your prompt, and press 'r' in terminal"
initial_prompt = initial_prompt .. '\n\n====\n> AI Answer will be here.\n\n'

local prompt_file = aip.file.ensure_exists(prompt_path, initial_prompt)

-- Load Prompt file
prompt_file = aip.file.load(prompt_file.path)

-- Split content and make normalize to nil if empty
local first_part, second_part = aip.text.split_first(prompt_file.content, "====\n")
first_part  = first_part:find("%S") and first_part or nil

-- Extract the Eventual Meta
local meta, prompt = aip.md.extract_meta(first_part)

-- Skip if prompt does not start with PLACEHOLDER
print("CONTENT... \n".. prompt)
if prompt == nil or prompt:match("^%s*PLACEHOLDER") then
    return aip.flow.skip("Enter your prompt in file: '" .. prompt_path .. "'")
end

-- Remove the lines starting with '>' (considered as info only by this agent)
_lines, second_part = aip.text.extract_line_blocks(second_part or "", { starts_with = ">", extrude = "content"})
second_part = second_part:find("%S") and second_part or nil

print("second part: " .. (second_part or "no second part"))

-- Return Data for next stages
return aip.flow.data_response({
    data = {
        prompt_path = prompt_path,
        prompt      = prompt,
        first_part  = first_part,
        second_part = second_part        
    },
    options = aip.agent.extract_options(meta)
})
```

# System

You are an agent that answers any question the user might have.

- Make sure to be concise.
- If you need bullet points, use `-`
- When using bullet points, leave empty lines between each point.
- Do not use long dashes to separate sentence parts.
- Do not use 'delve'

# Instruction

{{#if data.first_part}}
{{data.prompt}}
{{/if}}

{{#if data.second_part}}
<PREVIOUS_ANSWER>
Here is the previous answer you gave me for more about my request above: 
{{data.second_part}}
</PREVIOUS_ANSWER>
{{/if}}

# Output

```lua
-- Extract AI Answer
local response = ai_response and ai_response.content or "> AI Answer here"

-- Build new prompt file content
local content = data.first_part or ""
content = aip.text.trim_end(content) .. "\n\n====\n"

if ai_response then
    local first, second = aip.text.split_first(ai_response.info, "| Model: ")
    content = content .. "> " .. first .. "\n> Model: " .. second .. "\n"
end

content = content .. "\n" .. response

-- Save new content in prompt file
aip.file.save(data.prompt_path, content)

-- Return value
return "AI Answer: " .. aip.text.truncate(response, 32, "...")
```
