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