Tutorial

Collecting User Input

Pause your agent mid-run, ask the user a question, and feed their answer straight back into the next prompt — all with a single @effect input. The agent can ask questions too.

Margarita
1
Ask the user with @effect input
@effect input pauses execution, prints a prompt to the terminal, and waits for the user to type a response. The => arrow captures their answer into a variable — here, userTheme.
input.mgx
@effect input "Choose a workspace theme (pick one):\n• Light\n• Dark\n• System (follow OS)" => userTheme
2
Use the answer in the next prompt
Once the user hits Enter, userTheme holds their response. Inject it into a << >> block with ${userTheme} just like any other variable — the LLM sees the actual value.
input.mgx
@effect input "Choose a workspace theme (pick one):\n• Light\n• Dark\n• System (follow OS)" => userTheme

// ${userTheme} is now whatever the user typed
<<
The user chose the ${userTheme} theme.
Write a two-sentence description of what that experience looks and feels like.
>>

@effect run
3
Chain questions — and let the agent ask too
Call @effect input as many times as you need before the first LLM call. You can also instruct the agent to ask a clarifying question itself — Margarita surfaces the agent's question as an input prompt exactly the same way.
input.mgx
// Gather inputs up front
@effect input "What is your name?" => userName
@effect input "Which programming language do you work in most?" => userLanguage
@effect input "Experience level? (beginner / intermediate / expert)" => userLevel

<<
Write a personalised learning plan for ${userName},
a ${userLevel} ${userLanguage} developer.
Keep it to three bullet points.
Then ask the user one follow-up question to refine the plan
further and store it into `plan` variable
>>

@effect run

// The agent's follow-up question surfaces as an input prompt
@effect input "How long should the summary be?:" => userFollowUp

<<
Summarize the ${plan} and write a conclusion
in the length that the user specified here: ${userFollowUp}.
Revise the conclusion based on that answer.
>>

@effect run

What's next?

Read the full Margarita docs or go back to the State tutorial.