Skip to main content
The user_approval method shows an approval card in the Narada browser UI and waits for the user to choose one of two buttons. Use this when a Python agent should not continue until a person explicitly approves or rejects the next action.
For a higher-level guide covering both human-in-the-loop methods, see Human-in-the-Loop Steps.

Method Signature

async def user_approval(
    self,
    *,
    step_id: str,
    prompt_message: str,
    approve_label: str,
    reject_label: str,
    timeout: int | None = 300,
) -> bool

Parameters

step_id
str
required
A stable identifier for this approval step.
step_id="approve-invoice-submission"
prompt_message
str
required
The message shown in the approval card.
prompt_message="Submit this invoice for approval?"
approve_label
str
required
The label for the button that returns True.
approve_label="Submit"
reject_label
str
required
The label for the button that returns False.
reject_label="Cancel"
timeout
int | None
default:"300"
Maximum time in seconds to wait for the user response. The default is 300 seconds, and the maximum is 3600 seconds.

Return Value

approved
bool
True when the user clicks the approve button. False when the user clicks the reject button.
If the interaction is cancelled or aborted, the method raises UserAbortedError.

Example

import asyncio

from narada import Agent, BrowserEnvironment, UserAbortedError

async def main():
    env = BrowserEnvironment()
    agent = Agent(environment=env)

    try:
        try:
            approved = await agent.user_approval(
                step_id="approve-send-message",
                prompt_message="Send the drafted message to the customer?",
                approve_label="Send",
                reject_label="Do not send",
                timeout=300,
            )
        except UserAbortedError:
            print("The approval step was cancelled.")
            return

        if not approved:
            print("The user rejected the action.")
            return

        await agent.run(prompt="Send the drafted message.")
    finally:
        await env.close()

if __name__ == "__main__":
    asyncio.run(main())