feat(agent): add dedicated crypto_agent for wallet & market ops (#1397)#1736
Conversation
…humansai#1397) Introduce a new built-in `crypto_agent` specialized for wallet actions (balances, transfers, swaps, contract calls) and market operations. The agent enforces a strict read → simulate → confirm → execute contract, with a narrow tool allowlist (wallet_*, stock_* market data, ask_user_clarification, memory_recall, current_time) — no shell, file_write, curl, or integration delegation. The safety preamble stays ON; identity / skills / memory boilerplate is omitted to keep the financial-risk voice tight. Routing: orchestrator gains `crypto_agent` in its `subagents` list so the runtime synthesises a `delegate_do_crypto` tool, and the orchestrator prompt explicitly routes crypto wallet/market requests here (never through `delegate_to_integrations_agent` or `delegate_run_code`). Coverage: - loader tests assert narrow allowlist, safety on, write-tool exclusions, iteration cap, and orchestrator routing entry. - prompt builder tests assert the read/simulate/confirm/execute contract, the prepared_id gating, and the no-fabrication / no-secret-logging rules are present. - capability catalog gains `automation.crypto_agent` for user-visible docs. Tool implementations themselves (wallet_*) land separately via tinyhumansai#1396 — unknown names are silently dropped by the tool filter today, so this PR is safe to merge ahead of them.
📝 WalkthroughWalkthroughAdds a new built-in crypto agent: capability catalog entry, agent configuration and narrow tool allowlist, detailed prompt and builder enforcing read→simulate→confirm→execute, loader registration with tests, and orchestrator routing to a synthesized delegate for crypto operations. ChangesCrypto Agent Implementation
Sequence DiagramsequenceDiagram
participant User
participant Orchestrator
participant CryptoAgent
participant WalletTools
User->>Orchestrator: request involving wallet/market action
Orchestrator->>CryptoAgent: delegate_do_crypto (route request)
CryptoAgent->>WalletTools: read balances / inspect state
WalletTools-->>CryptoAgent: balances / positions
CryptoAgent->>WalletTools: wallet_prepare_transfer / quote (simulate)
WalletTools-->>CryptoAgent: quote + prepared_id
CryptoAgent->>User: confirmation prompt (fees/ETA/prepared_id)
User-->>CryptoAgent: user approval (ok to send)
CryptoAgent->>WalletTools: wallet_execute_prepared(prepared_id)
WalletTools-->>CryptoAgent: execution result or tool error
CryptoAgent->>User: final report (success or sanitized error)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/openhuman/agent/agents/crypto_agent/prompt.md`:
- Line 37: The prompt's "6. **On failure.**" rule currently instructs to "Show
the tool's error verbatim"; change it to require a sanitized/redacted error
instead: instruct the agent to present a short, faithful but redacted error
excerpt (remove/replace sensitive tokens, stack traces, request IDs, payloads),
then on the next line output the one-line likely cause (e.g. "RPC rejected —
nonce gap", "insufficient gas"), and then stop without retrying; ensure the
edited text explicitly forbids printing raw tool output and gives examples of
what to redact (secrets, full traces, IDs).
In `@src/openhuman/agent/agents/crypto_agent/prompt.rs`:
- Around line 17-45: The build function in prompt.rs lacks tracing around
entry/exit and section assembly; add debug/trace logs at the start and end of
PromptContext::build (function build) and after each section render call
(render_user_files, render_tools, render_safety, render_workspace) to record
presence/emptiness and length (e.g., trimmed length or "empty") and the final
output length; use the project's tracing/log crate at debug or trace level and
include contextual info like ctx identifier and ARCHETYPE usage so you can
correlate logs to specific prompt builds.
In `@src/openhuman/agent/agents/loader.rs`:
- Around line 522-579: The test currently checks a subset of the crypto_agent
tool allowlist/ban; extend the assertions in the match &def.tools block in
loader.rs to pin the full crypto tool contract by (1) adding assertions that
required grounding/utility tools like "stock_quote", "stock_exchange_rate",
"memory_recall", and "current_time" are present (similar to the existing
required checks for wallet_* and stock_crypto_series) and (2) adding assertions
that banned/dangerous tools such as "delegate_run_code" (and any other
disallowed entries mentioned in the contract) are NOT present (similar to the
existing forbidden loop). Reference the same match &def.tools block and reuse
the pattern of iter().any(...) assertions to tighten the test so TOML changes
cannot remove or reintroduce these tools silently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5530afd8-7597-41f2-a4d2-989aafc8662c
📒 Files selected for processing (9)
src/openhuman/about_app/catalog.rssrc/openhuman/agent/agents/crypto_agent/agent.tomlsrc/openhuman/agent/agents/crypto_agent/mod.rssrc/openhuman/agent/agents/crypto_agent/prompt.mdsrc/openhuman/agent/agents/crypto_agent/prompt.rssrc/openhuman/agent/agents/loader.rssrc/openhuman/agent/agents/mod.rssrc/openhuman/agent/agents/orchestrator/agent.tomlsrc/openhuman/agent/agents/orchestrator/prompt.md
) - prompt.md: sanitize tool error rule. The previous "show the tool's error verbatim" wording conflicted with the never-log-secrets rule earlier in the prompt — verbatim errors can carry payloads, request ids, stack traces, signed blobs. The on-failure step now requires a redacted summary plus the one-line likely cause. - prompt.rs: add debug/trace tracing around the build flow so prompt regressions are observable at runtime (entry with model/tool/skill counts, exit with prompt length + section-presence flags). - loader.rs test: pin the full crypto_agent tool contract. Previously the test only guarded `stock_crypto_series`; it now also asserts `stock_quote`, `stock_exchange_rate`, `memory_recall`, and `current_time` are present, and that none of `delegate_run_code`, `delegate_research`, or `delegate_plan` slipped into the allowlist via a future TOML edit.
Resolves a conflict in `orchestrator/prompt.md` where upstream's tinyhumansai#1731 added a new step-2 "live external service" branch and renumbered the decision tree (3 → 4). Keeps both upstream's integrations-first ordering and the crypto branch from this PR under the renumbered step 4 ("Does this need other specialised execution?").
Summary
crypto_agent(undersrc/openhuman/agent/agents/crypto_agent/) specialized for wallet actions and market operations.wallet_status/wallet_balances/wallet_supported_assets/wallet_chain_status,wallet_prepare_{transfer,swap,contract_call},wallet_execute_prepared,stock_quote/stock_exchange_rate/stock_crypto_series,memory_recall,ask_user_clarification,current_time. No shell, nofile_write, nocurl, no integration delegation.crypto_agentin itssubagents(synthesisesdelegate_do_crypto) and the prompt's decision tree routes crypto wallet/market requests there — explicitly not throughdelegate_to_integrations_agentordelegate_run_code.automation.crypto_agentfor user-visible docs.Problem
OpenHuman already supports built-in agent definitions under
src/openhuman/agent/agents/, but there was no domain-specific agent for crypto workflows. Routing wallet / trading work through generic agents either over-broadens the tool surface (shell, broad HTTP, etc.) or skips the read-before-write and quote-before-execute discipline a financial-risk agent needs. A dedicated agent gives the orchestrator a safe place to send these requests.Solution
src/openhuman/agent/agents/crypto_agent/withagent.toml,mod.rs,prompt.rs,prompt.md. Prompt builder mirrors the help/researcher pattern (archetype + tools + safety + workspace), keeps the global safety preamble ON, and omits identity / skills / memory boilerplate to keep the financial-risk voice tight.BUILTINSinagents/loader.rs; module declared inagents/mod.rs. Built-in count assertion bumped 15 → 16.src/openhuman/wallet/schemas.rsand the financial-apisstock_*series. Tools not yet registered are silently dropped by the tool filter at spawn time — so this PR is safe to merge ahead of Add crypto wallet tools for balances, transfers, swaps, and contract calls #1396.subagentslistscrypto_agentso the runtime auto-synthesises adelegate_do_cryptotool. The decision-tree section inorchestrator/prompt.mdadds an explicit branch for crypto requests.Submission Checklist
docs/TEST-COVERAGE-MATRIX.md(capability catalog updated instead).## RelatedCloses #NNNin the## RelatedsectionImpact
wallet_execute_prepared.Related
automation.crypto_agent,skills.wallet_execution,skills.connect_web3_wallet,skills.connect_crypto_exchangeAI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
Commit & Branch
issue/1397-add-a-dedicated-crypto-transaction-agentc7c5e6029de2095bf1102ba587e85dc254bab0dbValidation Run
app/workspace changes,pnpm --filter openhuman-app format:checknot relevant.pnpm typechecknot relevant.cargo test --lib openhuman::agent::agents(54 passed),cargo test --lib openhuman::about_app(20 passed)cargo fmt+cargo checkclean for changed cratecargo fmt/cargo checkonapp/src-taurinot relevant.Validation Blocked
command:N/Aerror:N/Aimpact:N/ABehavior Changes
Parity Contract
stock_*tools).Duplicate / Superseded PR Handling
Summary by CodeRabbit
New Features
Documentation
Tests