Repository navigation
feat(examples): add FXMacroData macro research example #1438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
roberttidball
wants to merge
6
commits into
VoltAgent:main
Choose a base branch
from
fxmacrodata:examples/with-fxmacrodata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+513
−0
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d1f7fb
feat(examples): add FXMacroData macro research example
roberttidball beceaae
fix(examples): refuse redirects, keep the API key out of errors, chec…
roberttidball 7471eae
fix(examples): NodeNext resolution, stricter dates and slugs, catalog…
roberttidball 26d53d8
docs(examples): say which with-fxmacrodata requests need an FXMacroDa…
roberttidball e560fa3
fix(examples): tell the model keyless FXMacroData releases are delaye…
roberttidball b92b800
fix(examples): bind the with-fxmacrodata server to 127.0.0.1
roberttidball File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| OPENAI_API_KEY=your_openai_api_key_here | ||
| # Optional: USD data works without a key | ||
| FXMACRODATA_API_KEY= | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # VoltAgent with FXMacroData | ||
|
|
||
| This example gives a VoltAgent research agent tools for official macroeconomic data from [FXMacroData](https://fxmacrodata.com/documentation/reference?utm_source=github&utm_medium=referral&utm_campaign=voltagent&utm_content=readme): indicator releases with their publication times, release calendars and FX rates. | ||
|
|
||
| ## Features | ||
|
|
||
| - List the indicators available for a currency (CPI, GDP, policy rate, payrolls, bond yields and more) | ||
| - Fetch released values with the period, the publication timestamp and the official source link | ||
| - Fetch the upcoming release calendar, with times in UTC and the publisher's local time | ||
| - Fetch daily FX rates for a currency pair | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. **OpenAI API Key**: Used by the example agent model | ||
| 2. **FXMacroData API Key** (optional): USD releases from the last 90 days, the USD calendar and the indicator catalogue work without a key. Older history, other currencies and FX rates need one, see [plans](https://fxmacrodata.com/subscribe?utm_source=github&utm_medium=referral&utm_campaign=voltagent&utm_content=readme) | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Install dependencies: | ||
|
|
||
| ```bash | ||
| pnpm install | ||
| ``` | ||
|
|
||
| 2. Configure environment variables: | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| Then edit `.env`: | ||
|
|
||
| ```env | ||
| OPENAI_API_KEY=your_openai_api_key_here | ||
| FXMACRODATA_API_KEY= | ||
| ``` | ||
|
|
||
| 3. Run the example: | ||
|
|
||
| ```bash | ||
| pnpm dev | ||
| ``` | ||
|
|
||
| The agent runs on the default VoltAgent server port and exposes one agent named `macroResearchAgent`. | ||
|
|
||
| ## Tools Available | ||
|
|
||
| ### 1. List Indicators | ||
|
|
||
| - **Purpose**: List indicator slugs, names, units and sources for a currency | ||
| - **Endpoint**: `GET /v1/data_catalogue/{currency}` | ||
|
|
||
| ### 2. Get Indicator History | ||
|
|
||
| - **Purpose**: Released values for one indicator, newest first | ||
| - **Endpoint**: `GET /v1/announcements/{currency}/{indicator}` | ||
| - **Parameters**: | ||
| - `currency`: Three-letter code such as `usd` | ||
| - `indicator`: Slug such as `inflation` or `policy_rate` | ||
| - `startDate`, `endDate`: Optional `YYYY-MM-DD` bounds | ||
| - `limit`: Maximum rows (default 12) | ||
|
|
||
| ### 3. Get Release Calendar | ||
|
|
||
| - **Purpose**: Scheduled releases for a currency | ||
| - **Endpoint**: `GET /v1/calendar/{currency}` | ||
| - **Parameters**: | ||
| - `indicator`: Optional slug filter | ||
| - `startDate`, `endDate`: Optional `YYYY-MM-DD` bounds | ||
|
|
||
| ### 4. Get FX Rates | ||
|
|
||
| - **Purpose**: Daily rates for a currency pair (needs an API key) | ||
| - **Endpoint**: `GET /v1/forex/{base}/{quote}` | ||
|
|
||
| ## Example Prompts | ||
|
|
||
| - "What was the latest US CPI print and when was it published?" | ||
| - "When are the next US payrolls and CPI releases?" | ||
| - "How has the Fed's policy rate moved this year?" | ||
| - "Compare the latest euro area and UK inflation" (needs an API key) | ||
|
|
||
| ## Notes | ||
|
|
||
| The tools return the API response unchanged, so the agent sees units, source links and data-quality fields as published. Redirects are refused, so the key header is only ever sent to `api.fxmacrodata.com`, and the key is removed from error text. Responses are not cached; the keyless tier has a fair-use allowance of 100 requests per day. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "name": "voltagent-example-with-fxmacrodata", | ||
| "author": "", | ||
| "dependencies": { | ||
| "@voltagent/cli": "^0.1.21", | ||
| "@voltagent/core": "^2.11.0", | ||
| "@voltagent/logger": "^2.0.2", | ||
| "@voltagent/server-hono": "^2.0.14", | ||
| "ai": "^6.0.0", | ||
| "zod": "^3.25.76" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^24.2.1", | ||
| "tsx": "^4.21.0", | ||
| "typescript": "^5.8.2" | ||
| }, | ||
| "keywords": [ | ||
| "agent", | ||
| "ai", | ||
| "economic-calendar", | ||
| "fxmacrodata", | ||
| "macroeconomics", | ||
| "voltagent" | ||
| ], | ||
| "license": "MIT", | ||
| "private": true, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/VoltAgent/voltagent.git", | ||
| "directory": "examples/with-fxmacrodata" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "dev": "tsx watch --env-file=.env ./src", | ||
| "start": "node dist/index.js", | ||
| "volt": "volt" | ||
| }, | ||
| "type": "module" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { Agent, VoltAgent } from "@voltagent/core"; | ||
| import { createPinoLogger } from "@voltagent/logger"; | ||
| import { honoServer } from "@voltagent/server-hono"; | ||
| import { fxmacrodataTools } from "./tools.js"; | ||
|
|
||
| const logger = createPinoLogger({ | ||
| name: "fxmacrodata-agent", | ||
| level: "info", | ||
| }); | ||
|
|
||
| const macroResearchAgent = new Agent({ | ||
| name: "macro-research-agent", | ||
| instructions: `You answer macroeconomic and FX questions with FXMacroData tools. | ||
|
|
||
| Use listIndicators when you need an indicator slug, getIndicatorHistory for released values, | ||
| getReleaseCalendar for what is scheduled next, and getFxRates for exchange rates. | ||
| Quote each value with the period it refers to and when it was published, and cite the source link. | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
| If a tool returns HTTP 401 or 403, say that the currency or dataset needs an FXMacroData API key | ||
| rather than guessing a number.`, | ||
| model: "openai/gpt-4o-mini", | ||
| tools: fxmacrodataTools, | ||
| }); | ||
|
|
||
| new VoltAgent({ | ||
| agents: { | ||
| macroResearchAgent, | ||
| }, | ||
| logger, | ||
| server: honoServer(), | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.