Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI4Finance Foundation FinGPT Agent Ledger Models

From Leeroopedia
Knowledge Sources
Domains Database, Fintech_Infrastructure, Agent_Ledger
Last Updated 2026-10-18 00:00 GMT

Overview

Concrete tool for persisting the agent ledger entity hierarchy (AgentAccount, AgentKYA, AgentWallet, PaymentIntent, MicroTransaction) as SQLAlchemy models provided by the Finogrid platform within FinGPT.

Description

The agent_ledger module defines the stablecoin micro-transaction layer for the Finogrid platform. It establishes an actor hierarchy: AgentOwner (human Client) → AgentAccount (master agent) → AgentWallet (sub-wallet) → PaymentIntent (closed-loop). It also defines enums for KYA status, agent status, loop type, intent status/category, and micro-transaction status. The settlement flow covers fiat top-up → USDC prefund → off-chain micropay → on-chain sweep, with zero modifications to v1 models.

Usage

Import these models when you need to query or mutate agent account balances, wallets, payment intents, or micro-transactions within the Finogrid Agent Ledger API.

Code Reference

Source Location

Signature

class KYAStatus(str, PyEnum):
    UNVERIFIED = "unverified"; PENDING = "pending"
    BASIC = "basic"; ENHANCED = "enhanced"

class AgentStatus(str, PyEnum):
    ACTIVE = "active"; SUSPENDED = "suspended"; TERMINATED = "terminated"

class LoopType(str, PyEnum):
    OPEN = "open"; CLOSED = "closed"

class IntentStatus(str, PyEnum):
    RESERVED = "reserved"; CONSUMED = "consumed"; EXPIRED = "expired"
    REFUNDED = "refunded"; SUPERSEDED = "superseded"

class IntentCategory(str, PyEnum):
    COMPUTE = "compute"; DATA = "data"; AGENT_SERVICE = "agent_service"
    CONTENT = "content"; OFFRAMP = "offramp"; OTHER = "other"

class MicroTxStatus(str, PyEnum):
    PENDING = "pending"; SETTLED_OFFCHAIN = "settled_offchain"
    SETTLED_ONCHAIN = "settled_onchain"; FAILED = "failed"; REFUNDED = "refunded"

class AgentAccount(Base, UUIDMixin, TimestampMixin):
    __tablename__ = "agent_accounts"
    name: Mapped[str]
    owner_client_id: Mapped[uuid.UUID | None]
    api_key_hash: Mapped[str]
    status: Mapped[AgentStatus]
    kya_status: Mapped[KYAStatus]
    chain: Mapped[str]
    prefund_balance_usdc: Mapped[float]
    reserved_balance_usdc: Mapped[float]

class AgentKYA(Base, UUIDMixin, TimestampMixin): ...
class AgentWallet(Base, UUIDMixin, TimestampMixin): ...
class PaymentIntent(Base, UUIDMixin, TimestampMixin): ...
class MicroTransaction(Base, UUIDMixin, TimestampMixin): ...
class AgentLedgerEntry(Base, UUIDMixin, TimestampMixin): ...

Import

from finogrid.database.models.agent_ledger import (
    AgentAccount, AgentKYA, AgentWallet, PaymentIntent,
    MicroTransaction, AgentLedgerEntry,
    KYAStatus, AgentStatus, LoopType, IntentStatus, IntentCategory, MicroTxStatus,
)

I/O Contract

Inputs

Name Type Required Description
AgentAccount fields str/float/enum Yes Name, api_key_hash, owner_client_id, chain, balances
AgentWallet fields str/enum Yes loop_type, spending_rules per wallet
PaymentIntent fields str/float/enum Yes (closed-loop) category, amount, expires_at

Outputs

Name Type Description
ORM instances SQLAlchemy mapped objects Persistent rows in agent_accounts, agent_wallets, payment_intents, micro_transactions tables

Usage Examples

Create an Agent Account and Wallet

import uuid
from finogrid.database.models.agent_ledger import (
    AgentAccount, AgentWallet, AgentStatus, KYAStatus, LoopType,
)
from finogrid.database.models.base import Base
from sqlalchemy import create_engine
from sqlalchemy.orm import Session

engine = create_engine("postgresql:///finogrid")
Base.metadata.create_all(engine)

with Session(engine) as session:
    agent = AgentAccount(
        name="trading-agent-1",
        owner_client_id=uuid.uuid4(),
        api_key_hash="hashed_key_here",
        status=AgentStatus.ACTIVE,
        kya_status=KYAStatus.UNVERIFIED,
        chain="base",
        prefund_balance_usdc=0.0,
        reserved_balance_usdc=0.0,
    )
    session.add(agent)
    session.flush()

    wallet = AgentWallet(
        agent_account_id=agent.id,
        label="primary",
        loop_type=LoopType.OPEN,
    )
    session.add(wallet)
    session.commit()
    print(f"Created agent {agent.id} with wallet {wallet.id}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment