@xbbg/langgraph 1.2.6
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 -0
- package/README.md +182 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +2543 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2019 Alpha x1
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,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
|
|
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 PX_LAST for AAPL US Equity." }],
|
|
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, pass the returned tools to LangGraph's `ToolNode`.
|
|
81
|
+
|
|
82
|
+
All tools use LangChain `responseFormat: "content_and_artifact"`. In `ToolNode`, the tool message content is a compact summary for the model, while `artifact` contains the bounded structured envelope for application code.
|
|
83
|
+
|
|
84
|
+
## Tool factories
|
|
85
|
+
|
|
86
|
+
Core Bloomberg request tools:
|
|
87
|
+
|
|
88
|
+
- `xbbg_bdp` - reference/current fields such as `PX_LAST`, `NAME`, `CUR_MKT_CAP`.
|
|
89
|
+
- `xbbg_bdh` - historical time series; requires explicit `start` and `end`.
|
|
90
|
+
- `xbbg_bds` - one Bloomberg bulk/table field such as index members.
|
|
91
|
+
- `xbbg_bdib` - intraday bars; requires explicit `start`, `end`, and `interval`.
|
|
92
|
+
- `xbbg_bdtick` - intraday ticks; requires explicit `start`, `end`, and event types when not using `TRADE`.
|
|
93
|
+
- `xbbg_bql` - BQL expressions only.
|
|
94
|
+
- `xbbg_bsrch` - Bloomberg search/grid requests, not normal security lookup.
|
|
95
|
+
- `xbbg_bqr` - Bloomberg Quote Request / fixed-income dealer quotes; prefer identifiers such as `/isin/US037833FB15@MSG1 Corp`.
|
|
96
|
+
- `xbbg_bflds` - field metadata/search; use first for uncertain mnemonics.
|
|
97
|
+
- `xbbg_beqs` - named Bloomberg BEQS equity screens.
|
|
98
|
+
- `xbbg_yas` - fixed-income YAS recipe fields such as `YAS_BOND_YLD`, `YAS_MOD_DUR`, `YAS_ZSPREAD`, and `YAS_BOND_PX`.
|
|
99
|
+
- `xbbg_preferreds` - preferred stock discovery for one equity ticker.
|
|
100
|
+
- `xbbg_corporate_bonds` - corporate bond universe query for one issuer/company ticker.
|
|
101
|
+
- `xbbg_index_members` - index constituents through the core index recipe.
|
|
102
|
+
- `xbbg_resolve_isins` - raw ISIN-to-security resolution; pass raw ISIN strings to this recipe only.
|
|
103
|
+
- `xbbg_issuer_isins` - issuer/bond ISIN workflow starting from known bond ISIN strings.
|
|
104
|
+
- `xbbg_etf_holdings` - ETF holdings for one ETF ticker.
|
|
105
|
+
- `xbbg_stream_snapshot` - bounded `//blp/mktdata` live observation that always unsubscribes.
|
|
106
|
+
- `xbbg_mktbar_snapshot` - bounded `//blp/mktbar` live bar observation for one ticker.
|
|
107
|
+
- `xbbg_depth_snapshot` - bounded `//blp/mktdepthdata` market-depth observation for one ticker.
|
|
108
|
+
|
|
109
|
+
For raw identifiers, ask for or pass Bloomberg's identifier syntax directly: `/isin/US0378331005` for ISINs and `/cusip/037833100` for CUSIPs.
|
|
110
|
+
BQL is passed as one complete expression string. Use shapes such as `get(px_last) for('AAPL US Equity')`, `get(px_last, volume) for(['IBM US Equity', 'AAPL US Equity'])`, `get(id_isin, weights) for(holdings('SPY US Equity'))`, or `get(px_last) for(members('SPX Index')) with(...)`. Prefer `xbbg_bdp`/`xbbg_bdh` for simple reference or historical requests.
|
|
111
|
+
|
|
112
|
+
Dealer quote / BQR workflows in xbbg use fixed-income identifiers with a quote source, for example `/isin/US037833FB15@MSG1 Corp`; use `xbbg_bqr` for that workflow and `xbbg_bdtick` for raw intraday ticks.
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { createBloombergTools, createBdpTool } from "@xbbg/langgraph";
|
|
118
|
+
|
|
119
|
+
const tools = createBloombergTools();
|
|
120
|
+
const bdpOnly = createBdpTool({ maxSecurities: 3 });
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Extension helper tools:
|
|
124
|
+
|
|
125
|
+
- `xbbg_ext_ticker` - ticker hygiene before live requests: parse, normalize lists, filter equity tickers, check specific contracts, and validate generic futures tickers.
|
|
126
|
+
- `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.
|
|
127
|
+
- `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.
|
|
128
|
+
- `xbbg_ext_currency` - currency planning: build FX pair metadata, test same-currency requests, and identify currencies needing conversion to a target.
|
|
129
|
+
- `xbbg_ext_bql_builder` - BQL query builders for preferred stocks, corporate bonds, and ETF holdings; prefer these over hand-writing those query shapes.
|
|
130
|
+
- `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.
|
|
131
|
+
- `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.
|
|
132
|
+
- `xbbg_ext_constants` - static constants and formatting helpers for dates, futures months, dividend types, and ETF/dividend columns.
|
|
133
|
+
- `xbbg_ext_columns` - rename helpers for dividend, ETF, and earnings-shaped Bloomberg responses.
|
|
134
|
+
- `xbbg_ext_calculate` - small numeric helper for level percentage calculations.
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { createBloombergExtTools, createAllBloombergTools } from "@xbbg/langgraph";
|
|
138
|
+
|
|
139
|
+
const helperTools = createBloombergExtTools();
|
|
140
|
+
const allTools = createAllBloombergTools({
|
|
141
|
+
disabledTools: ["xbbg_bql", "xbbg_bsrch"],
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Engine handling
|
|
146
|
+
|
|
147
|
+
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.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import * as xbbg from "@xbbg/core";
|
|
151
|
+
import { createBloombergTools } from "@xbbg/langgraph";
|
|
152
|
+
|
|
153
|
+
const engine = await xbbg.connect({ host: "localhost", port: 8194 });
|
|
154
|
+
const tools = createBloombergTools({ engine });
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Limits and outputs
|
|
158
|
+
|
|
159
|
+
Defaults:
|
|
160
|
+
|
|
161
|
+
- `maxSecurities = 25`
|
|
162
|
+
- `maxFields = 25`
|
|
163
|
+
- `maxRows = 500`
|
|
164
|
+
- `maxStringChars = 2000`
|
|
165
|
+
- `maxStreamUpdates = 10`
|
|
166
|
+
- `maxStreamWaitMs = 15000`
|
|
167
|
+
|
|
168
|
+
Each tool uses `backend: "json"` for finite request results and LangChain `content_and_artifact` output. The model-facing content is a short summary, for example:
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
xbbg_bdp: 1 row; truncated=false
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The artifact is the bounded structured envelope:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{ "tool": "xbbg_bdp", "rowCount": 1, "truncated": false, "data": [{ "ticker": "AAPL US Equity" }] }
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
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`.
|
|
181
|
+
|
|
182
|
+
Use smaller factories or `disabledTools` when broad BQL/search helpers are not appropriate for a deployment.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as xbbg from '@xbbg/core';
|
|
2
|
+
import { StructuredToolInterface } from '@langchain/core/tools';
|
|
3
|
+
|
|
4
|
+
type XbbgCoreModule = typeof xbbg;
|
|
5
|
+
type XbbgEngineLike = Pick<Awaited<ReturnType<XbbgCoreModule["connect"]>>, "bdp" | "bdh" | "bds" | "bdib" | "bdtick" | "bql" | "bsrch" | "bqr" | "bflds" | "beqs" | "yas" | "preferreds" | "corporateBonds" | "indexMembers" | "resolveIsins" | "issuerIsins" | "etfHoldings" | "stream" | "mktbar" | "depth">;
|
|
6
|
+
type XbbgCoreLike = Pick<XbbgCoreModule, "connect" | "ext">;
|
|
7
|
+
|
|
8
|
+
declare const BLOOMBERG_TOOL_NAMES: readonly ["xbbg_bdp", "xbbg_bdh", "xbbg_bds", "xbbg_bdib", "xbbg_bdtick", "xbbg_bql", "xbbg_bsrch", "xbbg_bqr", "xbbg_bflds", "xbbg_beqs", "xbbg_yas", "xbbg_preferreds", "xbbg_corporate_bonds", "xbbg_index_members", "xbbg_resolve_isins", "xbbg_issuer_isins", "xbbg_etf_holdings", "xbbg_stream_snapshot", "xbbg_mktbar_snapshot", "xbbg_depth_snapshot", "xbbg_ext_ticker", "xbbg_ext_futures", "xbbg_ext_cdx", "xbbg_ext_currency", "xbbg_ext_bql_builder", "xbbg_ext_market_session", "xbbg_ext_yas_overrides", "xbbg_ext_constants", "xbbg_ext_columns", "xbbg_ext_calculate"];
|
|
9
|
+
type BloombergToolName = (typeof BLOOMBERG_TOOL_NAMES)[number];
|
|
10
|
+
interface BloombergToolsOptions {
|
|
11
|
+
readonly engine?: XbbgEngineLike;
|
|
12
|
+
readonly engineConfig?: xbbg.EngineConfig;
|
|
13
|
+
readonly core?: XbbgCoreLike;
|
|
14
|
+
readonly maxSecurities?: number;
|
|
15
|
+
readonly maxFields?: number;
|
|
16
|
+
readonly maxRows?: number;
|
|
17
|
+
readonly maxStringChars?: number;
|
|
18
|
+
readonly maxBqlQueryChars?: number;
|
|
19
|
+
readonly maxSearchSpecChars?: number;
|
|
20
|
+
readonly maxStreamUpdates?: number;
|
|
21
|
+
readonly maxStreamWaitMs?: number;
|
|
22
|
+
readonly validateFields?: boolean;
|
|
23
|
+
readonly disabledTools?: readonly BloombergToolName[];
|
|
24
|
+
}
|
|
25
|
+
interface NormalizedBloombergToolsOptions {
|
|
26
|
+
readonly engine?: XbbgEngineLike;
|
|
27
|
+
readonly engineConfig?: xbbg.EngineConfig;
|
|
28
|
+
readonly core?: XbbgCoreLike;
|
|
29
|
+
readonly maxSecurities: number;
|
|
30
|
+
readonly maxFields: number;
|
|
31
|
+
readonly maxRows: number;
|
|
32
|
+
readonly maxStringChars: number;
|
|
33
|
+
readonly maxBqlQueryChars: number;
|
|
34
|
+
readonly maxSearchSpecChars: number;
|
|
35
|
+
readonly maxStreamUpdates: number;
|
|
36
|
+
readonly maxStreamWaitMs: number;
|
|
37
|
+
readonly validateFields: boolean | undefined;
|
|
38
|
+
readonly disabledTools: ReadonlySet<BloombergToolName>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type BloombergTool = StructuredToolInterface;
|
|
42
|
+
declare function createBdpTool(options?: BloombergToolsOptions): BloombergTool;
|
|
43
|
+
declare function createBdhTool(options?: BloombergToolsOptions): BloombergTool;
|
|
44
|
+
declare function createBdsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
45
|
+
declare function createBdibTool(options?: BloombergToolsOptions): BloombergTool;
|
|
46
|
+
declare function createBdtickTool(options?: BloombergToolsOptions): BloombergTool;
|
|
47
|
+
declare function createBqlTool(options?: BloombergToolsOptions): BloombergTool;
|
|
48
|
+
declare function createBsrchTool(options?: BloombergToolsOptions): BloombergTool;
|
|
49
|
+
declare function createBqrTool(options?: BloombergToolsOptions): BloombergTool;
|
|
50
|
+
declare function createBfldsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
51
|
+
declare function createBeqsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
52
|
+
declare function createYasTool(options?: BloombergToolsOptions): BloombergTool;
|
|
53
|
+
declare function createPreferredsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
54
|
+
declare function createCorporateBondsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
55
|
+
declare function createIndexMembersTool(options?: BloombergToolsOptions): BloombergTool;
|
|
56
|
+
declare function createResolveIsinsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
57
|
+
declare function createIssuerIsinsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
58
|
+
declare function createEtfHoldingsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
59
|
+
declare function createStreamSnapshotTool(options?: BloombergToolsOptions): BloombergTool;
|
|
60
|
+
declare function createMktbarSnapshotTool(options?: BloombergToolsOptions): BloombergTool;
|
|
61
|
+
declare function createDepthSnapshotTool(options?: BloombergToolsOptions): BloombergTool;
|
|
62
|
+
declare function createBloombergTools(options?: BloombergToolsOptions): BloombergTool[];
|
|
63
|
+
|
|
64
|
+
declare const BLOOMBERG_TOOL_INSTRUCTIONS: string;
|
|
65
|
+
interface BloombergToolInstructionsOptions {
|
|
66
|
+
readonly includeExtensionGuidance?: boolean;
|
|
67
|
+
readonly includeLimitReminder?: boolean;
|
|
68
|
+
}
|
|
69
|
+
declare function getBloombergToolInstructions(options?: BloombergToolInstructionsOptions): string;
|
|
70
|
+
|
|
71
|
+
declare const BLOOMBERG_EXT_TOOL_NAMES: readonly ("xbbg_bdp" | "xbbg_bdh" | "xbbg_bds" | "xbbg_bdib" | "xbbg_bdtick" | "xbbg_bql" | "xbbg_bsrch" | "xbbg_bqr" | "xbbg_bflds" | "xbbg_beqs" | "xbbg_yas" | "xbbg_preferreds" | "xbbg_corporate_bonds" | "xbbg_index_members" | "xbbg_resolve_isins" | "xbbg_issuer_isins" | "xbbg_etf_holdings" | "xbbg_stream_snapshot" | "xbbg_mktbar_snapshot" | "xbbg_depth_snapshot" | "xbbg_ext_ticker" | "xbbg_ext_futures" | "xbbg_ext_cdx" | "xbbg_ext_currency" | "xbbg_ext_bql_builder" | "xbbg_ext_market_session" | "xbbg_ext_yas_overrides" | "xbbg_ext_constants" | "xbbg_ext_columns" | "xbbg_ext_calculate")[];
|
|
72
|
+
declare function createExtTickerTool(options?: BloombergToolsOptions): BloombergTool;
|
|
73
|
+
declare function createExtFuturesTool(options?: BloombergToolsOptions): BloombergTool;
|
|
74
|
+
declare function createExtCdxTool(options?: BloombergToolsOptions): BloombergTool;
|
|
75
|
+
declare function createExtCurrencyTool(options?: BloombergToolsOptions): BloombergTool;
|
|
76
|
+
declare function createExtBqlBuilderTool(options?: BloombergToolsOptions): BloombergTool;
|
|
77
|
+
declare function createExtMarketSessionTool(options?: BloombergToolsOptions): BloombergTool;
|
|
78
|
+
declare function createExtYasOverridesTool(options?: BloombergToolsOptions): BloombergTool;
|
|
79
|
+
declare function createExtConstantsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
80
|
+
declare function createExtColumnsTool(options?: BloombergToolsOptions): BloombergTool;
|
|
81
|
+
declare function createExtCalculateTool(options?: BloombergToolsOptions): BloombergTool;
|
|
82
|
+
declare function createBloombergExtTools(options?: BloombergToolsOptions): BloombergTool[];
|
|
83
|
+
|
|
84
|
+
interface ToolEnvelope {
|
|
85
|
+
readonly tool: BloombergToolName;
|
|
86
|
+
readonly rowCount: number | null;
|
|
87
|
+
readonly truncated: boolean;
|
|
88
|
+
readonly data: unknown;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare function createAllBloombergTools(options?: BloombergToolsOptions): BloombergTool[];
|
|
92
|
+
|
|
93
|
+
export { BLOOMBERG_EXT_TOOL_NAMES, BLOOMBERG_TOOL_INSTRUCTIONS, BLOOMBERG_TOOL_NAMES, type BloombergTool, type BloombergToolInstructionsOptions, type BloombergToolName, type BloombergToolsOptions, type NormalizedBloombergToolsOptions, type ToolEnvelope, createAllBloombergTools, createBdhTool, createBdibTool, createBdpTool, createBdsTool, createBdtickTool, createBeqsTool, createBfldsTool, createBloombergExtTools, createBloombergTools, createBqlTool, createBqrTool, createBsrchTool, createCorporateBondsTool, createDepthSnapshotTool, createEtfHoldingsTool, createExtBqlBuilderTool, createExtCalculateTool, createExtCdxTool, createExtColumnsTool, createExtConstantsTool, createExtCurrencyTool, createExtFuturesTool, createExtMarketSessionTool, createExtTickerTool, createExtYasOverridesTool, createIndexMembersTool, createIssuerIsinsTool, createMktbarSnapshotTool, createPreferredsTool, createResolveIsinsTool, createStreamSnapshotTool, createYasTool, getBloombergToolInstructions };
|