@mongodb-js/agent-engine-sdk-langgraph 0.11.3
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/CHANGELOG.md +39 -0
- package/LICENSE.md +201 -0
- package/README.md +149 -0
- package/dist/agent.d.ts +53 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +508 -0
- package/dist/agent.js.map +1 -0
- package/dist/backends/tool_sandbox.d.ts +15 -0
- package/dist/backends/tool_sandbox.d.ts.map +1 -0
- package/dist/backends/tool_sandbox.js +15 -0
- package/dist/backends/tool_sandbox.js.map +1 -0
- package/dist/backends/toolpod.d.ts +68 -0
- package/dist/backends/toolpod.d.ts.map +1 -0
- package/dist/backends/toolpod.js +451 -0
- package/dist/backends/toolpod.js.map +1 -0
- package/dist/call_interrupt.d.ts +20 -0
- package/dist/call_interrupt.d.ts.map +1 -0
- package/dist/call_interrupt.js +23 -0
- package/dist/call_interrupt.js.map +1 -0
- package/dist/checkpoint_branch.d.ts +58 -0
- package/dist/checkpoint_branch.d.ts.map +1 -0
- package/dist/checkpoint_branch.js +239 -0
- package/dist/checkpoint_branch.js.map +1 -0
- package/dist/checkpointer.d.ts +21 -0
- package/dist/checkpointer.d.ts.map +1 -0
- package/dist/checkpointer.js +31 -0
- package/dist/checkpointer.js.map +1 -0
- package/dist/deep_agent.d.ts +49 -0
- package/dist/deep_agent.d.ts.map +1 -0
- package/dist/deep_agent.js +110 -0
- package/dist/deep_agent.js.map +1 -0
- package/dist/deep_agent_checkpointer.d.ts +11 -0
- package/dist/deep_agent_checkpointer.d.ts.map +1 -0
- package/dist/deep_agent_checkpointer.js +19 -0
- package/dist/deep_agent_checkpointer.js.map +1 -0
- package/dist/deep_agent_task.d.ts +26 -0
- package/dist/deep_agent_task.d.ts.map +1 -0
- package/dist/deep_agent_task.js +49 -0
- package/dist/deep_agent_task.js.map +1 -0
- package/dist/durable_deep_agent.d.ts +23 -0
- package/dist/durable_deep_agent.d.ts.map +1 -0
- package/dist/durable_deep_agent.js +176 -0
- package/dist/durable_deep_agent.js.map +1 -0
- package/dist/durable_message_identity.d.ts +5 -0
- package/dist/durable_message_identity.d.ts.map +1 -0
- package/dist/durable_message_identity.js +106 -0
- package/dist/durable_message_identity.js.map +1 -0
- package/dist/durable_session.d.ts +30 -0
- package/dist/durable_session.d.ts.map +1 -0
- package/dist/durable_session.js +400 -0
- package/dist/durable_session.js.map +1 -0
- package/dist/durable_subgraphs.d.ts +13 -0
- package/dist/durable_subgraphs.d.ts.map +1 -0
- package/dist/durable_subgraphs.js +82 -0
- package/dist/durable_subgraphs.js.map +1 -0
- package/dist/durable_tools.d.ts +12 -0
- package/dist/durable_tools.d.ts.map +1 -0
- package/dist/durable_tools.js +41 -0
- package/dist/durable_tools.js.map +1 -0
- package/dist/execution_session.d.ts +63 -0
- package/dist/execution_session.d.ts.map +1 -0
- package/dist/execution_session.js +300 -0
- package/dist/execution_session.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/llm_adapter.d.ts +41 -0
- package/dist/llm_adapter.d.ts.map +1 -0
- package/dist/llm_adapter.js +177 -0
- package/dist/llm_adapter.js.map +1 -0
- package/dist/messages.d.ts +56 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +592 -0
- package/dist/messages.js.map +1 -0
- package/dist/node_logger_adapter.d.ts +51 -0
- package/dist/node_logger_adapter.d.ts.map +1 -0
- package/dist/node_logger_adapter.js +163 -0
- package/dist/node_logger_adapter.js.map +1 -0
- package/dist/platform_checkpointer.d.ts +70 -0
- package/dist/platform_checkpointer.d.ts.map +1 -0
- package/dist/platform_checkpointer.js +252 -0
- package/dist/platform_checkpointer.js.map +1 -0
- package/dist/query.d.ts +103 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +623 -0
- package/dist/query.js.map +1 -0
- package/dist/runtime.d.ts +336 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +881 -0
- package/dist/runtime.js.map +1 -0
- package/dist/secure_llm.d.ts +93 -0
- package/dist/secure_llm.d.ts.map +1 -0
- package/dist/secure_llm.js +423 -0
- package/dist/secure_llm.js.map +1 -0
- package/dist/session_factory.d.ts +6 -0
- package/dist/session_factory.d.ts.map +1 -0
- package/dist/session_factory.js +29 -0
- package/dist/session_factory.js.map +1 -0
- package/dist/session_fork.d.ts +76 -0
- package/dist/session_fork.d.ts.map +1 -0
- package/dist/session_fork.js +428 -0
- package/dist/session_fork.js.map +1 -0
- package/dist/subagents.d.ts +37 -0
- package/dist/subagents.d.ts.map +1 -0
- package/dist/subagents.js +67 -0
- package/dist/subagents.js.map +1 -0
- package/dist/suspend.d.ts +27 -0
- package/dist/suspend.d.ts.map +1 -0
- package/dist/suspend.js +87 -0
- package/dist/suspend.js.map +1 -0
- package/dist/thread_id.d.ts +30 -0
- package/dist/thread_id.d.ts.map +1 -0
- package/dist/thread_id.js +69 -0
- package/dist/thread_id.js.map +1 -0
- package/dist/workflow_json.d.ts +11 -0
- package/dist/workflow_json.d.ts.map +1 -0
- package/dist/workflow_json.js +49 -0
- package/dist/workflow_json.js.map +1 -0
- package/dist/workflow_message.d.ts +11 -0
- package/dist/workflow_message.d.ts.map +1 -0
- package/dist/workflow_message.js +179 -0
- package/dist/workflow_message.js.map +1 -0
- package/dist/workflow_state.d.ts +7 -0
- package/dist/workflow_state.d.ts.map +1 -0
- package/dist/workflow_state.js +62 -0
- package/dist/workflow_state.js.map +1 -0
- package/package.json +66 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this package will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Durable LLM activities now replay deterministically: LangGraph runtime keys
|
|
12
|
+
injected into the model call options (`executionInfo` — per-attempt
|
|
13
|
+
checkpoint/task UUIDs and `nodeFirstAttemptTime` — plus `durability` and
|
|
14
|
+
`control`) no longer reach the OE activity semantic input. Replaying a
|
|
15
|
+
durable attempt whose suspension turn included LLM calls previously failed
|
|
16
|
+
with `workflow is nondeterministic: activity ... changed` (deep Agent HITL
|
|
17
|
+
recovery was the first scenario to hit this).
|
|
18
|
+
- Session summaries' `message_count` now reports the actual message count, matching the session messages endpoint. It previously reported the checkpoint count, which LangGraph writes once per graph super-step.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- Session-history reads with a workspace scope now query only the scoped
|
|
22
|
+
checkpoint key, so legacy bare-key histories are no longer returned. A
|
|
23
|
+
workspace resolver returning `null` or `undefined` now fails closed;
|
|
24
|
+
explicitly unscoped local runtimes continue to read bare-key checkpoints.
|
|
25
|
+
- Session-history messages for human-authored turns now report role `"user"` instead of `"human"`, matching the live invoke/stream `Message.role` vocabulary.
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
- Deep Agent graphs now run on `durable_workflow` sessions. Deep Agent task
|
|
29
|
+
delegation is adapter-owned rather than a compiled child graph, so `createAgentEngineDeepAgent`
|
|
30
|
+
installs a `DurableDeepAgentMiddleware` that attributes subagent work to a deterministic
|
|
31
|
+
child operation path (name + ToolCall id, preallocated per same-step batch), stamps the
|
|
32
|
+
subagent's input and result messages with replay-stable ids, and rejects compiled
|
|
33
|
+
subagents whose runnable carries its own checkpointer. The graph's checkpointer is
|
|
34
|
+
wrapped to tolerate LangChain's internal Send routing while sharing the platform
|
|
35
|
+
scratch state.
|
|
36
|
+
- Initial package scaffold (Step 1).
|
|
37
|
+
- `src/_stubs.ts` — temporary stand-ins for agent-engine-runner-shared Phase 9 + Phase 12 symbols.
|
|
38
|
+
- `App.resolveThreadId()` — agent-owned LangGraph checkpoint keys. The return value is used verbatim on fresh and resume invocations instead of the default `session_id:workspace_id` derivation.
|
|
39
|
+
- `CHECKPOINT_DB_NAME` — exact `MongoDBSaver` database override with no project scoping, for dual-runtime shared checkpoint stores.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 MongoDB, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# @mongodb-js/agent-engine-sdk-langgraph
|
|
2
|
+
|
|
3
|
+
The LangGraph framework SDK for Atlas Agent Engine in TypeScript. It wraps LangGraph agents with platform security, audit, and observability. A [Python version](../../../python/packages/agent-engine-sdk-langgraph/) is also available.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mongodb-js/agent-engine-sdk-langgraph
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
| File | Purpose |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `src/index.ts` | Public re-exports (`App`, `LangGraphBaseAgent`, etc.) |
|
|
18
|
+
| `src/runtime.ts` | `App` class — the SDK entry point |
|
|
19
|
+
| `src/agent.ts` | `LangGraphBaseAgent` wrapping `CompiledStateGraph` |
|
|
20
|
+
| `src/query.ts` | `LangGraphQueryPlugin` — session summaries/messages from `MongoDBSaver` collections |
|
|
21
|
+
| `src/secure_llm.ts` | `SecureWrappedLLM` — routes LLM calls through proxy |
|
|
22
|
+
| `src/messages.ts` | LangChain ↔ platform message translator |
|
|
23
|
+
| `src/llm_adapter.ts` | Adapter from `BaseChatModel` to platform `BaseLLM` |
|
|
24
|
+
| `src/subagents.ts` | Subagent dispatch + `lc_agent_name` tracking |
|
|
25
|
+
| `src/node_logger_adapter.ts` | LangGraph callbacks → `NodeExecutionLogger` |
|
|
26
|
+
| `src/deep_agent.ts` | `deepagents` library wrapper |
|
|
27
|
+
| `src/deep_agent_task.ts` | Deep Agent `task` tool-call parsing |
|
|
28
|
+
| `src/deep_agent_checkpointer.ts` | Deep Agent checkpointer policy (tolerates adapter-owned Send routing) |
|
|
29
|
+
| `src/durable_deep_agent.ts` | Durable `task` dispatch: child operation paths + message-id stamping |
|
|
30
|
+
| `src/session_fork.ts` | Session fork: native copy + durable OE branch, wrapped into `updateState` |
|
|
31
|
+
| `src/backends/toolpod.ts` | `AgentEngineToolPodBackend` (sandbox backend) |
|
|
32
|
+
|
|
33
|
+
## Dependency direction
|
|
34
|
+
|
|
35
|
+
Each line below is one dependency rank, top to bottom (computed from the
|
|
36
|
+
actual local import graph):
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
index.ts
|
|
40
|
+
runtime.ts
|
|
41
|
+
agent.ts
|
|
42
|
+
session_factory.ts
|
|
43
|
+
durable_session.ts
|
|
44
|
+
deep_agent.ts · execution_session.ts · secure_llm.ts · backends/toolpod.ts
|
|
45
|
+
deep_agent_checkpointer.ts · durable_deep_agent.ts · durable_subgraphs.ts · session_fork.ts
|
|
46
|
+
platform_checkpointer.ts
|
|
47
|
+
workflow_state.ts
|
|
48
|
+
durable_tools.ts · llm_adapter.ts · query.ts · suspend.ts · workflow_message.ts
|
|
49
|
+
messages.ts · checkpoint_branch.ts · checkpointer.ts · deep_agent_task.ts ·
|
|
50
|
+
durable_message_identity.ts · node_logger_adapter.ts ·
|
|
51
|
+
stopped_tool_call_middleware.ts · subagents.ts · thread_id.ts ·
|
|
52
|
+
backends/tool_sandbox.ts · workflow_json.ts
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
A file **may only import from files on lower lines** in this tree. Imports going the other way are bugs.
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
| Environment variable | Default | Description |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `MONGODB_URI` | _(unset)_ | MongoDB connection source for the checkpointer and query plugin in AER mode. |
|
|
62
|
+
| `MDB_AGENTIC_STORE_DB` | `mdb_store` | Base name for the per-project MongoDB store used for LangGraph checkpoints in AER mode. Project scoping and discovery still apply unless overridden below. |
|
|
63
|
+
| `CHECKPOINT_DB_NAME` | _(unset)_ | Exact `MongoDBSaver` database name when set. Skips project scoping and discovery. Set it on the agent AER pod environment or a SecretRef to opt into a checkpoint database shared by dual-runtime agents. |
|
|
64
|
+
|
|
65
|
+
By default, the LangGraph checkpoint `thread_id` is `session_id:workspace_id`.
|
|
66
|
+
Agents can register `app.resolveThreadId((ctx) => ...)`; its return value is
|
|
67
|
+
used verbatim on fresh and resume invocations, with no workspace suffix
|
|
68
|
+
appended. Custom keys are invisible to Atlas Agent Engine `/query/sessions*` history,
|
|
69
|
+
which still looks up only the default session/workspace-derived keys. Agents
|
|
70
|
+
that bypass workspace scoping own collision isolation within the checkpoint
|
|
71
|
+
database. The key must be reconstructible from `RequestContext` (including the
|
|
72
|
+
session and authenticated identity) on every turn.
|
|
73
|
+
|
|
74
|
+
**Reads are scoped-only.** Session history expands each Atlas Agent Engine `session_id`
|
|
75
|
+
to only its workspace-scoped composite key; the bare unscoped key is never
|
|
76
|
+
queried once a workspace scope is known, because bare keys are readable and
|
|
77
|
+
writable by every workspace on the shared store. Legacy checkpoints written
|
|
78
|
+
before scoping existed are therefore not served by the history endpoints. An
|
|
79
|
+
empty scope is legitimate only on explicitly unscoped runtimes (local
|
|
80
|
+
development and tests, with no `APP_ID`). Managed AERs carry
|
|
81
|
+
`REQUIRE_PROJECT_SCOPED_DB`; if `APP_ID` is missing there, reads and writes
|
|
82
|
+
fail closed instead of trusting the wire workspace or using bare keys.
|
|
83
|
+
Production adopters of custom keys should still treat checkpoint-key
|
|
84
|
+
uniqueness inside a shared database as agent-owned.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { App } from "@mongodb-js/agent-engine-sdk-langgraph";
|
|
88
|
+
|
|
89
|
+
const app = new App({ appName: "support-agent" });
|
|
90
|
+
|
|
91
|
+
app.resolveThreadId((ctx) => `${ctx.sessionId}__${ctx.userId}`);
|
|
92
|
+
|
|
93
|
+
app.entrypoint(() => {
|
|
94
|
+
// Build the LangGraph graph here and pass this saver to graph.compile().
|
|
95
|
+
const checkpointer = app.checkpointer();
|
|
96
|
+
return buildGraph().compile({ checkpointer });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// On the agent AER pod, set CHECKPOINT_DB_NAME to the exact shared database.
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Differences from the Python SDK
|
|
103
|
+
|
|
104
|
+
| Feature | Python | TypeScript | Notes |
|
|
105
|
+
| --------------------------- | ------ | ---------- | ----------------------------------------------------------------------------------------- |
|
|
106
|
+
| MCP tool servers | ✅ | ✅ | `agent-engine-runner-shared`'s `mcp_tools.ts`/`mcp_oauth.ts`, discovery wired into `App`. |
|
|
107
|
+
| `langgraph.types.Overwrite` | ✅ | ⚠️ shim | Not in LangGraph.js yet — handled via defensive unwrap. |
|
|
108
|
+
|
|
109
|
+
## Skills
|
|
110
|
+
|
|
111
|
+
Pass parent source directories through `App.deepAgent(..., { skills: [...] })`.
|
|
112
|
+
At runtime,
|
|
113
|
+
deepagents lists each source through the configured backend and discovers only
|
|
114
|
+
its immediate child directories containing `SKILL.md`; discovery is not
|
|
115
|
+
recursive. deepagents skips unreadable or unparsable frontmatter and skills
|
|
116
|
+
missing `name` or `description`; it warns but may still load Agent Skills naming
|
|
117
|
+
or directory-name violations. This SDK forwards declared paths without
|
|
118
|
+
inspecting or filtering them. The skills root is resolved at Tool Pod
|
|
119
|
+
startup, not at SDK import time, so a normal static SDK import works — no
|
|
120
|
+
import-order workaround is needed.
|
|
121
|
+
|
|
122
|
+
## Development
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
# install dependencies
|
|
126
|
+
npm install
|
|
127
|
+
|
|
128
|
+
# type-check only (no emit)
|
|
129
|
+
npm run typecheck
|
|
130
|
+
|
|
131
|
+
# build distributable
|
|
132
|
+
npm run build
|
|
133
|
+
|
|
134
|
+
# unit tests
|
|
135
|
+
npm run test
|
|
136
|
+
|
|
137
|
+
# lint
|
|
138
|
+
npm run lint
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Coding standards
|
|
142
|
+
|
|
143
|
+
- Strict TypeScript (`strict: true` + `noUncheckedIndexedAccess` + `exactOptionalPropertyTypes`).
|
|
144
|
+
- Snake_case filenames.
|
|
145
|
+
- camelCase function/variable names.
|
|
146
|
+
- PascalCase class/type names.
|
|
147
|
+
- Each file = single responsibility (one class or one focused concept).
|
|
148
|
+
- Public surface depends on interfaces (Dependency Inversion).
|
|
149
|
+
- No hardcoded secrets, ever.
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangGraph BaseAgent adapter.
|
|
3
|
+
*
|
|
4
|
+
* Wraps a LangGraph compiled graph to implement the framework-neutral
|
|
5
|
+
* `BaseAgent` protocol from agent-engine-sdk. Execution-session setup lives in
|
|
6
|
+
* `execution_session.ts`; this adapter owns graph invocation and event/result
|
|
7
|
+
* translation.
|
|
8
|
+
*
|
|
9
|
+
* Port of `agent_engine_sdk_langgraph/agent.py`.
|
|
10
|
+
*/
|
|
11
|
+
import type { CompiledStateGraph } from "@langchain/langgraph";
|
|
12
|
+
import { type AgentInput, type AgentOutput, type BaseAgent, type ExecutionResult, type RequestContext, type StreamEvent } from "@mongodb-js/agent-engine-sdk";
|
|
13
|
+
import { type PrepareAgentInput, type ResolveThreadId } from "./execution_session.js";
|
|
14
|
+
/**
|
|
15
|
+
* Tenant hook registered via `App.prepareAgentInput`. Receives the
|
|
16
|
+
* framework-neutral `AgentInput` (the opaque caller payload) and the
|
|
17
|
+
* `RequestContext`, and returns a value LangGraph can ingest directly — a
|
|
18
|
+
* graph-state object or a `Command`. Lets an agent author control how a fresh
|
|
19
|
+
* invocation becomes the graph's starting input. Resume stays platform-managed.
|
|
20
|
+
*
|
|
21
|
+
* Port of Python's `PrepareAgentInput` (agent_engine_sdk_langgraph/agent.py).
|
|
22
|
+
*/
|
|
23
|
+
export type { PrepareAgentInput } from "./execution_session.js";
|
|
24
|
+
/**
|
|
25
|
+
* Tenant hook registered via `App.resolveThreadId`. Maps `RequestContext` to
|
|
26
|
+
* the LangGraph checkpoint `thread_id`. When set, the return value is used
|
|
27
|
+
* verbatim (no workspace suffix). Port of Python's `ResolveThreadId`.
|
|
28
|
+
*/
|
|
29
|
+
export type { ResolveThreadId } from "./execution_session.js";
|
|
30
|
+
/** LangGraph adapter implementing the BaseAgent protocol. */
|
|
31
|
+
export declare class LangGraphBaseAgent implements BaseAgent {
|
|
32
|
+
private readonly graph;
|
|
33
|
+
private readonly callbacks;
|
|
34
|
+
private readonly prepareInput;
|
|
35
|
+
private readonly resolveThreadIdFn;
|
|
36
|
+
private readonly durableSubgraphs;
|
|
37
|
+
constructor(graph: CompiledStateGraph<unknown, unknown>, callbacks?: readonly unknown[], prepareInput?: PrepareAgentInput | null, resolveThreadId?: ResolveThreadId | null);
|
|
38
|
+
/** The wrapped compiled graph (Python `compiled_graph` parity). */
|
|
39
|
+
get compiledGraph(): CompiledStateGraph<unknown, unknown>;
|
|
40
|
+
/** The tenant thread-id hook, or null (Python `_resolve_thread_id` parity). */
|
|
41
|
+
get resolveThreadId(): ResolveThreadId | null;
|
|
42
|
+
execute(ctx: RequestContext, input: AgentInput): ExecutionResult;
|
|
43
|
+
private session;
|
|
44
|
+
invoke(ctx: RequestContext, input: AgentInput): Promise<AgentOutput>;
|
|
45
|
+
private invokeGraph;
|
|
46
|
+
resume(ctx: RequestContext, input: AgentInput, decision: string): Promise<AgentOutput>;
|
|
47
|
+
private processMessagesChunk;
|
|
48
|
+
private processAddMessagesUpdate;
|
|
49
|
+
private processCommandUpdate;
|
|
50
|
+
stream(ctx: RequestContext, input: AgentInput): AsyncIterable<StreamEvent>;
|
|
51
|
+
private streamGraph;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAWhC;;;;;;;;GAQG;AACH,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;GAIG;AACH,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAkN9D,6DAA6D;AAC7D,qBAAa,kBAAmB,YAAW,SAAS;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA2B;IACxD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAyB;IAC3D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAiC;gBAGhE,KAAK,EAAE,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,EAC3C,SAAS,CAAC,EAAE,SAAS,OAAO,EAAE,EAC9B,YAAY,CAAC,EAAE,iBAAiB,GAAG,IAAI,EACvC,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI;IAkB1C,mEAAmE;IACnE,IAAI,aAAa,IAAI,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAExD;IAED,+EAA+E;IAC/E,IAAI,eAAe,IAAI,eAAe,GAAG,IAAI,CAE5C;IAED,OAAO,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,GAAG,eAAe;IAOhE,OAAO,CAAC,OAAO;IAST,MAAM,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;YAS5D,WAAW;IA2CnB,MAAM,CACV,GAAG,EAAE,cAAc,EACnB,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC;YAcR,oBAAoB;YA8BpB,wBAAwB;YA0BxB,oBAAoB;IA8B5B,MAAM,CACX,GAAG,EAAE,cAAc,EACnB,KAAK,EAAE,UAAU,GAChB,aAAa,CAAC,WAAW,CAAC;YASd,WAAW;CAiL3B"}
|