Skip to content

feat(core): Institutional RWA Cognition & Compliance — StableHacks 2026#200

Merged
zaebee merged 2 commits into
mainfrom
feat/rwa-cognition-compliance
Mar 20, 2026
Merged

feat(core): Institutional RWA Cognition & Compliance — StableHacks 2026#200
zaebee merged 2 commits into
mainfrom
feat/rwa-cognition-compliance

Conversation

@zaebee

@zaebee zaebee commented Mar 20, 2026

Copy link
Copy Markdown
Owner

Summary

Pivots the Hive's transformer to an "Institutional RWA-Backed Stablecoin Vault" cognitive mode. Before issuing any vault instruction, the Agent acts as a strict compliance officer: KYC/AML is verified first, the physical asset is appraised using SIX data partner rates from context, LTV-adjusted collateral value is calculated, and only then is a structured RWAVaultIntent produced for the Solana TransactionSkill.

Proto changes

Two new messages added to metabolism.proto:

RWAComplianceScore — KYC/AML result embedded in every vault intent:

  • kyc_passed, aml_passed, compliance_status (APPROVED/REJECTED/PENDING)
  • violation_code: KYC_MISSING, AML_SUSPICIOUS, ASSET_UNVERIFIED, or empty
  • think: LLM reasoning block
  • flags: human-readable compliance notes

RWAVaultIntent — vault lock/mint instruction:

  • appraised_value_usd (from vision report + SIX rates), ltv_ratio, collateral_value_usd
  • wallet_address, stablecoin_currency (USDC), embedded RWAComplianceScore

Wired as Intent.oneof.params field 15 (rwa_vault).

Core changes

transformer/signatures.pyAppraiseAndVerifyRWA

New DSPy signature with 6 inputs (vision_report, wallet_address, kyc_status, six_rates, ltv_ratio, system_vitals) and 6 outputs. The LLM docstring enforces three rejection gates in order:

  1. kyc_status == "false"KYC_MISSING
  2. Suspicious vision report keywords (counterfeit, damaged, unverified, stolen, forged) → ASSET_UNVERIFIED
  3. Sanctions/high-risk jurisdiction indicators → AML_SUSPICIOUS

Only if all three pass does the LLM compute appraised_value_usd from vision + SIX rates and apply ltv_ratio.

reasoning/engine.pyAuraRWANegotiator

Single-stage DSPy module (vs. the two-stage trade chain). Compliance and appraisal are tightly coupled — no point separating them into two predictors.

transformer/main.py

  • _is_rwa_context(): detects metadata["rwa_mode"] == "true"
  • _think_rwa(): full RWA path, builds RWAComplianceScore + RWAVaultIntent, returns ACTION_TYPE_REJECT on any compliance failure
  • think() routing: RWA is checked before the trade path — both signals can coexist without conflict
  • _as_dict() extracted to module level (was a local function inside _build_trade_context — would have caused a NameError in the new RWA context builder)

membrane/main.py

RWA KYC backstop added before the existing trade guard. Any RWAVaultIntent with kyc_passed=False is forced to ACTION_TYPE_REJECT regardless of transformer output.

config/policy.py

rwa_ltv_ratio: float = 0.60 added to SafetySettings. Configurable via AURA_SAFETY__RWA_LTV_RATIO.

transaction/skill.py

mint_rwa_vault stub added (returns success=False, pending Solana vault program ABI) — consistent with submit_to_router.

Tests

9 new tests in core/tests/test_rwa_transformer.py:

Test Covers
test_appraise_and_verify_rwa_signature_fields All 6 inputs + 6 outputs present
test_rwa_negotiator_kyc_rejected kyc_status=FalseKYC_MISSING, values 0.0
test_rwa_negotiator_approved Valid report → APPROVED, collateral_value_usd > 0
test_transformer_think_rwa_path_rejected rwa_mode=true, kyc_status=falseREJECT, params="rwa_vault"
test_transformer_think_rwa_path_approved kyc_status=trueACCEPT
test_transformer_rwa_takes_priority_over_trade Both rwa_mode and asset_domain set → RWA path taken
test_membrane_blocks_kyc_failure kyc_passed=False → membrane forces REJECT
test_membrane_passes_compliant_rwa kyc_passed=True → passes through unchanged
test_rwa_ltv_ratio_from_settings Custom rwa_ltv_ratio=0.50 → passed to reasoning protein

Known limitations

  • LTV arithmetic is performed by the LLM, not enforced server-side. A follow-up guard capping collateral_value_usd at appraised * rwa_ltv_ratio in _think_rwa() would add a hard server-side check.
  • SIX rates must be pre-populated in metadata["six_rates"] by the upstream caller. Nothing enforces this at runtime.
  • mint_rwa_vault is a stub — real Solana SPL token minting requires the vault program ABI.

Test results

107 passed, 1 warning

…026)

Adds KYC/AML compliance gating and LTV-adjusted RWA vault intent generation
to the AuraTransformer. The Agent now acts as a strict compliance officer
before issuing any stablecoin vault instruction.

Proto:
- RWAComplianceScore: kyc_passed, aml_passed, compliance_status, violation_code,
  think, flags
- RWAVaultIntent: vault_id, asset_identifier, asset_domain, appraised_value_usd,
  ltv_ratio, collateral_value_usd, stablecoin_currency, wallet_address,
  compliance, reasoning
- Intent.oneof.params field 15: rwa_vault

Signatures (transformer/signatures.py):
- AppraiseAndVerifyRWA: 6 inputs (vision_report, wallet_address, kyc_status,
  six_rates, ltv_ratio, system_vitals), 6 outputs. LLM rejects on KYC_MISSING,
  ASSET_UNVERIFIED, AML_SUSPICIOUS before any appraisal.

Reasoning (engine.py):
- AuraRWANegotiator: single-stage DSPy module, chains compliance check and
  LTV appraisal in one predictor call.

ReasoningSkill: 'rwa' capability registered; RWAParams schema model added.

SafetySettings: rwa_ltv_ratio field (default 0.60), configurable via env.

Transformer (main.py):
- _is_rwa_context(): detects rwa_mode=true in metadata
- _build_rwa_context(): extracts vision_report, wallet_address, kyc_status,
  six_rates, vitals from Context.metadata
- _rwa_ltv_ratio(): reads from SafetySettings, defaults to 0.60
- _think_rwa(): full RWA path returning Intent with params.rwa_vault set
- think() routing: RWA checked before trade path
- Module-level _as_dict() helper extracted (was local to _build_trade_context)

Membrane: RWA KYC backstop added before trade guard in inspect_outbound().
Forces ACTION_TYPE_REJECT for any RWAVaultIntent with kyc_passed=False.

TransactionSkill: mint_rwa_vault stub added (pending Solana vault program ABI).

Tests (test_rwa_transformer.py): 9 tests covering signature contracts, both
compliance paths, transformer routing, RWA priority over trade, membrane
blocking, and configurable LTV ratio.

107 tests pass, 0 regressions.

Co-authored-by: Ona <no-reply@ona.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant new capability to the Hive system by enabling an "Institutional RWA-Backed Stablecoin Vault" cognitive mode. This mode integrates robust compliance checks, including KYC/AML verification and asset appraisal, directly into the vault instruction generation process. The changes ensure that only compliant and properly valued real-world assets can back stablecoins, enhancing the system's integrity and adherence to regulatory standards for digital asset tokenization.

Highlights

  • Institutional RWA-Backed Stablecoin Vault Mode: Introduced a new cognitive mode for the Hive's transformer, focusing on institutional Real-World Asset (RWA) backed stablecoin vaults, ensuring strict compliance and appraisal before vault instructions.
  • New Protobuf Messages for RWA: Added RWAComplianceScore to embed KYC/AML results and RWAVaultIntent for structured vault lock/mint instructions, including appraised value and collateral details.
  • LLM-Driven Compliance and Appraisal: Implemented AppraiseAndVerifyRWA DSPy signature and AuraRWANegotiator to handle KYC/AML verification, physical asset appraisal using SIX data, and LTV-adjusted collateral value calculation.
  • Transformer and Membrane Integration: Updated the transformer to prioritize RWA context and route requests through the new RWA path, and added a KYC backstop in the membrane layer to prevent non-compliant vault intents.
  • Configurable LTV Ratio: Added rwa_ltv_ratio to SafetySettings, allowing configuration of the maximum Loan-to-Value ratio for RWA-backed collateral.
  • Comprehensive Test Coverage: Included 9 new tests specifically for the RWA transformer, covering various scenarios from KYC rejection to approved vault intents and membrane blocking.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new "Institutional RWA-Backed Stablecoin Vault" cognitive mode, enhancing the system with KYC/AML compliance and asset appraisal capabilities. The changes are well-structured, integrating new proto messages, DSPy signatures, and reasoning logic across the transformer, reasoning protein, and membrane components. Comprehensive test cases have been added to validate the new functionality, covering various scenarios including KYC rejection, approval, and priority routing. The externalization of configuration values like rwa_ltv_ratio and the refactoring of _as_dict improve maintainability and clarity. The membrane's role as a backstop for KYC failures adds a crucial security layer. The comments highlight opportunities to improve type consistency and data flow between Python types and DSPy model expectations for kyc_status and ltv_ratio.

Comment thread core/src/hive/proteins/reasoning/engine.py Outdated
Comment on lines +74 to +76
kyc_status: str = dspy.InputField(
desc='KYC verification status as a plain string: "true" (verified) or "false" (not verified).'
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The kyc_status input field is described as a 'plain string: "true" (verified) or "false" (not verified)'. This implies that the DSPy model expects a string. However, in RWAParams and AuraRWANegotiator.forward, kyc_status is typed as bool. This leads to a bool to str conversion (str(kyc_status).lower()) before calling the DSPy model. For better type consistency and clarity, consider if RWAParams should also define kyc_status as a str if the DSPy model strictly requires it, or if the DSPy signature could be updated to accept a bool if the underlying model can handle it.

Comment on lines +81 to +83
ltv_ratio: str = dspy.InputField(
desc="Loan-to-value ratio as a plain float string (e.g. '0.60'). "
"collateral_value_usd = appraised_value_usd * ltv_ratio."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to kyc_status, the ltv_ratio input field is described as a 'plain float string (e.g. '0.60')'. This indicates the DSPy model expects a string. However, ltv_ratio is typed as float in RWAParams and AuraRWANegotiator.forward, requiring a float to str conversion (str(ltv_ratio)) before calling the DSPy model. Aligning the type in RWAParams to str or exploring if the DSPy signature can accept float directly would improve type consistency.

…ndary

RWAParams and AuraRWANegotiator.forward() now use str for kyc_status
("true"/"false") and ltv_ratio (e.g. "0.60") to match the
AppraiseAndVerifyRWA DSPy InputField types directly. The implicit
bool->str and float->str conversions are removed; the transformer
produces the string forms in _build_rwa_context() before passing to
the registry, making the type contract explicit at the boundary.

Co-authored-by: Ona <no-reply@ona.com>
@zaebee
zaebee merged commit 5f38c90 into main Mar 20, 2026
11 checks passed
@zaebee
zaebee deleted the feat/rwa-cognition-compliance branch March 20, 2026 12:54
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.

1 participant