Skip to content

feat(tools): add interactive_prompt tool with Discord UI support#39911

Open
TerminalSausage wants to merge 4 commits into
NousResearch:mainfrom
TerminalSausage:feat/interactive-prompt-tool
Open

feat(tools): add interactive_prompt tool with Discord UI support#39911
TerminalSausage wants to merge 4 commits into
NousResearch:mainfrom
TerminalSausage:feat/interactive-prompt-tool

Conversation

@TerminalSausage

Copy link
Copy Markdown

Summary

Adds interactive_prompt — a new tool that lets agents present structured interactive forms (buttons, modals with text/select/checkbox/file-upload fields) to users on Discord and CLI. Bridges the gap between clarify (single-choice quick prompts) and full conversation, giving agents a way to collect multi-field input, route workflows via button actions, and render rich Discord UI components.

What it does

  • Buttons mode: Present up to 25 labeled options that resolve immediately or open modal forms
  • Modal mode: Collect 1–5 typed fields (text, select, radio, checkbox, file_upload) per option
  • Auth gating: Per-policy enforcement — session_owner_only, any_allowed_user, any_allowed_role, any_allowed_user_or_role
  • Timeout: Views auto-expire after a configurable timeout (default 15 min, config-aware in all paths)
  • Cross-platform: Discord gets native buttons/modals; CLI falls back to numbered text selection with automatic reply capture
  • Gateway lifecycle: Views are registered on the platform adapter and cleaned up on gateway shutdown

Key files

File Purpose
tools/interactive_prompt_tool.py Tool implementation — schema, execution, result routing, runtime validation
tools/discord_interactive_views.py Discord UI components — Button view, Modal, per-policy auth
tools/human_input_gateway.py Human-input gateway — shared prompt/resolve primitive, text-fallback support
tools/discord_auth_helpers.py Shared Discord interaction auth verification
gateway/platforms/discord_components.py Discord component registration on gateway
gateway/run.py Gateway lifecycle hooks + text-reply intercept for non-rich platforms
gateway/platforms/base.py Base platform adapter interface for components + text fallback
plugins/platforms/discord/adapter.py Discord adapter integration
agent/tool_executor.py Tool executor routing for interactive prompts
agent/agent_runtime_helpers.py Runtime helper for prompt lifecycle
tools/clarify_gateway.py Clarify gateway shared clear_all() utility
toolsets.py Toolset registration
cli-config.yaml.example Config example with timeout field
docs/interactive-prompt-tool-spec.md Design specification and reference
website/docs/reference/tools-reference.md Tools reference docs
website/docs/developer-guide/gateway-internals.md Gateway internals docs

Tests

  • 135 new tests across 5 test files (tool unit, integration, human-input gateway, Discord views, review-fix verification)
  • 135/135 passing locally (Discord view tests require py-cord; CI runs full suite)
  • Review-fix tests cover: double-JSON-encoding, text-fallback resolution, config-aware timeout, _finish_agent_tool wrapping, profile-aware cache paths, per-policy auth, runtime validation

Known limitations

  • File upload in modals is Discord-only; CLI falls back to text prompts
  • Max 25 options per interactive_prompt call (Discord component limit)
  • Modal fields limited to 5 per form (Discord API constraint)
  • Views are in-memory — gateway restart discards active prompts

Implements structured interactive prompts with button choices and modal
forms, rendered as Discord embeds + components with auth gating.

New files:
- tools/interactive_prompt_tool.py — schema, validation, tool entry point
- tools/human_input_gateway.py — cross-platform prompt registry (per-session
  wait/resolve, timeout, cleanup)
- tools/discord_auth_helpers.py — shared auth check for interactive views
- tools/discord_interactive_views.py — Discord modal + choice button views
- gateway/platforms/discord_components.py — Discord Components API adapter
- tests/tools/ — 79 tests (4 files)

Modified files:
- gateway/run.py — interactive_prompt_callback wiring + gateway shutdown
  cleanup (clear_all for clarify + interactive prompts)
- gateway/platforms/base.py — send_interactive_prompt adapter method
- plugins/platforms/discord/adapter.py — Discord render override
- agent/agent_runtime_helpers.py, agent/tool_executor.py — tool call paths
- tools/clarify_gateway.py — clear_all() for shutdown cleanup
- toolsets.py — toolset registration

79 tests passing. Docs committed separately.
P1: Fix double-JSON-encoding — detect and pass through already-serialized
JSON strings from production gateway callbacks instead of re-encoding.

P1: Add text-fallback resolution for non-rich platforms — add
get_pending_for_session/mark_awaiting_text/resolve_text_response to
human_input_gateway, wire base-platform send_human_input to mark
text-capture, add gateway intercept for interactive_prompt text replies.

P2: Use config-aware timeout in AIAgent intercepted paths — both
agent_runtime_helpers.py and tool_executor.py now call
get_interactive_prompt_timeout() when timeout_seconds is absent.

P2: Wrap interactive_prompt in _finish_agent_tool in runtime_helpers so
post-tool-call hooks fire (timing, metrics, tracing).

P2: Use get_hermes_home() instead of hardcoded ~/.hermes for upload cache
path in discord_interactive_views.py.

P2: Implement per-policy auth checks — any_allowed_user only checks user
allowlist, any_allowed_role only checks role allowlist,
any_allowed_user_or_role checks union.

P3: Enforce runtime validation — reject invalid display_type and
auth_policy values, clamp timeout_seconds to 60-3600 range.

45 new tests covering all 7 findings.
@alt-glitch alt-glitch added type/feature New feature or request comp/tools Tool registry, model_tools, toolsets platform/discord Discord bot adapter comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have platform/discord Discord bot adapter type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants