Skip to main content

Core loop

1. Receive user query + metadata.accountInfo[]
2. Build prompt context (sanitized metadata)
3. Generate model output with automatic tool calling
4. Execute tools through SDKTool wrapper
5. Handle interactive confirmations if needed
6. Return finalText + chainId + step trace



## NLP stages in detail

### 1. Tokenization & normalization

Raw input is lowercased, whitespace-normalized, and split into tokens. Shorthand like `"half my ETH"` or `"max USDC"` is expanded to resolvable quantities before entity extraction.

### 2. Intent classification

The engine identifies the primary action class:

| Class | Trigger words |
|---|---|
| Swap | swap, exchange, trade, convert |
| Bridge | bridge, move, transfer cross-chain, send to |
| Zap | zap, deposit into, LP, provide liquidity |
| Query | balance, price, show, what is, how much |
| Schedule | every, recurring, daily, at midnight |

### 3. Entity extraction

Entities extracted per intent:

| Entity | Resolved via |
|---|---|
| Token symbol | on-chain registry + alias list |
| Token address | direct match or ENS resolution |
| Amount | numeric parse + `max`/`half`/`all` expansion |
| Source chain | chain name → chain ID mapping |
| Destination chain | same as above |
| Wallet address | `0x...` detection or session-scoped default |

### 4. Ambiguity resolution

When entities are ambiguous the engine applies a priority order:

1. Explicit session metadata (wallet, connected chain)
2. Prior turn context (stable `sessionId`)
3. Statistical defaults (e.g. native ETH before WETH on mainnet)
4. Clarifying question to user if still unresolved

## Example flow

For: `Swap 100 USDC to WETH on Arbitrum`

```text
1. TokenAddressTool -> resolve symbols
2. BalanceTool -> verify funds
3. ZapCallDataGeneratorTool -> build and cache session route
4. PerformZapTool -> waits for confirmation, then executes
5. Return execution summary + explorer-style link
The response includes:
  • result.finalText: user-facing answer
  • result.steps: step-by-step tool events
  • result.sessionId: memory and confirmation scope

Multi-turn context

With a stable sessionId, each turn carries forward:
  • Previously resolved token/chain entities
  • Wallet and balance context
  • User preferences stated earlier in the session
Use a new sessionId to reset context and start a fresh conversation.

Tool selection behavior

Tool choice is influenced by:
  • Prompt clarity
  • Available metadata (wallet, chain, account)
  • Tool schemas and descriptions
  • System prompt constraints

Error handling

SDKTool returns normalized error details with durations. Model retries are bounded by DZAP_MODEL_MAX_RETRIES (default 2).

Streaming

sdk.ask() can stream intermediate NLP and tool events:
await sdk.ask({
  userQuery: "...",
  metadata: {
    accountInfo: [{ blockchain: "evm", chain: "1", user_account: "0xabc..." }],
  },
  onStep: (step) => {
    console.log(step.toolName ?? step.type);
  },
});

Memory behavior

Each turn is tied to a sessionId. Reuse it for multi-turn context, or start a new one to isolate conversations.
Last modified on May 26, 2026