feat: [PRO-474] implement invoke command with API, webhook, and local options#116
Merged
Conversation
… options ## Summary - Added --api (default), --webhook, and --local invocation options - Changed default invocation from local handler to API - Removed fallback logic between invocation methods - Added top-level `xpander invoke` command alias ## Changes ### Invoke Command Options - Added `--api` flag for API invocation (now the default) - Added `--webhook` flag for webhook invocation - Added `--local` flag for local handler invocation - Each method is explicit with no automatic fallbacks ### API Invocation (Default) - Uses `/v1/agents/<agent-id>/invoke` API endpoint - Sends request with `input.text` payload - Requires both API key and organization ID headers - Returns structured response with proper error handling ### Webhook Invocation - Maintains existing webhook functionality - Uses agent's configured webhook_url or fallback URL - No longer used as fallback from local handler failures ### Local Handler Invocation - Must be explicitly requested with `--local` flag - Fails immediately if xpander_handler.py not available - No fallback to webhook or API on failure ### Top-Level Command Alias - Created `xpander invoke` as alias for `xpander agent invoke` - Uses same registration function for consistency - Available at root command level for convenience ## Files Modified - src/commands/agent/commands/invoke.ts - Updated invoke logic - src/commands/invoke.ts - New top-level command registration - src/index.ts - Registered invoke command ## Breaking Changes - Default invocation method changed from local to API - Local handler no longer auto-selected when available - No automatic fallbacks between invocation methods ## Test plan - [ ] Test `xpander invoke` API invocation (default) - [ ] Test `xpander invoke --webhook` webhook invocation - [ ] Test `xpander invoke --local` local handler invocation - [ ] Test `xpander agent invoke` still works - [ ] Verify no fallbacks occur between methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…nt not found Previously, when a user ran `xpander invoke <invalid-name>`, the command would fail without checking the .env file for XPANDER_AGENT_ID. Now the agent resolution logic: 1. Always checks for .env file first to see if agent_id is present 2. If an agent name/ID is provided, tries to resolve it 3. If resolution fails AND .env has agent_id, falls back to using the .env agent_id 4. Shows a warning message when falling back to .env This makes the invoke command more intelligent when running in an agent directory. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| ); | ||
| } | ||
| return envAgentId; | ||
| } |
There was a problem hiding this comment.
Bug: Silent fallback to .env agent when explicit agent fails
When a user explicitly provides an agent name that doesn't exist, getAgentIdFromEnvOrSelection silently falls back to using the agent_id from the .env file. This contradicts the PR's stated goal of removing fallback logic and making errors clear. A user who types xpander invoke "WrongAgentName" "message" might unknowingly invoke a completely different agent from their .env file. The invoke command's error handling at lines 101-108 never triggers because the function returns the env agent ID instead of null.
Added explicit --message flag to allow users to clearly specify the message when invoking agents. This works alongside --agent-id and --agent-name flags for maximum flexibility. Changes: - Added --message flag for explicit message specification - Improved argument parsing priority: 1. --message flag takes precedence 2. --agent/--agent-id/--agent-name flags for explicit agent specification 3. In agent directory with .env: all positional args become message 4. Otherwise: first arg is agent, rest is message - Updated help text with examples of all invocation patterns - Fixed duplicate "Using agent" message by using silent mode in resolveAgentId Usage examples: - xpander agent invoke --agent-id abc123 --message "hi" - xpander agent invoke --agent-name "MyAgent" -m "hello" - xpander agent invoke "hi" (in agent directory) - xpander agent invoke MyAgent "hi" (outside agent directory) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed 3 bugs identified by Cursor code review: 1. Bug #1 (Silent fallback): Already fixed in previous commit - removed fallback logic from agent-resolver so explicit agent failures are clear 2. Bug #2 (Missing org ID validation): Added validation for organization ID before making API request. Now shows clear error message if org ID is missing, matching the API key validation pattern 3. Bug #3 (Staging URL support): Added IS_STG environment variable check to switch between production and staging API URLs: - Production: https://api.xpander.ai - Staging: https://api-stg.xpander.ai Changes in invoke.ts: - Lines 317-324: Added orgId validation with clear error message - Lines 326-330: Added staging environment detection and dynamic base URL 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
xpander-moriel
approved these changes
Dec 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements explicit invocation methods for the invoke command with API as the default, removing automatic fallbacks between methods.
Key Changes
1. API Invocation (New Default)
What: Uses
/v1/agents/<agent-id>/invokeREST API endpointHow: Sends
{"input": {"text": "message"}}payload with API key and org ID headersWhy: More reliable and consistent than webhook, better for production use
2. Explicit Invocation Options
--api: API invocation (default - no flag needed)--webhook: Webhook invocation (explicit flag required)--local: Local handler invocation (explicit flag required)3. Removed Fallback Logic
Before: Local → Webhook fallback chain
After: Each method is independent, fails immediately if unavailable
Why: Makes behavior predictable and errors clear
4. Top-Level Command Alias
Added:
xpander invokeas alias forxpander agent invokeWhy: Convenience and consistency with other top-level commands
Files Modified
Examples
Breaking Changes
Migration: Add
--localflag if you need local handler behaviorTest plan
xpander invokecommand🤖 Generated with Claude Code
Note
Adds explicit API (default), webhook, and local invocation modes to
agent invoke, enhances message/agent resolution (including .env), and introduces a top‑levelxpander invokealias.agent invoke--api(default),--webhook, and--localpaths; remove automatic fallbacks.POST /v1/agents/{agentId}/invokewith{"input": {"text": message}}, usingx-api-keyandx-organization-idheaders.--message; support.envagent auto-detection; maintain legacy--agent/--agent-id/--agent-name; improved interactive prompts.xpander invokeviaconfigureInvokeCommandand register it insrc/index.ts.Written by Cursor Bugbot for commit 54f7cd6. This will update automatically on new commits. Configure here.