@langchain/langgraph 0.4.8 → 1.0.0-alpha.0
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 +7 -2
- package/README.md +1 -2
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/channels/any_value.d.cts +26 -0
- package/dist/channels/any_value.d.cts.map +1 -0
- package/dist/channels/any_value.d.ts +16 -9
- package/dist/channels/any_value.d.ts.map +1 -0
- package/dist/channels/base.cjs +97 -133
- package/dist/channels/base.cjs.map +1 -0
- package/dist/channels/base.d.cts +73 -0
- package/dist/channels/base.d.cts.map +1 -0
- package/dist/channels/base.d.ts +73 -74
- package/dist/channels/base.d.ts.map +1 -0
- package/dist/channels/base.js +94 -127
- package/dist/channels/base.js.map +1 -1
- package/dist/channels/binop.cjs +47 -77
- package/dist/channels/binop.cjs.map +1 -0
- package/dist/channels/binop.d.cts +22 -0
- package/dist/channels/binop.d.cts.map +1 -0
- package/dist/channels/binop.d.ts +17 -12
- package/dist/channels/binop.d.ts.map +1 -0
- package/dist/channels/binop.js +45 -71
- package/dist/channels/binop.js.map +1 -1
- package/dist/channels/dynamic_barrier_value.d.cts +43 -0
- package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
- package/dist/channels/dynamic_barrier_value.d.ts +20 -34
- package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
- package/dist/channels/ephemeral_value.cjs +46 -70
- package/dist/channels/ephemeral_value.cjs.map +1 -0
- package/dist/channels/ephemeral_value.d.cts +23 -0
- package/dist/channels/ephemeral_value.d.cts.map +1 -0
- package/dist/channels/ephemeral_value.d.ts +18 -11
- package/dist/channels/ephemeral_value.d.ts.map +1 -0
- package/dist/channels/ephemeral_value.js +45 -65
- package/dist/channels/ephemeral_value.js.map +1 -1
- package/dist/channels/index.cjs +2 -10
- package/dist/channels/index.js +4 -3
- package/dist/channels/last_value.cjs +91 -140
- package/dist/channels/last_value.cjs.map +1 -0
- package/dist/channels/last_value.d.cts +30 -0
- package/dist/channels/last_value.d.cts.map +1 -0
- package/dist/channels/last_value.d.ts +15 -23
- package/dist/channels/last_value.d.ts.map +1 -0
- package/dist/channels/last_value.js +88 -133
- package/dist/channels/last_value.js.map +1 -1
- package/dist/channels/named_barrier_value.cjs +114 -170
- package/dist/channels/named_barrier_value.cjs.map +1 -0
- package/dist/channels/named_barrier_value.d.cts +33 -0
- package/dist/channels/named_barrier_value.d.cts.map +1 -0
- package/dist/channels/named_barrier_value.d.ts +19 -29
- package/dist/channels/named_barrier_value.d.ts.map +1 -0
- package/dist/channels/named_barrier_value.js +112 -163
- package/dist/channels/named_barrier_value.js.map +1 -1
- package/dist/channels/topic.cjs +63 -96
- package/dist/channels/topic.cjs.map +1 -0
- package/dist/channels/topic.d.cts +26 -0
- package/dist/channels/topic.d.cts.map +1 -0
- package/dist/channels/topic.d.ts +21 -18
- package/dist/channels/topic.d.ts.map +1 -0
- package/dist/channels/topic.js +61 -90
- package/dist/channels/topic.js.map +1 -1
- package/dist/constants.cjs +373 -452
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +284 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.ts +112 -148
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +333 -444
- package/dist/constants.js.map +1 -1
- package/dist/errors.cjs +150 -179
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +80 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.ts +55 -46
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +139 -165
- package/dist/errors.js.map +1 -1
- package/dist/func/index.cjs +289 -290
- package/dist/func/index.cjs.map +1 -0
- package/dist/func/index.d.cts +289 -0
- package/dist/func/index.d.cts.map +1 -0
- package/dist/func/index.d.ts +81 -71
- package/dist/func/index.d.ts.map +1 -0
- package/dist/func/index.js +285 -284
- package/dist/func/index.js.map +1 -1
- package/dist/func/types.d.cts +64 -0
- package/dist/func/types.d.cts.map +1 -0
- package/dist/func/types.d.ts +24 -19
- package/dist/func/types.d.ts.map +1 -0
- package/dist/graph/annotation.cjs +96 -120
- package/dist/graph/annotation.cjs.map +1 -0
- package/dist/graph/annotation.d.cts +116 -0
- package/dist/graph/annotation.d.cts.map +1 -0
- package/dist/graph/annotation.d.ts +33 -34
- package/dist/graph/annotation.d.ts.map +1 -0
- package/dist/graph/annotation.js +91 -112
- package/dist/graph/annotation.js.map +1 -1
- package/dist/graph/graph.cjs +419 -723
- package/dist/graph/graph.cjs.map +1 -0
- package/dist/graph/graph.d.cts +131 -0
- package/dist/graph/graph.d.cts.map +1 -0
- package/dist/graph/graph.d.ts +122 -91
- package/dist/graph/graph.d.ts.map +1 -0
- package/dist/graph/graph.js +412 -713
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.cjs +4 -17
- package/dist/graph/index.js +6 -5
- package/dist/graph/message.cjs +59 -104
- package/dist/graph/message.cjs.map +1 -0
- package/dist/graph/message.d.cts +19 -0
- package/dist/graph/message.d.cts.map +1 -0
- package/dist/graph/message.d.ts +11 -10
- package/dist/graph/message.d.ts.map +1 -0
- package/dist/graph/message.js +56 -98
- package/dist/graph/message.js.map +1 -1
- package/dist/graph/messages_annotation.cjs +106 -106
- package/dist/graph/messages_annotation.cjs.map +1 -0
- package/dist/graph/messages_annotation.d.cts +111 -0
- package/dist/graph/messages_annotation.d.cts.map +1 -0
- package/dist/graph/messages_annotation.d.ts +18 -9
- package/dist/graph/messages_annotation.d.ts.map +1 -0
- package/dist/graph/messages_annotation.js +100 -100
- package/dist/graph/messages_annotation.js.map +1 -1
- package/dist/graph/state.cjs +476 -777
- package/dist/graph/state.cjs.map +1 -0
- package/dist/graph/state.d.cts +216 -0
- package/dist/graph/state.d.cts.map +1 -0
- package/dist/graph/state.d.ts +129 -134
- package/dist/graph/state.d.ts.map +1 -0
- package/dist/graph/state.js +470 -768
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/zod/index.cjs +10 -21
- package/dist/graph/zod/index.d.cts +3 -0
- package/dist/graph/zod/index.d.ts +3 -3
- package/dist/graph/zod/index.js +4 -4
- package/dist/graph/zod/meta.cjs +142 -177
- package/dist/graph/zod/meta.cjs.map +1 -0
- package/dist/graph/zod/meta.d.cts +116 -0
- package/dist/graph/zod/meta.d.cts.map +1 -0
- package/dist/graph/zod/meta.d.ts +99 -97
- package/dist/graph/zod/meta.d.ts.map +1 -0
- package/dist/graph/zod/meta.js +136 -170
- package/dist/graph/zod/meta.js.map +1 -1
- package/dist/graph/zod/plugin.cjs +36 -39
- package/dist/graph/zod/plugin.cjs.map +1 -0
- package/dist/graph/zod/plugin.js +34 -35
- package/dist/graph/zod/plugin.js.map +1 -1
- package/dist/graph/zod/schema.cjs +82 -110
- package/dist/graph/zod/schema.cjs.map +1 -0
- package/dist/graph/zod/schema.d.cts +38 -0
- package/dist/graph/zod/schema.d.cts.map +1 -0
- package/dist/graph/zod/schema.d.ts +12 -6
- package/dist/graph/zod/schema.d.ts.map +1 -0
- package/dist/graph/zod/schema.js +77 -103
- package/dist/graph/zod/schema.js.map +1 -1
- package/dist/graph/zod/zod-registry.cjs +41 -47
- package/dist/graph/zod/zod-registry.cjs.map +1 -0
- package/dist/graph/zod/zod-registry.d.cts +51 -0
- package/dist/graph/zod/zod-registry.d.cts.map +1 -0
- package/dist/graph/zod/zod-registry.d.ts +34 -26
- package/dist/graph/zod/zod-registry.d.ts.map +1 -0
- package/dist/graph/zod/zod-registry.js +37 -41
- package/dist/graph/zod/zod-registry.js.map +1 -1
- package/dist/hash.cjs +205 -267
- package/dist/hash.cjs.map +1 -0
- package/dist/hash.js +205 -265
- package/dist/hash.js.map +1 -1
- package/dist/index.cjs +110 -33
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -5
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/interrupt.cjs +79 -85
- package/dist/interrupt.cjs.map +1 -0
- package/dist/interrupt.d.cts +49 -0
- package/dist/interrupt.d.cts.map +1 -0
- package/dist/interrupt.d.ts +6 -1
- package/dist/interrupt.d.ts.map +1 -0
- package/dist/interrupt.js +76 -80
- package/dist/interrupt.js.map +1 -1
- package/dist/prebuilt/agentName.cjs +139 -172
- package/dist/prebuilt/agentName.cjs.map +1 -0
- package/dist/prebuilt/agentName.d.cts +42 -0
- package/dist/prebuilt/agentName.d.cts.map +1 -0
- package/dist/prebuilt/agentName.d.ts +13 -21
- package/dist/prebuilt/agentName.d.ts.map +1 -0
- package/dist/prebuilt/agentName.js +139 -168
- package/dist/prebuilt/agentName.js.map +1 -1
- package/dist/prebuilt/agent_executor.cjs +42 -80
- package/dist/prebuilt/agent_executor.cjs.map +1 -0
- package/dist/prebuilt/agent_executor.d.cts +57 -0
- package/dist/prebuilt/agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/agent_executor.d.ts +46 -37
- package/dist/prebuilt/agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/agent_executor.js +40 -75
- package/dist/prebuilt/agent_executor.js.map +1 -1
- package/dist/prebuilt/chat_agent_executor.cjs +66 -128
- package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
- package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
- package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/chat_agent_executor.d.ts +18 -10
- package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/chat_agent_executor.js +63 -123
- package/dist/prebuilt/chat_agent_executor.js.map +1 -1
- package/dist/prebuilt/index.cjs +15 -18
- package/dist/prebuilt/index.d.cts +8 -0
- package/dist/prebuilt/index.d.ts +8 -8
- package/dist/prebuilt/index.js +8 -7
- package/dist/prebuilt/interrupt.d.cts +73 -0
- package/dist/prebuilt/interrupt.d.cts.map +1 -0
- package/dist/prebuilt/interrupt.d.ts +32 -15
- package/dist/prebuilt/interrupt.d.ts.map +1 -0
- package/dist/prebuilt/react_agent_executor.cjs +317 -473
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.cts +229 -0
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.ts +171 -143
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/react_agent_executor.js +315 -465
- package/dist/prebuilt/react_agent_executor.js.map +1 -1
- package/dist/prebuilt/tool_executor.cjs +45 -67
- package/dist/prebuilt/tool_executor.cjs.map +1 -0
- package/dist/prebuilt/tool_executor.d.cts +42 -0
- package/dist/prebuilt/tool_executor.d.cts.map +1 -0
- package/dist/prebuilt/tool_executor.d.ts +30 -24
- package/dist/prebuilt/tool_executor.d.ts.map +1 -0
- package/dist/prebuilt/tool_executor.js +44 -63
- package/dist/prebuilt/tool_executor.js.map +1 -1
- package/dist/prebuilt/tool_node.cjs +213 -275
- package/dist/prebuilt/tool_node.cjs.map +1 -0
- package/dist/prebuilt/tool_node.d.cts +151 -0
- package/dist/prebuilt/tool_node.d.cts.map +1 -0
- package/dist/prebuilt/tool_node.d.ts +30 -17
- package/dist/prebuilt/tool_node.d.ts.map +1 -0
- package/dist/prebuilt/tool_node.js +209 -268
- package/dist/prebuilt/tool_node.js.map +1 -1
- package/dist/pregel/algo.cjs +521 -692
- package/dist/pregel/algo.cjs.map +1 -0
- package/dist/pregel/algo.d.cts +13 -0
- package/dist/pregel/algo.d.cts.map +1 -0
- package/dist/pregel/algo.d.ts +8 -38
- package/dist/pregel/algo.d.ts.map +1 -0
- package/dist/pregel/algo.js +516 -683
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/call.cjs +46 -42
- package/dist/pregel/call.cjs.map +1 -0
- package/dist/pregel/call.js +43 -37
- package/dist/pregel/call.js.map +1 -1
- package/dist/pregel/debug.cjs +153 -223
- package/dist/pregel/debug.cjs.map +1 -0
- package/dist/pregel/debug.js +152 -215
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +1134 -1604
- package/dist/pregel/index.cjs.map +1 -0
- package/dist/pregel/index.d.cts +534 -0
- package/dist/pregel/index.d.cts.map +1 -0
- package/dist/pregel/index.d.ts +458 -422
- package/dist/pregel/index.d.ts.map +1 -0
- package/dist/pregel/index.js +1125 -1592
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/io.cjs +127 -234
- package/dist/pregel/io.cjs.map +1 -0
- package/dist/pregel/io.js +122 -225
- package/dist/pregel/io.js.map +1 -1
- package/dist/pregel/loop.cjs +539 -954
- package/dist/pregel/loop.cjs.map +1 -0
- package/dist/pregel/loop.js +536 -948
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages.cjs +104 -196
- package/dist/pregel/messages.cjs.map +1 -0
- package/dist/pregel/messages.js +102 -191
- package/dist/pregel/messages.js.map +1 -1
- package/dist/pregel/read.cjs +150 -280
- package/dist/pregel/read.cjs.map +1 -0
- package/dist/pregel/read.d.cts +51 -0
- package/dist/pregel/read.d.cts.map +1 -0
- package/dist/pregel/read.d.ts +48 -46
- package/dist/pregel/read.d.ts.map +1 -0
- package/dist/pregel/read.js +147 -274
- package/dist/pregel/read.js.map +1 -1
- package/dist/pregel/remote.cjs +339 -458
- package/dist/pregel/remote.cjs.map +1 -0
- package/dist/pregel/remote.d.cts +121 -0
- package/dist/pregel/remote.d.cts.map +1 -0
- package/dist/pregel/remote.d.ts +79 -69
- package/dist/pregel/remote.d.ts.map +1 -0
- package/dist/pregel/remote.js +337 -453
- package/dist/pregel/remote.js.map +1 -1
- package/dist/pregel/retry.cjs +87 -138
- package/dist/pregel/retry.cjs.map +1 -0
- package/dist/pregel/retry.js +83 -130
- package/dist/pregel/retry.js.map +1 -1
- package/dist/pregel/runnable_types.d.cts +25 -0
- package/dist/pregel/runnable_types.d.cts.map +1 -0
- package/dist/pregel/runnable_types.d.ts +22 -16
- package/dist/pregel/runnable_types.d.ts.map +1 -0
- package/dist/pregel/runner.cjs +222 -315
- package/dist/pregel/runner.cjs.map +1 -0
- package/dist/pregel/runner.js +219 -308
- package/dist/pregel/runner.js.map +1 -1
- package/dist/pregel/stream.cjs +89 -130
- package/dist/pregel/stream.cjs.map +1 -0
- package/dist/pregel/stream.js +87 -125
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/types.cjs +25 -62
- package/dist/pregel/types.cjs.map +1 -0
- package/dist/pregel/types.d.cts +437 -0
- package/dist/pregel/types.d.cts.map +1 -0
- package/dist/pregel/types.d.ts +377 -431
- package/dist/pregel/types.d.ts.map +1 -0
- package/dist/pregel/types.js +23 -57
- package/dist/pregel/types.js.map +1 -1
- package/dist/pregel/utils/config.cjs +100 -147
- package/dist/pregel/utils/config.cjs.map +1 -0
- package/dist/pregel/utils/config.d.cts +36 -0
- package/dist/pregel/utils/config.d.cts.map +1 -0
- package/dist/pregel/utils/config.d.ts +12 -9
- package/dist/pregel/utils/config.d.ts.map +1 -0
- package/dist/pregel/utils/config.js +98 -143
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.cjs +87 -125
- package/dist/pregel/utils/index.cjs.map +1 -0
- package/dist/pregel/utils/index.d.cts +51 -0
- package/dist/pregel/utils/index.d.cts.map +1 -0
- package/dist/pregel/utils/index.d.ts +45 -61
- package/dist/pregel/utils/index.d.ts.map +1 -0
- package/dist/pregel/utils/index.js +86 -120
- package/dist/pregel/utils/index.js.map +1 -1
- package/dist/pregel/utils/subgraph.cjs +15 -26
- package/dist/pregel/utils/subgraph.cjs.map +1 -0
- package/dist/pregel/utils/subgraph.js +12 -21
- package/dist/pregel/utils/subgraph.js.map +1 -1
- package/dist/pregel/validate.cjs +42 -92
- package/dist/pregel/validate.cjs.map +1 -0
- package/dist/pregel/validate.js +39 -84
- package/dist/pregel/validate.js.map +1 -1
- package/dist/pregel/write.cjs +87 -137
- package/dist/pregel/write.cjs.map +1 -0
- package/dist/pregel/write.d.cts +35 -0
- package/dist/pregel/write.d.cts.map +1 -0
- package/dist/pregel/write.d.ts +27 -23
- package/dist/pregel/write.d.ts.map +1 -0
- package/dist/pregel/write.js +83 -131
- package/dist/pregel/write.js.map +1 -1
- package/dist/remote.cjs +3 -6
- package/dist/remote.d.cts +2 -0
- package/dist/remote.d.ts +2 -1
- package/dist/remote.js +3 -2
- package/dist/setup/async_local_storage.cjs +10 -7
- package/dist/setup/async_local_storage.cjs.map +1 -0
- package/dist/setup/async_local_storage.js +7 -2
- package/dist/setup/async_local_storage.js.map +1 -1
- package/dist/ui/index.cjs +4 -0
- package/dist/ui/index.d.cts +5 -0
- package/dist/ui/index.d.ts +5 -0
- package/dist/ui/index.js +3 -0
- package/dist/ui/stream.cjs +145 -0
- package/dist/ui/stream.cjs.map +1 -0
- package/dist/ui/stream.d.cts +25 -0
- package/dist/ui/stream.d.cts.map +1 -0
- package/dist/ui/stream.d.ts +25 -0
- package/dist/ui/stream.d.ts.map +1 -0
- package/dist/ui/stream.js +143 -0
- package/dist/ui/stream.js.map +1 -0
- package/dist/ui/types.infer.d.cts +53 -0
- package/dist/ui/types.infer.d.cts.map +1 -0
- package/dist/ui/types.infer.d.ts +53 -0
- package/dist/ui/types.infer.d.ts.map +1 -0
- package/dist/ui/types.message.d.cts +95 -0
- package/dist/ui/types.message.d.cts.map +1 -0
- package/dist/ui/types.message.d.ts +95 -0
- package/dist/ui/types.message.d.ts.map +1 -0
- package/dist/ui/types.schema.d.cts +228 -0
- package/dist/ui/types.schema.d.cts.map +1 -0
- package/dist/ui/types.schema.d.ts +228 -0
- package/dist/ui/types.schema.d.ts.map +1 -0
- package/dist/utils.cjs +77 -147
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +32 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.ts +29 -25
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +73 -140
- package/dist/utils.js.map +1 -1
- package/dist/web.cjs +97 -55
- package/dist/web.d.cts +23 -0
- package/dist/web.d.ts +23 -14
- package/dist/web.js +15 -8
- package/package.json +83 -86
- package/dist/channels/any_value.cjs +0 -65
- package/dist/channels/any_value.js +0 -61
- package/dist/channels/any_value.js.map +0 -1
- package/dist/channels/dynamic_barrier_value.cjs +0 -212
- package/dist/channels/dynamic_barrier_value.js +0 -207
- package/dist/channels/dynamic_barrier_value.js.map +0 -1
- package/dist/channels/index.d.ts +0 -7
- package/dist/channels/index.js.map +0 -1
- package/dist/func/types.cjs +0 -15
- package/dist/func/types.js +0 -12
- package/dist/func/types.js.map +0 -1
- package/dist/graph/index.d.ts +0 -4
- package/dist/graph/index.js.map +0 -1
- package/dist/graph/message.test.cjs +0 -196
- package/dist/graph/message.test.d.ts +0 -1
- package/dist/graph/message.test.js +0 -194
- package/dist/graph/message.test.js.map +0 -1
- package/dist/graph/zod/index.js.map +0 -1
- package/dist/graph/zod/plugin.d.ts +0 -28
- package/dist/hash.d.ts +0 -2
- package/dist/prebuilt/index.js.map +0 -1
- package/dist/prebuilt/interrupt.cjs +0 -3
- package/dist/prebuilt/interrupt.js +0 -2
- package/dist/prebuilt/interrupt.js.map +0 -1
- package/dist/pregel/call.d.ts +0 -16
- package/dist/pregel/debug.d.ts +0 -41
- package/dist/pregel/debug.test.cjs +0 -258
- package/dist/pregel/debug.test.d.ts +0 -1
- package/dist/pregel/debug.test.js +0 -256
- package/dist/pregel/debug.test.js.map +0 -1
- package/dist/pregel/io.d.ts +0 -30
- package/dist/pregel/io.mapCommand.test.cjs +0 -150
- package/dist/pregel/io.mapCommand.test.d.ts +0 -1
- package/dist/pregel/io.mapCommand.test.js +0 -148
- package/dist/pregel/io.mapCommand.test.js.map +0 -1
- package/dist/pregel/loop.d.ts +0 -147
- package/dist/pregel/messages.d.ts +0 -30
- package/dist/pregel/messages.test.cjs +0 -369
- package/dist/pregel/messages.test.d.ts +0 -1
- package/dist/pregel/messages.test.js +0 -367
- package/dist/pregel/messages.test.js.map +0 -1
- package/dist/pregel/read.test.cjs +0 -194
- package/dist/pregel/read.test.d.ts +0 -1
- package/dist/pregel/read.test.js +0 -192
- package/dist/pregel/read.test.js.map +0 -1
- package/dist/pregel/retry.d.ts +0 -17
- package/dist/pregel/runnable_types.cjs +0 -3
- package/dist/pregel/runnable_types.js +0 -2
- package/dist/pregel/runnable_types.js.map +0 -1
- package/dist/pregel/runner.d.ts +0 -79
- package/dist/pregel/runner.test.cjs +0 -66
- package/dist/pregel/runner.test.d.ts +0 -1
- package/dist/pregel/runner.test.js +0 -64
- package/dist/pregel/runner.test.js.map +0 -1
- package/dist/pregel/stream.d.ts +0 -40
- package/dist/pregel/utils/config.test.cjs +0 -214
- package/dist/pregel/utils/config.test.d.ts +0 -1
- package/dist/pregel/utils/config.test.js +0 -212
- package/dist/pregel/utils/config.test.js.map +0 -1
- package/dist/pregel/utils/subgraph.d.ts +0 -4
- package/dist/pregel/utils/subgraph.test.cjs +0 -83
- package/dist/pregel/utils/subgraph.test.d.ts +0 -1
- package/dist/pregel/utils/subgraph.test.js +0 -81
- package/dist/pregel/utils/subgraph.test.js.map +0 -1
- package/dist/pregel/validate.d.ts +0 -16
- package/dist/pregel/validate.test.cjs +0 -220
- package/dist/pregel/validate.test.d.ts +0 -1
- package/dist/pregel/validate.test.js +0 -218
- package/dist/pregel/validate.test.js.map +0 -1
- package/dist/pregel/write.test.cjs +0 -181
- package/dist/pregel/write.test.d.ts +0 -1
- package/dist/pregel/write.test.js +0 -179
- package/dist/pregel/write.test.js.map +0 -1
- package/dist/remote.js.map +0 -1
- package/dist/setup/async_local_storage.d.ts +0 -1
- package/dist/web.js.map +0 -1
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/prebuilt.cjs +0 -1
- package/prebuilt.d.cts +0 -1
- package/prebuilt.d.ts +0 -1
- package/prebuilt.js +0 -1
- package/pregel.cjs +0 -1
- package/pregel.d.cts +0 -1
- package/pregel.d.ts +0 -1
- package/pregel.js +0 -1
- package/remote.cjs +0 -1
- package/remote.d.cts +0 -1
- package/remote.d.ts +0 -1
- package/remote.js +0 -1
- package/web.cjs +0 -1
- package/web.d.cts +0 -1
- package/web.d.ts +0 -1
- package/web.js +0 -1
- package/zod/schema.cjs +0 -1
- package/zod/schema.d.cts +0 -1
- package/zod/schema.d.ts +0 -1
- package/zod/schema.js +0 -1
- package/zod.cjs +0 -1
- package/zod.d.cts +0 -1
- package/zod.d.ts +0 -1
- package/zod.js +0 -1
|
@@ -1,500 +1,344 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const message_js_1 = require("../graph/message.cjs");
|
|
14
|
-
const constants_js_1 = require("../constants.cjs");
|
|
15
|
-
const agentName_js_1 = require("./agentName.cjs");
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_annotation = require('../graph/annotation.cjs');
|
|
3
|
+
const require_constants = require('../constants.cjs');
|
|
4
|
+
const require_state = require('../graph/state.cjs');
|
|
5
|
+
const require_message = require('../graph/message.cjs');
|
|
6
|
+
require('../graph/index.cjs');
|
|
7
|
+
const require_tool_node = require('./tool_node.cjs');
|
|
8
|
+
const require_agentName = require('./agentName.cjs');
|
|
9
|
+
const __langchain_core_runnables = require_rolldown_runtime.__toESM(require("@langchain/core/runnables"));
|
|
10
|
+
const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
|
|
11
|
+
|
|
12
|
+
//#region src/prebuilt/react_agent_executor.ts
|
|
16
13
|
function _convertMessageModifierToPrompt(messageModifier) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
// Handle callable function
|
|
23
|
-
if (typeof messageModifier === "function") {
|
|
24
|
-
return async (state) => messageModifier(state.messages);
|
|
25
|
-
}
|
|
26
|
-
// Handle Runnable
|
|
27
|
-
if (runnables_1.Runnable.isRunnable(messageModifier)) {
|
|
28
|
-
return runnables_1.RunnableLambda.from((state) => state.messages).pipe(messageModifier);
|
|
29
|
-
}
|
|
30
|
-
throw new Error(`Unexpected type for messageModifier: ${typeof messageModifier}`);
|
|
14
|
+
if (typeof messageModifier === "string" || (0, __langchain_core_messages.isBaseMessage)(messageModifier) && messageModifier._getType() === "system") return messageModifier;
|
|
15
|
+
if (typeof messageModifier === "function") return async (state) => messageModifier(state.messages);
|
|
16
|
+
if (__langchain_core_runnables.Runnable.isRunnable(messageModifier)) return __langchain_core_runnables.RunnableLambda.from((state) => state.messages).pipe(messageModifier);
|
|
17
|
+
throw new Error(`Unexpected type for messageModifier: ${typeof messageModifier}`);
|
|
31
18
|
}
|
|
32
19
|
const PROMPT_RUNNABLE_NAME = "prompt";
|
|
33
20
|
function _getPromptRunnable(prompt) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
else if (typeof prompt === "function") {
|
|
48
|
-
promptRunnable = runnables_1.RunnableLambda.from(prompt).withConfig({
|
|
49
|
-
runName: PROMPT_RUNNABLE_NAME,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
else if (runnables_1.Runnable.isRunnable(prompt)) {
|
|
53
|
-
promptRunnable = prompt;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);
|
|
57
|
-
}
|
|
58
|
-
return promptRunnable;
|
|
21
|
+
let promptRunnable;
|
|
22
|
+
if (prompt == null) promptRunnable = __langchain_core_runnables.RunnableLambda.from((state) => state.messages).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
23
|
+
else if (typeof prompt === "string") {
|
|
24
|
+
const systemMessage = new __langchain_core_messages.SystemMessage(prompt);
|
|
25
|
+
promptRunnable = __langchain_core_runnables.RunnableLambda.from((state) => {
|
|
26
|
+
return [systemMessage, ...state.messages ?? []];
|
|
27
|
+
}).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
28
|
+
} else if ((0, __langchain_core_messages.isBaseMessage)(prompt) && prompt._getType() === "system") promptRunnable = __langchain_core_runnables.RunnableLambda.from((state) => [prompt, ...state.messages]).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
29
|
+
else if (typeof prompt === "function") promptRunnable = __langchain_core_runnables.RunnableLambda.from(prompt).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
30
|
+
else if (__langchain_core_runnables.Runnable.isRunnable(prompt)) promptRunnable = prompt;
|
|
31
|
+
else throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);
|
|
32
|
+
return promptRunnable;
|
|
59
33
|
}
|
|
60
34
|
function isClientTool(tool) {
|
|
61
|
-
|
|
35
|
+
return __langchain_core_runnables.Runnable.isRunnable(tool);
|
|
62
36
|
}
|
|
63
37
|
function _getPrompt(prompt, stateModifier, messageModifier) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
finalPrompt = _convertMessageModifierToPrompt(messageModifier);
|
|
75
|
-
}
|
|
76
|
-
return _getPromptRunnable(finalPrompt);
|
|
38
|
+
const definedCount = [
|
|
39
|
+
prompt,
|
|
40
|
+
stateModifier,
|
|
41
|
+
messageModifier
|
|
42
|
+
].filter((x) => x != null).length;
|
|
43
|
+
if (definedCount > 1) throw new Error("Expected only one of prompt, stateModifier, or messageModifier, got multiple values");
|
|
44
|
+
let finalPrompt = prompt;
|
|
45
|
+
if (stateModifier != null) finalPrompt = stateModifier;
|
|
46
|
+
else if (messageModifier != null) finalPrompt = _convertMessageModifierToPrompt(messageModifier);
|
|
47
|
+
return _getPromptRunnable(finalPrompt);
|
|
77
48
|
}
|
|
78
49
|
function _isBaseChatModel(model) {
|
|
79
|
-
|
|
80
|
-
typeof model.invoke === "function" &&
|
|
81
|
-
"_modelType" in model);
|
|
50
|
+
return "invoke" in model && typeof model.invoke === "function" && "_modelType" in model;
|
|
82
51
|
}
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
52
|
function _isConfigurableModel(model) {
|
|
85
|
-
|
|
86
|
-
"_model" in model &&
|
|
87
|
-
typeof model._model === "function");
|
|
53
|
+
return "_queuedMethodOperations" in model && "_model" in model && typeof model._model === "function";
|
|
88
54
|
}
|
|
89
55
|
function _isChatModelWithBindTools(llm) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return "bindTools" in llm && typeof llm.bindTools === "function";
|
|
56
|
+
if (!_isBaseChatModel(llm)) return false;
|
|
57
|
+
return "bindTools" in llm && typeof llm.bindTools === "function";
|
|
93
58
|
}
|
|
94
59
|
async function _shouldBindTools(llm, tools) {
|
|
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
|
-
typeof model.config === "object" &&
|
|
121
|
-
"tools" in model.config &&
|
|
122
|
-
Array.isArray(model.config.tools)) {
|
|
123
|
-
return (model.config.tools ?? null);
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
126
|
-
})();
|
|
127
|
-
// google-style
|
|
128
|
-
if (boundTools != null &&
|
|
129
|
-
boundTools.length === 1 &&
|
|
130
|
-
"functionDeclarations" in boundTools[0]) {
|
|
131
|
-
boundTools = boundTools[0].functionDeclarations;
|
|
132
|
-
}
|
|
133
|
-
// If no tools in kwargs, we should bind tools
|
|
134
|
-
if (boundTools == null)
|
|
135
|
-
return true;
|
|
136
|
-
// Check if tools count matches
|
|
137
|
-
if (tools.length !== boundTools.length) {
|
|
138
|
-
throw new Error("Number of tools in the model.bindTools() and tools passed to createReactAgent must match");
|
|
139
|
-
}
|
|
140
|
-
const toolNames = new Set(tools.flatMap((tool) => (isClientTool(tool) ? tool.name : [])));
|
|
141
|
-
const boundToolNames = new Set();
|
|
142
|
-
for (const boundTool of boundTools) {
|
|
143
|
-
let boundToolName;
|
|
144
|
-
// OpenAI-style tool
|
|
145
|
-
if ("type" in boundTool && boundTool.type === "function") {
|
|
146
|
-
boundToolName = boundTool.function.name;
|
|
147
|
-
}
|
|
148
|
-
// Anthropic or Google-style tool
|
|
149
|
-
else if ("name" in boundTool) {
|
|
150
|
-
boundToolName = boundTool.name;
|
|
151
|
-
}
|
|
152
|
-
// Bedrock-style tool
|
|
153
|
-
else if ("toolSpec" in boundTool && "name" in boundTool.toolSpec) {
|
|
154
|
-
boundToolName = boundTool.toolSpec.name;
|
|
155
|
-
}
|
|
156
|
-
// unknown tool type so we'll ignore it
|
|
157
|
-
else {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (boundToolName) {
|
|
161
|
-
boundToolNames.add(boundToolName);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));
|
|
165
|
-
if (missingTools.length > 0) {
|
|
166
|
-
throw new Error(`Missing tools '${missingTools}' in the model.bindTools().` +
|
|
167
|
-
`Tools in the model.bindTools() must match the tools passed to createReactAgent.`);
|
|
168
|
-
}
|
|
169
|
-
return false;
|
|
60
|
+
let model = llm;
|
|
61
|
+
if (__langchain_core_runnables.RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => __langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
|
|
62
|
+
if (_isConfigurableModel(model)) model = await model._model();
|
|
63
|
+
if (!__langchain_core_runnables.RunnableBinding.isRunnableBinding(model)) return true;
|
|
64
|
+
let boundTools = (() => {
|
|
65
|
+
if (model.kwargs != null && typeof model.kwargs === "object" && "tools" in model.kwargs && Array.isArray(model.kwargs.tools)) return model.kwargs.tools ?? null;
|
|
66
|
+
if (model.config != null && typeof model.config === "object" && "tools" in model.config && Array.isArray(model.config.tools)) return model.config.tools ?? null;
|
|
67
|
+
return null;
|
|
68
|
+
})();
|
|
69
|
+
if (boundTools != null && boundTools.length === 1 && "functionDeclarations" in boundTools[0]) boundTools = boundTools[0].functionDeclarations;
|
|
70
|
+
if (boundTools == null) return true;
|
|
71
|
+
if (tools.length !== boundTools.length) throw new Error("Number of tools in the model.bindTools() and tools passed to createReactAgent must match");
|
|
72
|
+
const toolNames = new Set(tools.flatMap((tool) => isClientTool(tool) ? tool.name : []));
|
|
73
|
+
const boundToolNames = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const boundTool of boundTools) {
|
|
75
|
+
let boundToolName;
|
|
76
|
+
if ("type" in boundTool && boundTool.type === "function") boundToolName = boundTool.function.name;
|
|
77
|
+
else if ("name" in boundTool) boundToolName = boundTool.name;
|
|
78
|
+
else if ("toolSpec" in boundTool && "name" in boundTool.toolSpec) boundToolName = boundTool.toolSpec.name;
|
|
79
|
+
else continue;
|
|
80
|
+
if (boundToolName) boundToolNames.add(boundToolName);
|
|
81
|
+
}
|
|
82
|
+
const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));
|
|
83
|
+
if (missingTools.length > 0) throw new Error(`Missing tools '${missingTools}' in the model.bindTools().Tools in the model.bindTools() must match the tools passed to createReactAgent.`);
|
|
84
|
+
return false;
|
|
170
85
|
}
|
|
171
86
|
const _simpleBindTools = (llm, toolClasses) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
87
|
+
if (_isChatModelWithBindTools(llm)) return llm.bindTools(toolClasses);
|
|
88
|
+
if (__langchain_core_runnables.RunnableBinding.isRunnableBinding(llm) && _isChatModelWithBindTools(llm.bound)) {
|
|
89
|
+
const newBound = llm.bound.bindTools(toolClasses);
|
|
90
|
+
if (__langchain_core_runnables.RunnableBinding.isRunnableBinding(newBound)) return new __langchain_core_runnables.RunnableBinding({
|
|
91
|
+
bound: newBound.bound,
|
|
92
|
+
config: {
|
|
93
|
+
...llm.config,
|
|
94
|
+
...newBound.config
|
|
95
|
+
},
|
|
96
|
+
kwargs: {
|
|
97
|
+
...llm.kwargs,
|
|
98
|
+
...newBound.kwargs
|
|
99
|
+
},
|
|
100
|
+
configFactories: newBound.configFactories ?? llm.configFactories
|
|
101
|
+
});
|
|
102
|
+
return new __langchain_core_runnables.RunnableBinding({
|
|
103
|
+
bound: newBound,
|
|
104
|
+
config: llm.config,
|
|
105
|
+
kwargs: llm.kwargs,
|
|
106
|
+
configFactories: llm.configFactories
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
194
110
|
};
|
|
195
111
|
async function _bindTools(llm, toolClasses) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
throw new Error(`llm ${llm} must define bindTools method.`);
|
|
112
|
+
const model = _simpleBindTools(llm, toolClasses);
|
|
113
|
+
if (model) return model;
|
|
114
|
+
if (_isConfigurableModel(llm)) {
|
|
115
|
+
const model$1 = _simpleBindTools(await llm._model(), toolClasses);
|
|
116
|
+
if (model$1) return model$1;
|
|
117
|
+
}
|
|
118
|
+
if (__langchain_core_runnables.RunnableSequence.isRunnableSequence(llm)) {
|
|
119
|
+
const modelStep = llm.steps.findIndex((step) => __langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step));
|
|
120
|
+
if (modelStep >= 0) {
|
|
121
|
+
const model$1 = _simpleBindTools(llm.steps[modelStep], toolClasses);
|
|
122
|
+
if (model$1) {
|
|
123
|
+
const nextSteps = llm.steps.slice();
|
|
124
|
+
nextSteps.splice(modelStep, 1, model$1);
|
|
125
|
+
return __langchain_core_runnables.RunnableSequence.from(nextSteps);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`llm ${llm} must define bindTools method.`);
|
|
218
130
|
}
|
|
219
131
|
async function _getModel(llm) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
_isConfigurableModel(step)) || model;
|
|
227
|
-
}
|
|
228
|
-
if (_isConfigurableModel(model)) {
|
|
229
|
-
model = await model._model();
|
|
230
|
-
}
|
|
231
|
-
// Get the underlying model from a RunnableBinding
|
|
232
|
-
if (runnables_1.RunnableBinding.isRunnableBinding(model)) {
|
|
233
|
-
model = model.bound;
|
|
234
|
-
}
|
|
235
|
-
if (!_isBaseChatModel(model)) {
|
|
236
|
-
throw new Error(`Expected \`llm\` to be a ChatModel or RunnableBinding (e.g. llm.bind_tools(...)) with invoke() and generate() methods, got ${model.constructor.name}`);
|
|
237
|
-
}
|
|
238
|
-
return model;
|
|
132
|
+
let model = llm;
|
|
133
|
+
if (__langchain_core_runnables.RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => __langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
|
|
134
|
+
if (_isConfigurableModel(model)) model = await model._model();
|
|
135
|
+
if (__langchain_core_runnables.RunnableBinding.isRunnableBinding(model)) model = model.bound;
|
|
136
|
+
if (!_isBaseChatModel(model)) throw new Error(`Expected \`llm\` to be a ChatModel or RunnableBinding (e.g. llm.bind_tools(...)) with invoke() and generate() methods, got ${model.constructor.name}`);
|
|
137
|
+
return model;
|
|
239
138
|
}
|
|
240
|
-
const createReactAgentAnnotation = () =>
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
});
|
|
247
|
-
exports.createReactAgentAnnotation = createReactAgentAnnotation;
|
|
248
|
-
const PreHookAnnotation = annotation_js_1.Annotation.Root({
|
|
249
|
-
llmInputMessages: (0, annotation_js_1.Annotation)({
|
|
250
|
-
reducer: (_, update) => (0, message_js_1.messagesStateReducer)([], update),
|
|
251
|
-
default: () => [],
|
|
252
|
-
}),
|
|
139
|
+
const createReactAgentAnnotation = () => require_annotation.Annotation.Root({
|
|
140
|
+
messages: require_annotation.Annotation({
|
|
141
|
+
reducer: require_message.messagesStateReducer,
|
|
142
|
+
default: () => []
|
|
143
|
+
}),
|
|
144
|
+
structuredResponse: require_annotation.Annotation
|
|
253
145
|
});
|
|
146
|
+
const PreHookAnnotation = require_annotation.Annotation.Root({ llmInputMessages: require_annotation.Annotation({
|
|
147
|
+
reducer: (_, update) => require_message.messagesStateReducer([], update),
|
|
148
|
+
default: () => []
|
|
149
|
+
}) });
|
|
254
150
|
/**
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
151
|
+
* @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
|
|
152
|
+
* Update your import to `import { createReactAgent } from "langchain";`
|
|
153
|
+
*
|
|
154
|
+
* Creates a StateGraph agent that relies on a chat model utilizing tool calling.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { ChatOpenAI } from "@langchain/openai";
|
|
159
|
+
* import { tool } from "@langchain/core/tools";
|
|
160
|
+
* import { z } from "zod";
|
|
161
|
+
* import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
162
|
+
*
|
|
163
|
+
* const model = new ChatOpenAI({
|
|
164
|
+
* model: "gpt-4o",
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* const getWeather = tool((input) => {
|
|
168
|
+
* if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
|
|
169
|
+
* return "It's 60 degrees and foggy.";
|
|
170
|
+
* } else {
|
|
171
|
+
* return "It's 90 degrees and sunny.";
|
|
172
|
+
* }
|
|
173
|
+
* }, {
|
|
174
|
+
* name: "get_weather",
|
|
175
|
+
* description: "Call to get the current weather.",
|
|
176
|
+
* schema: z.object({
|
|
177
|
+
* location: z.string().describe("Location to get the weather for."),
|
|
178
|
+
* })
|
|
179
|
+
* })
|
|
180
|
+
*
|
|
181
|
+
* const agent = createReactAgent({ llm: model, tools: [getWeather] });
|
|
182
|
+
*
|
|
183
|
+
* const inputs = {
|
|
184
|
+
* messages: [{ role: "user", content: "what is the weather in SF?" }],
|
|
185
|
+
* };
|
|
186
|
+
*
|
|
187
|
+
* const stream = await agent.stream(inputs, { streamMode: "values" });
|
|
188
|
+
*
|
|
189
|
+
* for await (const { messages } of stream) {
|
|
190
|
+
* console.log(messages);
|
|
191
|
+
* }
|
|
192
|
+
* // Returns the messages in the state at each step of execution
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
296
195
|
function createReactAgent(params) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
tools: "tools",
|
|
441
|
-
[entrypoint]: entrypoint,
|
|
442
|
-
generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
|
|
443
|
-
[constants_js_1.END]: responseFormat != null ? null : constants_js_1.END,
|
|
444
|
-
}));
|
|
445
|
-
}
|
|
446
|
-
if (responseFormat !== undefined) {
|
|
447
|
-
workflow
|
|
448
|
-
.addNode("generate_structured_response", generateStructuredResponse)
|
|
449
|
-
.addEdge("generate_structured_response", constants_js_1.END);
|
|
450
|
-
}
|
|
451
|
-
if (postModelHook == null) {
|
|
452
|
-
allNodeWorkflows.addConditionalEdges("agent", (state) => {
|
|
453
|
-
const { messages } = state;
|
|
454
|
-
const lastMessage = messages[messages.length - 1];
|
|
455
|
-
// if there's no function call, we finish
|
|
456
|
-
if (!(0, messages_1.isAIMessage)(lastMessage) || !lastMessage.tool_calls?.length) {
|
|
457
|
-
if (responseFormat != null)
|
|
458
|
-
return "generate_structured_response";
|
|
459
|
-
return constants_js_1.END;
|
|
460
|
-
}
|
|
461
|
-
// there are function calls, we continue
|
|
462
|
-
if (version === "v2") {
|
|
463
|
-
return lastMessage.tool_calls.map((toolCall) => new constants_js_1.Send("tools", { ...state, lg_tool_call: toolCall }));
|
|
464
|
-
}
|
|
465
|
-
return "tools";
|
|
466
|
-
}, conditionalMap({
|
|
467
|
-
tools: "tools",
|
|
468
|
-
generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
|
|
469
|
-
[constants_js_1.END]: responseFormat != null ? null : constants_js_1.END,
|
|
470
|
-
}));
|
|
471
|
-
}
|
|
472
|
-
if (shouldReturnDirect.size > 0) {
|
|
473
|
-
allNodeWorkflows.addConditionalEdges("tools", (state) => {
|
|
474
|
-
// Check the last consecutive tool calls
|
|
475
|
-
for (let i = state.messages.length - 1; i >= 0; i -= 1) {
|
|
476
|
-
const message = state.messages[i];
|
|
477
|
-
if (!(0, messages_1.isToolMessage)(message))
|
|
478
|
-
break;
|
|
479
|
-
// Check if this tool is configured to return directly
|
|
480
|
-
if (message.name !== undefined &&
|
|
481
|
-
shouldReturnDirect.has(message.name)) {
|
|
482
|
-
return constants_js_1.END;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
return entrypoint;
|
|
486
|
-
}, conditionalMap({ [entrypoint]: entrypoint, [constants_js_1.END]: constants_js_1.END }));
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
allNodeWorkflows.addEdge("tools", entrypoint);
|
|
490
|
-
}
|
|
491
|
-
return allNodeWorkflows.compile({
|
|
492
|
-
checkpointer: checkpointer ?? checkpointSaver,
|
|
493
|
-
interruptBefore,
|
|
494
|
-
interruptAfter,
|
|
495
|
-
store,
|
|
496
|
-
name,
|
|
497
|
-
description,
|
|
498
|
-
});
|
|
196
|
+
const { llm, tools, messageModifier, stateModifier, prompt, stateSchema, contextSchema, checkpointSaver, checkpointer, interruptBefore, interruptAfter, store, responseFormat, preModelHook, postModelHook, name, description, version = "v1", includeAgentName } = params;
|
|
197
|
+
let toolClasses;
|
|
198
|
+
let toolNode;
|
|
199
|
+
if (!Array.isArray(tools)) {
|
|
200
|
+
toolClasses = tools.tools;
|
|
201
|
+
toolNode = tools;
|
|
202
|
+
} else {
|
|
203
|
+
toolClasses = tools;
|
|
204
|
+
toolNode = new require_tool_node.ToolNode(toolClasses.filter(isClientTool));
|
|
205
|
+
}
|
|
206
|
+
let cachedStaticModel = null;
|
|
207
|
+
const _getStaticModel = async (llm$1) => {
|
|
208
|
+
if (cachedStaticModel) return cachedStaticModel;
|
|
209
|
+
let modelWithTools;
|
|
210
|
+
if (await _shouldBindTools(llm$1, toolClasses)) modelWithTools = await _bindTools(llm$1, toolClasses);
|
|
211
|
+
else modelWithTools = llm$1;
|
|
212
|
+
const promptRunnable = _getPrompt(prompt, stateModifier, messageModifier);
|
|
213
|
+
const modelRunnable = includeAgentName === "inline" ? require_agentName.withAgentName(modelWithTools, includeAgentName) : modelWithTools;
|
|
214
|
+
cachedStaticModel = promptRunnable.pipe(modelRunnable);
|
|
215
|
+
return cachedStaticModel;
|
|
216
|
+
};
|
|
217
|
+
const _getDynamicModel = async (llm$1, state, config) => {
|
|
218
|
+
const model = await llm$1(state, config);
|
|
219
|
+
return _getPrompt(prompt, stateModifier, messageModifier).pipe(includeAgentName === "inline" ? require_agentName.withAgentName(model, includeAgentName) : model);
|
|
220
|
+
};
|
|
221
|
+
const shouldReturnDirect = new Set(toolClasses.filter(isClientTool).filter((tool) => "returnDirect" in tool && tool.returnDirect).map((tool) => tool.name));
|
|
222
|
+
function getModelInputState(state) {
|
|
223
|
+
const { messages, llmInputMessages,...rest } = state;
|
|
224
|
+
if (llmInputMessages != null && llmInputMessages.length > 0) return {
|
|
225
|
+
messages: llmInputMessages,
|
|
226
|
+
...rest
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
messages,
|
|
230
|
+
...rest
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
const generateStructuredResponse = async (state, config) => {
|
|
234
|
+
if (responseFormat == null) throw new Error("Attempted to generate structured output with no passed response schema. Please contact us for help.");
|
|
235
|
+
const messages = [...state.messages];
|
|
236
|
+
let modelWithStructuredOutput;
|
|
237
|
+
const model = typeof llm === "function" ? await llm(state, config) : await _getModel(llm);
|
|
238
|
+
if (!_isBaseChatModel(model)) throw new Error(`Expected \`llm\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`);
|
|
239
|
+
if (typeof responseFormat === "object" && "schema" in responseFormat) {
|
|
240
|
+
const { prompt: prompt$1, schema: schema$1,...options } = responseFormat;
|
|
241
|
+
modelWithStructuredOutput = model.withStructuredOutput(schema$1, options);
|
|
242
|
+
if (prompt$1 != null) messages.unshift(new __langchain_core_messages.SystemMessage({ content: prompt$1 }));
|
|
243
|
+
} else modelWithStructuredOutput = model.withStructuredOutput(responseFormat);
|
|
244
|
+
const response = await modelWithStructuredOutput.invoke(messages, config);
|
|
245
|
+
return { structuredResponse: response };
|
|
246
|
+
};
|
|
247
|
+
const callModel = async (state, config) => {
|
|
248
|
+
const modelRunnable = typeof llm === "function" ? await _getDynamicModel(llm, state, config) : await _getStaticModel(llm);
|
|
249
|
+
const response = await modelRunnable.invoke(getModelInputState(state), config);
|
|
250
|
+
response.name = name;
|
|
251
|
+
response.lc_kwargs.name = name;
|
|
252
|
+
return { messages: [response] };
|
|
253
|
+
};
|
|
254
|
+
const schema = stateSchema ?? createReactAgentAnnotation();
|
|
255
|
+
const workflow = new require_state.StateGraph(schema, contextSchema).addNode("tools", toolNode);
|
|
256
|
+
if (!("messages" in workflow._schemaDefinition)) throw new Error("Missing required `messages` key in state schema.");
|
|
257
|
+
const allNodeWorkflows = workflow;
|
|
258
|
+
const conditionalMap = (map) => {
|
|
259
|
+
return Object.fromEntries(Object.entries(map).filter(([_, v]) => v != null));
|
|
260
|
+
};
|
|
261
|
+
let entrypoint = "agent";
|
|
262
|
+
let inputSchema;
|
|
263
|
+
if (preModelHook != null) {
|
|
264
|
+
allNodeWorkflows.addNode("pre_model_hook", preModelHook).addEdge("pre_model_hook", "agent");
|
|
265
|
+
entrypoint = "pre_model_hook";
|
|
266
|
+
inputSchema = require_annotation.Annotation.Root({
|
|
267
|
+
...workflow._schemaDefinition,
|
|
268
|
+
...PreHookAnnotation.spec
|
|
269
|
+
});
|
|
270
|
+
} else entrypoint = "agent";
|
|
271
|
+
allNodeWorkflows.addNode("agent", callModel, { input: inputSchema }).addEdge(require_constants.START, entrypoint);
|
|
272
|
+
if (postModelHook != null) allNodeWorkflows.addNode("post_model_hook", postModelHook).addEdge("agent", "post_model_hook").addConditionalEdges("post_model_hook", (state) => {
|
|
273
|
+
const { messages } = state;
|
|
274
|
+
const toolMessageIds = new Set(messages.filter(__langchain_core_messages.isToolMessage).map((msg) => msg.tool_call_id));
|
|
275
|
+
let lastAiMessage;
|
|
276
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
277
|
+
const message = messages[i];
|
|
278
|
+
if ((0, __langchain_core_messages.isAIMessage)(message)) {
|
|
279
|
+
lastAiMessage = message;
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const pendingToolCalls = lastAiMessage?.tool_calls?.filter((i) => i.id == null || !toolMessageIds.has(i.id)) ?? [];
|
|
284
|
+
const lastMessage = messages.at(-1);
|
|
285
|
+
if (pendingToolCalls.length > 0) {
|
|
286
|
+
if (version === "v2") return pendingToolCalls.map((toolCall) => new require_constants.Send("tools", {
|
|
287
|
+
...state,
|
|
288
|
+
lg_tool_call: toolCall
|
|
289
|
+
}));
|
|
290
|
+
return "tools";
|
|
291
|
+
}
|
|
292
|
+
if (lastMessage && (0, __langchain_core_messages.isToolMessage)(lastMessage)) return entrypoint;
|
|
293
|
+
if (responseFormat != null) return "generate_structured_response";
|
|
294
|
+
return require_constants.END;
|
|
295
|
+
}, conditionalMap({
|
|
296
|
+
tools: "tools",
|
|
297
|
+
[entrypoint]: entrypoint,
|
|
298
|
+
generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
|
|
299
|
+
[require_constants.END]: responseFormat != null ? null : require_constants.END
|
|
300
|
+
}));
|
|
301
|
+
if (responseFormat !== void 0) workflow.addNode("generate_structured_response", generateStructuredResponse).addEdge("generate_structured_response", require_constants.END);
|
|
302
|
+
if (postModelHook == null) allNodeWorkflows.addConditionalEdges("agent", (state) => {
|
|
303
|
+
const { messages } = state;
|
|
304
|
+
const lastMessage = messages[messages.length - 1];
|
|
305
|
+
if (!(0, __langchain_core_messages.isAIMessage)(lastMessage) || !lastMessage.tool_calls?.length) {
|
|
306
|
+
if (responseFormat != null) return "generate_structured_response";
|
|
307
|
+
return require_constants.END;
|
|
308
|
+
}
|
|
309
|
+
if (version === "v2") return lastMessage.tool_calls.map((toolCall) => new require_constants.Send("tools", {
|
|
310
|
+
...state,
|
|
311
|
+
lg_tool_call: toolCall
|
|
312
|
+
}));
|
|
313
|
+
return "tools";
|
|
314
|
+
}, conditionalMap({
|
|
315
|
+
tools: "tools",
|
|
316
|
+
generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
|
|
317
|
+
[require_constants.END]: responseFormat != null ? null : require_constants.END
|
|
318
|
+
}));
|
|
319
|
+
if (shouldReturnDirect.size > 0) allNodeWorkflows.addConditionalEdges("tools", (state) => {
|
|
320
|
+
for (let i = state.messages.length - 1; i >= 0; i -= 1) {
|
|
321
|
+
const message = state.messages[i];
|
|
322
|
+
if (!(0, __langchain_core_messages.isToolMessage)(message)) break;
|
|
323
|
+
if (message.name !== void 0 && shouldReturnDirect.has(message.name)) return require_constants.END;
|
|
324
|
+
}
|
|
325
|
+
return entrypoint;
|
|
326
|
+
}, conditionalMap({
|
|
327
|
+
[entrypoint]: entrypoint,
|
|
328
|
+
[require_constants.END]: require_constants.END
|
|
329
|
+
}));
|
|
330
|
+
else allNodeWorkflows.addEdge("tools", entrypoint);
|
|
331
|
+
return allNodeWorkflows.compile({
|
|
332
|
+
checkpointer: checkpointer ?? checkpointSaver,
|
|
333
|
+
interruptBefore,
|
|
334
|
+
interruptAfter,
|
|
335
|
+
store,
|
|
336
|
+
name,
|
|
337
|
+
description
|
|
338
|
+
});
|
|
499
339
|
}
|
|
500
|
-
|
|
340
|
+
|
|
341
|
+
//#endregion
|
|
342
|
+
exports.createReactAgent = createReactAgent;
|
|
343
|
+
exports.createReactAgentAnnotation = createReactAgentAnnotation;
|
|
344
|
+
//# sourceMappingURL=react_agent_executor.cjs.map
|