|
1 | | -# HyperFormula AI SDK |
| 1 | +# HyperFormula AI SDK for Vercel |
2 | 2 |
|
3 | | -Let LLMs safely read/write spreadsheets and compute formulas via a deterministic engine. |
| 3 | +A [Vercel AI SDK](https://sdk.vercel.ai/docs) tool that gives your agents deterministic spreadsheet and formula computation — backed by HyperFormula's Excel-compatible engine. |
| 4 | + |
| 5 | +::: warning Not available yet — coming soon |
| 6 | +This integration is on our roadmap and **cannot be installed or used today**. The API shown below is a preview and may still change before the first release. |
| 7 | + |
| 8 | +If you'd like to try it, [join the early access list](https://2fmjvg.share-eu1.hsforms.com/2e6drCkuLTn-1RuiYB91eJA) — we'll ping you the moment the first beta is ready, and your sign-up directly tells us how strongly to prioritize this integration. |
| 9 | +::: |
4 | 10 |
|
5 | 11 | ## What it does |
6 | 12 |
|
7 | | -- **Evaluate formulas on the fly** —call `calculateFormula()` to evaluate any Excel-compatible formula without placing it in a cell. |
8 | | -- **Read and write cells and ranges** —get or set individual cells and multi-cell ranges so an LLM can inspect, populate, or modify sheet data programmatically. |
9 | | -- **Trace dependencies** —call `getCellDependents()` and `getCellPrecedents()` to understand which cells feed into a formula and what downstream values would change. |
| 13 | +- **Evaluate formulas deterministically** — your agent runs any Excel-compatible formula through HyperFormula instead of asking the LLM to do math. Results are exact, reproducible, and auditable. |
| 14 | +- **Read and write cells and ranges** — the agent inspects, populates, or modifies sheet data through typed tool calls. |
| 15 | +- **Trace dependencies** — precedents and dependents are surfaced so the agent can explain how every value was derived. |
| 16 | +- **400+ built-in functions out of the box** — the agent has access to the full Excel-compatible function set (`SUM`, `VLOOKUP`, `IRR`, `INDEX/MATCH`, and the rest), no implementation work required. |
10 | 17 |
|
11 | | -## Quickstart |
| 18 | +## Example |
| 19 | + |
| 20 | +Using HyperFormula as a tool inside the Vercel AI SDK: |
12 | 21 |
|
13 | 22 | ```js |
| 23 | +import { generateText } from 'ai'; |
| 24 | +import { openai } from '@ai-sdk/openai'; |
14 | 25 | import HyperFormula from 'hyperformula'; |
15 | 26 | import { createSpreadsheetTools } from 'hyperformula/ai'; |
16 | 27 |
|
17 | | -// 1. Create a HyperFormula instance with initial data |
| 28 | +// Build a workbook your agent can reason about. |
18 | 29 | const hf = HyperFormula.buildFromArray([ |
19 | 30 | ['Revenue', 100], |
20 | 31 | ['Cost', 60], |
21 | 32 | ['Profit', '=B1-B2'], |
22 | 33 | ]); |
23 | 34 |
|
24 | | -// 2. Create tools your LLM agent can call |
25 | | -const tools = createSpreadsheetTools(hf); |
26 | | - |
27 | | -// 3. Agent interaction examples |
28 | | -tools.evaluate({ formula: '=IRR({-1000,300,400,500,200})' }); |
29 | | -// → 0.1189 — deterministic, no LLM math |
30 | | - |
31 | | -tools.setCellContents({ sheet: 0, col: 1, row: 0, value: 200 }); |
32 | | -tools.getRange({ sheet: 0, startCol: 0, startRow: 0, endCol: 1, endRow: 2 }); |
33 | | -// → [['Revenue', 200], ['Cost', 60], ['Profit', 140]] |
34 | | - |
35 | | -// Agent: "What drives the profit number?" |
36 | | -tools.getDependents({ sheet: 0, col: 1, row: 0 }); |
37 | | -// → [{ sheet: 0, col: 1, row: 2 }] — Revenue flows into Profit |
| 35 | +// Pass the spreadsheet tools straight into generateText. |
| 36 | +const result = await generateText({ |
| 37 | + model: openai('gpt-4o'), |
| 38 | + tools: createSpreadsheetTools(hf), |
| 39 | + prompt: 'What drives the profit number, and what happens if revenue doubles?', |
| 40 | +}); |
38 | 41 | ``` |
39 | 42 |
|
| 43 | +A single import, one extra line in `tools`, and the model can evaluate formulas, read ranges, and edit cells through the SDK — without inventing numbers. |
| 44 | + |
40 | 45 | ## Use cases |
41 | 46 |
|
42 | | -- **Explain a sheet** —ask an agent to summarize what a spreadsheet does, which cells are inputs, and how outputs are derived. |
43 | | -- **Generate a what-if scenario** —let the model tweak assumptions (price, volume, rate) and observe how results change in real time. |
44 | | -- **Validate and clean data** —have the agent scan ranges for errors, missing values, or inconsistencies and fix them with formulas or direct edits. |
45 | | -- **Create formulas from natural language** —describe a calculation in plain English and let the model write and verify the correct Excel formula. |
| 47 | +- **Explain the spreadsheet** — ask the agent what a workbook does, which cells are inputs, and how each output is derived; get answers grounded in real formula evaluation. |
| 48 | +- **What-if scenarios and forecasting** — the agent tweaks assumptions and reports how downstream results change, deterministically. |
| 49 | +- **Validate and clean data** — the agent scans ranges for errors, missing values, or inconsistencies and fixes them in place. |
| 50 | +- **Generate formulas from natural language** — the agent translates a plain-English calculation into a verified, working Excel formula. |
| 51 | +- **Financial modeling and reporting** — NPV, IRR, amortization, KPI rollups, and other quantitative workflows where the answer must be exact and auditable. |
| 52 | + |
| 53 | +## Get early access |
46 | 54 |
|
47 | | -## Beta access |
| 55 | +::: tip Be the first to try it |
| 56 | +We're actively building this integration. Drop your email and we'll notify you the moment the first beta lands — so you can try it before the public release. |
48 | 57 |
|
49 | | -::: tip |
50 | | -[Sign up for beta access](https://2fmjvg.share-eu1.hsforms.com/2e6drCkuLTn-1RuiYB91eJA) |
| 58 | +[Join the early access list →](https://2fmjvg.share-eu1.hsforms.com/2e6drCkuLTn-1RuiYB91eJA) |
51 | 59 | ::: |
| 60 | + |
| 61 | +## Links |
| 62 | + |
| 63 | +- [Vercel AI SDK documentation](https://sdk.vercel.ai/docs) |
| 64 | +- [HyperFormula on GitHub](https://github.com/handsontable/hyperformula) |
| 65 | +- [HyperFormula on npm](https://www.npmjs.com/package/hyperformula) |
| 66 | +- [Built-in functions](built-in-functions.md) |
| 67 | +- [Custom functions](custom-functions.md) |
0 commit comments