# Architecture

`@tychilabs/agent-finance` sits between local self-custody and the Tychi agent API.

## Main Pieces

- **Local TYI identity**: generated or loaded from the local data dir.
- **Local EVM vault**: encrypted wallet storage used for transaction and x402 signing.
- **TYI backend API**: auth, session, provider, policy, tool, run, broadcast, and ERC-8004 routes.
- **Resume boundary**: TYI prepares a `pending_tx` or `pending_x402`, the SDK signs locally, then TYI resumes execution.

## Request Flow

```text
local keypair -> auth/register -> auth/login -> session/start
-> session/unlock -> llm/keys -> policy -> run
-> pending_tx or pending_x402
-> local sign
-> tx/broadcast or exec/result resume
```

## Local vs Remote

Local:

- TYI seed
- encrypted EVM private key
- transaction signatures
- x402 signatures

Remote:

- JWT auth session
- session password state
- provider key registration
- policy compilation and storage
- run loop execution
- tx broadcast and result resume

## First-Run Behavior

- `loadOrCreateAgentKeypair()` creates the encrypted TYI seed on first use.
- `client.auth.register()` creates the remote agent if it does not exist yet.
- `onboardNewAgent()` combines local keypair load/create and remote onboarding.

## Single-Wallet V1

The SDK currently presents a single-wallet local model. That keeps the SDK behavior aligned with the current onboarding and signing flows.
