Skip to content

feat: SETUP_AGENT - unified agent setup with create and connect modes#76

Merged
pcarranzav merged 12 commits intomainfrom
feat/connect-agent-key
Apr 10, 2026
Merged

feat: SETUP_AGENT - unified agent setup with create and connect modes#76
pcarranzav merged 12 commits intomainfrom
feat/connect-agent-key

Conversation

@pcarranzav
Copy link
Copy Markdown
Member

@pcarranzav pcarranzav commented Mar 30, 2026

Summary

Consolidate agent setup into a single flow. Instead of separate requestAgentCreation() and requestConnectAgentKey() methods, requestAgentCreation() now accepts optional fields to control the mode:

  • No extra flags → create new agent (default for new users)
  • agent_address → connect key to specific existing agent
  • connect_to_existing → connect mode, user picks agent in dashboard

Changes

  • CreateAgentApprovalRequest: added optional agent_address, connect_to_existing, key_name fields
  • Removed ConnectAgentKeyApprovalRequest and requestConnectAgentKey()
  • requestAgentCreation() passes through agent_address, connect_to_existing, key_name when present
  • CLI setup start: new --agent <address>, --connect-to-existing, --key-name <name> flags
  • CLI outputs verificationCode (6-digit keccak256-derived) for MITM prevention
  • SKILL.md updated with all three setup modes and verification code instructions

CLI usage

# Create new agent (default)
ampersend setup start --name "my-agent"

# Connect to specific existing agent
ampersend setup start --agent 0xAgentAddress --key-name "my-key"

# Connect mode, user picks agent in dashboard
ampersend setup start --connect-to-existing

Test plan

  • All 168 tests pass
  • TypeScript type-check and build pass
  • Prettier/ESLint pass
  • E2E: create new agent via setup start --name
  • E2E: connect to existing via setup start --agent 0x...
  • E2E: connect mode via setup start --connect-to-existing
  • Verification codes match between CLI and dashboard

🤖 Generated with Claude Code

@pcarranzav pcarranzav marked this pull request as ready for review March 31, 2026 23:03
pcarranzav and others added 6 commits April 2, 2026 13:53
Add the ability to connect an agent key to an existing agent account
instead of creating a new one. This enables the primary use case where
a user creates an agent in the dashboard, then sets it up via CLI.

- New `ConnectAgentKeyApprovalRequest` type in types.ts
- New `requestConnectAgentKey()` method on ApprovalClient
- New `--agent <address>` option on `ampersend setup start`
- `setup finish` works unchanged (same resolved payload shape)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
--name is for agent name (create flow), --key-name is for the key
name (connect flow with --agent). Avoids confusing dual semantics.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add key_name field to CreateAgentApprovalRequest type
- Pass key_name through approval client for create flow
- --key-name now works for both create and connect flows
- Update SKILL.md with connect-to-existing docs, key naming
  explanation, and per-flow option tables

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- CLI setup start now outputs verificationCode (6-digit code derived
  from keccak256 of the key address) for both create and connect flows
- SKILL.md updated to instruct agents to show the verification code
  to the user alongside the approval URL

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Consolidate the separate CONNECT_AGENT_KEY flow into a unified
SETUP_AGENT approach. Instead of a separate requestConnectAgentKey()
method, requestAgentCreation() now accepts optional agent_address
and connect_to_existing fields.

- Add agent_address, connect_to_existing, key_name to CreateAgentApprovalRequest
- Remove ConnectAgentKeyApprovalRequest (if present)
- Remove requestConnectAgentKey() (if present)
- CLI: --agent, --connect-to-existing, --key-name all go through
  requestAgentCreation()
- SKILL.md: updated with new connect options

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pcarranzav pcarranzav force-pushed the feat/connect-agent-key branch from 423347c to 2001d88 Compare April 2, 2026 17:14
…te ConnectAgentKeyApprovalRequest

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pcarranzav pcarranzav changed the title feat: add CONNECT_AGENT_KEY support to CLI and approval client feat: SETUP_AGENT - unified agent setup with create and connect modes Apr 2, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pcarranzav pcarranzav force-pushed the feat/connect-agent-key branch from 9539cab to 96c055a Compare April 2, 2026 19:46
Copy link
Copy Markdown
Collaborator

@matiasedgeandnode matiasedgeandnode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest you consider the following:

TL;DR: Replace --connect-to-existing with --mode <create|connect> (default: create). Add cross-flag validation. Add tests for the new flags.

Why: The three new flags (--agent, --connect-to-existing, --key-name) have no mutual exclusion validation, so contradictory combinations like --agent 0x... --connect-to-existing or --name "foo" --connect-to-existing silently pass through. A --mode flag makes intent explicit and validation trivial.

Design:

  • --mode create (default): current behavior. --agent is invalid.
  • --mode connect: connects a key to an existing agent. --agent is optional (omit = user picks in dashboard). --name and spend config flags (--daily-limit, etc.) are invalid since the agent already exists.
  • --key-name is valid in both modes.
  • --connect-to-existing flag goes away entirely — it's just --mode connect without --agent.

Validation to add (in executeSetupStart, before the API call):

  • --mode connect + --name → error
  • --mode connect + any spend config flag → error
  • --mode create + --agent → error

Other:

  • Group related flags in CreateAgentApprovalRequest by mode.
  • Add tests for: connect mode with/without --agent, invalid address, --key-name passthrough, and the three validation errors above. The existing test infra (mockRequestAgentCreation,
    ExitError pattern) makes this straightforward.
  • Update SKILL.md examples to use --mode connect instead of --connect-to-existing.

pcarranzav and others added 2 commits April 8, 2026 16:52
Add `mode: "create" | "connect" | "connect_choose"` field to
CreateAgentApprovalRequest, replacing the implicit `connect_to_existing`
boolean. CLI resolves mode from flags before sending.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add --mode <create|connect> CLI flag (default: create)
- Cross-flag validation: --name and spend flags rejected in connect
  mode, --agent rejected in create mode
- Add tests for connect mode, connect_choose, key-name passthrough,
  and all three validation error cases
- Update SKILL.md examples

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pcarranzav pcarranzav force-pushed the feat/connect-agent-key branch from 8793808 to 822d510 Compare April 9, 2026 19:38
Copy link
Copy Markdown
Collaborator

@matiasedgeandnode matiasedgeandnode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - nits:

  1. requestAgentCreation naming — method + JSDoc still say "create" but now handles connect flows too. Consider requestAgentApproval.
  2. Missing test: invalid --agent address — the INVALID_ADDRESS error path (setup.ts:66-69) has no test coverage.
  3. Missing test: --auto-topup alone in connect mode — existing test triggers rejection via dailyLimit with autoTopup: false. No test that autoTopup: true alone is rejected.
  4. key_name uses Schema.optional(NullOr(String)) but null is never sent — CLI does options.keyName ?? undefined. Could simplify to Schema.optional(String) to match agent_address / mode pattern.
  5. Payload building in approval.ts — four sequential if (x !== undefined) blocks. Works, but fragile as fields grow.

- Rename requestAgentCreation -> requestAgentApproval and
  CreateAgentApprovalRequest -> AgentApprovalRequest to reflect that the
  method now handles both create and connect flows
- Simplify key_name schema: Schema.optional(String) instead of
  Schema.optional(NullOr(String)) since null is never sent
- Replace sequential if-blocks with Object.fromEntries filter pattern
- Add tests: invalid --agent address, --auto-topup alone in connect mode

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pcarranzav pcarranzav merged commit 13e6958 into main Apr 10, 2026
6 checks passed
@pcarranzav pcarranzav deleted the feat/connect-agent-key branch April 10, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants