from praisonaiagents import Agentfrom praisonaiagents.tools.clarify import clarifyagent = Agent( name="Writer", instructions="Write code. If requirements are ambiguous, ask clarifying questions.", tools=[clarify],)agent.start("Build me a web scraper")# Agent may call: clarify(question="Which language?", choices=["python", "rust"])
2
With Custom Handler
from praisonaiagents import Agentfrom praisonaiagents.tools.clarify import clarify, create_cli_clarify_handler# Setup CLI handler for interactive questionshandler = create_cli_clarify_handler()agent = Agent( name="Researcher", instructions="Research topics. Ask for clarification when needed.", tools=[clarify], ctx={"clarify_handler": handler})
# LLM sees this tool signature:{ "name": "clarify", "description": "Ask the user a focused clarifying question when genuinely ambiguous. Use sparingly - only when you cannot proceed without their input.", "parameters": { "type": "object", "properties": { "question": { "type": "string", "description": "The clarifying question to ask" }, "choices": { "type": "array", "items": {"type": "string"}, "description": "Optional list of predefined answer choices" } }, "required": ["question"] }}
from praisonaiagents.bots import BotConfigconfig = BotConfig( default_tools=["clarify"], # Included by default auto_approve_tools=True # No approval prompt for clarify)
The clarify tool is included in the bot’s default auto-approve list, so it won’t require manual approval in bot environments.
async def smart_clarify_handler(question, choices): """Handler that considers conversation context""" # Check previous messages for hints context = get_conversation_context() if "python" in context and "web" in question.lower(): # Auto-suggest based on context return "fastapi" return await show_user_dialog(question, choices)
# When no interactive channel available:result = await clarify("Which database?", ["postgres", "mysql"])# Returns: "No interactive channel available. Please proceed with your best judgment for: Which database?"# Agent can handle this gracefully:if "no interactive channel" in result.lower(): # Use reasonable defaults database = "postgres" # Pick sensible default
Only call clarify when you genuinely cannot proceed without user input. Don’t ask for preferences that have reasonable defaults.Good: “Which API endpoint format?” when building an API
Bad: “Should I use descriptive variable names?” (obvious default)
Provide Clear Choices
When possible, offer specific choices rather than open-ended questions.Good: choices=["fastapi", "flask", "django"]Bad: "What Python web framework should I use?" (no choices)
Handle Fallbacks Gracefully
Always check if the response indicates no interactive channel and proceed with sensible defaults.
response = await clarify("Pick a color", ["blue", "red"])if "no interactive channel" in response.lower(): color = "blue" # Use defaultelse: color = response
Context-Aware Questions
Frame questions with enough context for users to make informed decisions.Good: “Which authentication method for your user API?”
Bad: “Which auth?” (unclear context)