@xbbg/langgraph 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -190
- package/README.md +222 -182
- package/dist/index.js +489 -365
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,182 +1,222 @@
|
|
|
1
|
-
# @xbbg/langgraph
|
|
2
|
-
|
|
3
|
-
LangChain/LangGraph-compatible Bloomberg tools backed by [`@xbbg/core`](../js-xbbg/README.md).
|
|
4
|
-
|
|
5
|
-
This package is a reusable tool adapter. It is not a chat app, HTTP server, MCP server, browser package, or agent framework.
|
|
6
|
-
|
|
7
|
-
## Prerequisites
|
|
8
|
-
|
|
9
|
-
Bloomberg connectivity is still provided by `@xbbg/core`: an installed Bloomberg Terminal/Desktop API, B-PIPE, SAPI, or ZFP setup plus Bloomberg SDK runtime libraries must be available on the server running the tools.
|
|
10
|
-
|
|
11
|
-
## Install
|
|
12
|
-
|
|
13
|
-
Tool package only:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @xbbg/langgraph @xbbg/core @langchain/core
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
LangGraph app:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm install @xbbg/langgraph @xbbg/core @langchain/core @langchain/langgraph
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Current LangChain agent app:
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install @xbbg/langgraph @xbbg/core @langchain/core langchain
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Agent guidance
|
|
32
|
-
|
|
33
|
-
Append the exported instructions to your system prompt:
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
import { BLOOMBERG_TOOL_INSTRUCTIONS } from "@xbbg/langgraph";
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
The instructions tell the model to ask clarifying questions for ambiguous tickers, fields, date ranges, currencies, periodicity, overrides, or universes; request `/isin/{isin}` for ISIN identifiers and `/cusip/{cusip}` for CUSIPs; use `xbbg_bflds` for unknown fields; prefer finite recipe tools for BEQS/YAS/universe workflows; use bounded snapshot tools instead of open subscriptions; keep requests bounded; and report empty, truncated, or errored responses directly.
|
|
40
|
-
|
|
41
|
-
## LangChain `createAgent` example
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
import { createAgent } from "langchain";
|
|
45
|
-
import { ChatOpenAI } from "@langchain/openai";
|
|
46
|
-
import { createAllBloombergTools, BLOOMBERG_TOOL_INSTRUCTIONS } from "@xbbg/langgraph";
|
|
47
|
-
|
|
48
|
-
const tools = createAllBloombergTools({
|
|
49
|
-
maxSecurities: 10,
|
|
50
|
-
maxFields: 10,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const agent = createAgent({
|
|
54
|
-
model: new ChatOpenAI({ model: "gpt-4.1" }),
|
|
55
|
-
tools,
|
|
56
|
-
systemPrompt: BLOOMBERG_TOOL_INSTRUCTIONS,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const result = await agent.invoke({
|
|
60
|
-
messages: [{ role: "user", content: "Get
|
|
61
|
-
});
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## LangGraph example
|
|
65
|
-
|
|
66
|
-
`createReactAgent` from `@langchain/langgraph/prebuilt` is deprecated upstream in favor of `createAgent` from `langchain`, but it is still common in LangGraph examples and accepts these tools because they are normal LangChain tools.
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
70
|
-
import { ChatOpenAI } from "@langchain/openai";
|
|
71
|
-
import { createBloombergTools, BLOOMBERG_TOOL_INSTRUCTIONS } from "@xbbg/langgraph";
|
|
72
|
-
|
|
73
|
-
const agent = createReactAgent({
|
|
74
|
-
llm: new ChatOpenAI({ model: "gpt-4.1" }),
|
|
75
|
-
tools: createBloombergTools({ maxSecurities: 5, maxFields: 5 }),
|
|
76
|
-
prompt: BLOOMBERG_TOOL_INSTRUCTIONS,
|
|
77
|
-
});
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
For custom graphs,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
- `
|
|
126
|
-
- `
|
|
127
|
-
- `
|
|
128
|
-
- `
|
|
129
|
-
- `
|
|
130
|
-
- `
|
|
131
|
-
- `
|
|
132
|
-
- `
|
|
133
|
-
- `
|
|
134
|
-
- `
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
import { createBloombergTools } from "@xbbg/langgraph";
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
- `
|
|
162
|
-
- `
|
|
163
|
-
- `
|
|
164
|
-
- `
|
|
165
|
-
- `
|
|
166
|
-
- `
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
1
|
+
# @xbbg/langgraph
|
|
2
|
+
|
|
3
|
+
LangChain/LangGraph-compatible Bloomberg tools backed by [`@xbbg/core`](../js-xbbg/README.md).
|
|
4
|
+
|
|
5
|
+
This package is a reusable tool adapter. It is not a chat app, HTTP server, MCP server, browser package, or agent framework.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
Bloomberg connectivity is still provided by `@xbbg/core`: an installed Bloomberg Terminal/Desktop API, B-PIPE, SAPI, or ZFP setup plus Bloomberg SDK runtime libraries must be available on the server running the tools.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
Tool package only:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @xbbg/langgraph @xbbg/core @langchain/core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
LangGraph app:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @xbbg/langgraph @xbbg/core @langchain/core @langchain/langgraph @langchain/openai
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Current LangChain agent app:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @xbbg/langgraph @xbbg/core @langchain/core langchain @langchain/openai
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Agent guidance
|
|
32
|
+
|
|
33
|
+
Append the exported instructions to your system prompt:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { BLOOMBERG_TOOL_INSTRUCTIONS } from "@xbbg/langgraph";
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The instructions tell the model to ask clarifying questions for ambiguous tickers, fields, date ranges, currencies, periodicity, overrides, or universes; request `/isin/{isin}` for ISIN identifiers and `/cusip/{cusip}` for CUSIPs; use `xbbg_bflds` for unknown fields; prefer finite recipe tools for BEQS/YAS/universe workflows; use bounded snapshot tools instead of open subscriptions; keep requests bounded; and report empty, truncated, or errored responses directly.
|
|
40
|
+
|
|
41
|
+
## LangChain `createAgent` example
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createAgent } from "langchain";
|
|
45
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
46
|
+
import { createAllBloombergTools, BLOOMBERG_TOOL_INSTRUCTIONS } from "@xbbg/langgraph";
|
|
47
|
+
|
|
48
|
+
const tools = createAllBloombergTools({
|
|
49
|
+
maxSecurities: 10,
|
|
50
|
+
maxFields: 10,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const agent = createAgent({
|
|
54
|
+
model: new ChatOpenAI({ model: "gpt-4.1" }),
|
|
55
|
+
tools,
|
|
56
|
+
systemPrompt: BLOOMBERG_TOOL_INSTRUCTIONS,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const result = await agent.invoke({
|
|
60
|
+
messages: [{ role: "user", content: "Get <FIELD> for <TICKER> <MARKET_SECTOR>." }],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## LangGraph example
|
|
65
|
+
|
|
66
|
+
`createReactAgent` from `@langchain/langgraph/prebuilt` is deprecated upstream in favor of `createAgent` from `langchain`, but it is still common in LangGraph examples and accepts these tools because they are normal LangChain tools.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
70
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
71
|
+
import { createBloombergTools, BLOOMBERG_TOOL_INSTRUCTIONS } from "@xbbg/langgraph";
|
|
72
|
+
|
|
73
|
+
const agent = createReactAgent({
|
|
74
|
+
llm: new ChatOpenAI({ model: "gpt-4.1" }),
|
|
75
|
+
tools: createBloombergTools({ maxSecurities: 5, maxFields: 5 }),
|
|
76
|
+
prompt: BLOOMBERG_TOOL_INSTRUCTIONS,
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For custom graphs, bind the tools to your model and route tool calls through LangGraph's `ToolNode`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { AIMessage } from "@langchain/core/messages";
|
|
84
|
+
import { END, MessagesAnnotation, START, StateGraph } from "@langchain/langgraph";
|
|
85
|
+
import { ToolNode } from "@langchain/langgraph/prebuilt";
|
|
86
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
87
|
+
import { createBloombergTools, BLOOMBERG_TOOL_INSTRUCTIONS } from "@xbbg/langgraph";
|
|
88
|
+
|
|
89
|
+
const tools = createBloombergTools({ maxSecurities: 5, maxFields: 5 });
|
|
90
|
+
const model = new ChatOpenAI({ model: "gpt-4.1" }).bindTools(tools);
|
|
91
|
+
const toolNode = new ToolNode(tools);
|
|
92
|
+
|
|
93
|
+
const callModel = async (state: typeof MessagesAnnotation.State) => ({
|
|
94
|
+
messages: [
|
|
95
|
+
await model.invoke([
|
|
96
|
+
{ role: "system", content: BLOOMBERG_TOOL_INSTRUCTIONS },
|
|
97
|
+
...state.messages,
|
|
98
|
+
]),
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const route = (state: typeof MessagesAnnotation.State) => {
|
|
103
|
+
const last = state.messages.at(-1);
|
|
104
|
+
return last instanceof AIMessage && last.tool_calls?.length ? "tools" : END;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const graph = new StateGraph(MessagesAnnotation)
|
|
108
|
+
.addNode("model", callModel)
|
|
109
|
+
.addNode("tools", toolNode)
|
|
110
|
+
.addEdge(START, "model")
|
|
111
|
+
.addConditionalEdges("model", route)
|
|
112
|
+
.addEdge("tools", "model")
|
|
113
|
+
.compile();
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
All tools use LangChain `responseFormat: "content_and_artifact"`. In `ToolNode`, the tool message content starts with a compact summary and then includes bounded model-readable JSON; `artifact` contains the structured bounded envelope for application code.
|
|
117
|
+
|
|
118
|
+
## Tool factories
|
|
119
|
+
|
|
120
|
+
Core Bloomberg request tools:
|
|
121
|
+
|
|
122
|
+
- `xbbg_bdp` - reference/current fields for a bounded securities list and explicit fields list.
|
|
123
|
+
- `xbbg_bdh` - historical time series; requires explicit `start` and `end`.
|
|
124
|
+
- `xbbg_bds` - one Bloomberg bulk/table field.
|
|
125
|
+
- `xbbg_bdib` - intraday bars; requires explicit `start`, `end`, and `interval`.
|
|
126
|
+
- `xbbg_bdtick` - intraday ticks; requires explicit `start`, `end`, and event types when the default stream is not intended.
|
|
127
|
+
- `xbbg_bql` - BQL expressions only.
|
|
128
|
+
- `xbbg_bsrch` - Bloomberg search/grid requests, not normal security lookup.
|
|
129
|
+
- `xbbg_bqr` - Bloomberg Quote Request / fixed-income dealer quotes; prefer identifiers such as `/isin/<ISIN>@<QUOTE_SOURCE> <MARKET_SECTOR>`.
|
|
130
|
+
- `xbbg_bflds` - field metadata/search; use first for uncertain mnemonics.
|
|
131
|
+
- `xbbg_beqs` - named Bloomberg BEQS equity screens.
|
|
132
|
+
- `xbbg_yas` - fixed-income YAS recipe fields for yield, duration, spread, benchmark, or price analytics.
|
|
133
|
+
- `xbbg_preferreds` - preferred stock discovery for one equity ticker.
|
|
134
|
+
- `xbbg_corporate_bonds` - corporate bond universe query for one issuer/company ticker.
|
|
135
|
+
- `xbbg_index_members` - index constituents through the core index recipe.
|
|
136
|
+
- `xbbg_resolve_isins` - raw ISIN-to-security resolution; pass raw ISIN strings to this recipe only.
|
|
137
|
+
- `xbbg_issuer_isins` - issuer/bond ISIN workflow starting from known bond ISIN strings.
|
|
138
|
+
- `xbbg_etf_holdings` - ETF holdings for one ETF ticker.
|
|
139
|
+
- `xbbg_stream_snapshot` - bounded `//blp/mktdata` live observation that always unsubscribes.
|
|
140
|
+
- `xbbg_mktbar_snapshot` - bounded `//blp/mktbar` live bar observation for one ticker.
|
|
141
|
+
- `xbbg_depth_snapshot` - bounded `//blp/mktdepthdata` market-depth observation for one ticker.
|
|
142
|
+
|
|
143
|
+
For raw identifiers, ask for or pass Bloomberg's identifier syntax directly: `/isin/<ISIN>` for ISINs and `/cusip/<CUSIP>` for CUSIPs.
|
|
144
|
+
BQL is passed as one complete expression string. Use placeholder shapes such as `get(<FIELD>) for('<TICKER> <MARKET_SECTOR>')`, `get(<FIELD_1>, <FIELD_2>) for(['<TICKER_1> <MARKET_SECTOR>', '<TICKER_2> <MARKET_SECTOR>'])`, `get(<FIELD>, <WEIGHT_FIELD>) for(holdings('<ETF_TICKER> <MARKET_SECTOR>'))`, or `get(<FIELD>) for(members('<INDEX_TICKER> <MARKET_SECTOR>')) with(...)`. Prefer `xbbg_bdp`/`xbbg_bdh` for simple reference or historical requests.
|
|
145
|
+
|
|
146
|
+
Dealer quote / BQR workflows in xbbg use fixed-income identifiers with a quote source, for example `/isin/<ISIN>@<QUOTE_SOURCE> <MARKET_SECTOR>`; use `xbbg_bqr` for that workflow and `xbbg_bdtick` for raw intraday ticks.
|
|
147
|
+
|
|
148
|
+
Streaming surfaces are intentionally exposed only as bounded snapshot tools. Each snapshot requires `maxUpdates`, applies the configured `maxStreamUpdates`/`maxStreamWaitMs` caps, stops on count, timeout, or stream completion, and calls `unsubscribe(false)` unless `drain: true` is explicitly provided. The package does not expose open-ended async subscription iterators as agent tools.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { createBloombergTools, createBdpTool } from "@xbbg/langgraph";
|
|
152
|
+
|
|
153
|
+
const tools = createBloombergTools();
|
|
154
|
+
const bdpOnly = createBdpTool({ maxSecurities: 3 });
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Extension helper tools:
|
|
158
|
+
|
|
159
|
+
- `xbbg_ext_ticker` - ticker hygiene before live requests: parse, normalize lists, filter equity tickers, check specific contracts, and validate generic futures tickers.
|
|
160
|
+
- `xbbg_ext_futures` - futures construction and selection: month-code lookup, build a specific contract, generate candidates from a generic, rank contracts, filter by cycle, and filter valid contracts for a date.
|
|
161
|
+
- `xbbg_ext_cdx` - CDX workflows: parse CDX tickers, roll to previous series, resolve generic to specific series, and run predefined CDX info/pricing/risk field bundles.
|
|
162
|
+
- `xbbg_ext_currency` - currency planning: build FX pair metadata, test same-currency requests, and identify currencies needing conversion to a target.
|
|
163
|
+
- `xbbg_ext_bql_builder` - BQL query builders for preferred stocks, corporate bonds, and ETF holdings; prefer these over hand-writing those query shapes.
|
|
164
|
+
- `xbbg_ext_market_session` - exchange sessions and timezones: derive sessions, infer timezone, convert local session times to UTC, fetch market rules, compute turnover/BQR default ranges, and inspect exchange overrides.
|
|
165
|
+
- `xbbg_ext_yas_overrides` - build flat YAS override maps for lower-level fixed-income BDP workflows. Prefer `xbbg_yas` when you want the actual YAS recipe result.
|
|
166
|
+
- `xbbg_ext_constants` - static constants and formatting helpers for dates, futures months, dividend types, and ETF/dividend columns.
|
|
167
|
+
- `xbbg_ext_columns` - rename helpers for dividend, ETF, and earnings-shaped Bloomberg responses.
|
|
168
|
+
- `xbbg_ext_calculate` - small numeric helper for level percentage calculations.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { createBloombergExtTools, createAllBloombergTools } from "@xbbg/langgraph";
|
|
172
|
+
|
|
173
|
+
const helperTools = createBloombergExtTools();
|
|
174
|
+
const allTools = createAllBloombergTools({
|
|
175
|
+
disabledTools: ["xbbg_bql", "xbbg_bsrch"],
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Engine handling
|
|
180
|
+
|
|
181
|
+
By default the first tool invocation lazily imports `@xbbg/core`, calls `connect(engineConfig)`, and reuses the resulting engine across the tool set. Parallel LangGraph tool calls share the same in-flight initialization promise.
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import * as xbbg from "@xbbg/core";
|
|
185
|
+
import { createBloombergTools } from "@xbbg/langgraph";
|
|
186
|
+
|
|
187
|
+
const engine = await xbbg.connect({ host: "localhost", port: 8194 });
|
|
188
|
+
const tools = createBloombergTools({ engine });
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Limits and outputs
|
|
192
|
+
|
|
193
|
+
Defaults:
|
|
194
|
+
|
|
195
|
+
- `maxSecurities = 25`
|
|
196
|
+
- `maxFields = 25`
|
|
197
|
+
- `maxRows = 500`
|
|
198
|
+
- `maxStringChars = 2000`
|
|
199
|
+
- `maxStreamUpdates = 10`
|
|
200
|
+
- `maxStreamWaitMs = 15000`
|
|
201
|
+
|
|
202
|
+
Each tool uses `backend: "json"` for finite request results and LangChain `content_and_artifact` output. The model-facing content starts with a short summary and then includes bounded JSON data:
|
|
203
|
+
|
|
204
|
+
```text
|
|
205
|
+
xbbg_bdp: 1 row; truncated=false
|
|
206
|
+
{"tool":"xbbg_bdp","rowCount":1,"truncated":false,"data":[{"security":"<TICKER> <MARKET_SECTOR>","field":"<FIELD>","value":"<VALUE>"}]}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The artifact is the same bounded structured envelope for application code:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"tool": "xbbg_bdp",
|
|
214
|
+
"rowCount": 1,
|
|
215
|
+
"truncated": false,
|
|
216
|
+
"data": [{ "security": "<TICKER> <MARKET_SECTOR>", "field": "<FIELD>", "value": "<VALUE>" }]
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
When invoking tools outside an agent graph and you need the artifact, invoke with a tool-call id (or use LangGraph `ToolNode`) so LangChain returns a `ToolMessage` with `artifact`.
|
|
221
|
+
|
|
222
|
+
Use smaller factories or `disabledTools` when broad BQL/search helpers are not appropriate for a deployment.
|