langchain 0.0.130 → 0.0.132

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.
Files changed (831) hide show
  1. package/dist/agents/agent.cjs +23 -0
  2. package/dist/agents/agent.d.ts +28 -0
  3. package/dist/agents/agent.js +23 -0
  4. package/dist/agents/chat/index.cjs +28 -0
  5. package/dist/agents/chat/index.d.ts +33 -0
  6. package/dist/agents/chat/index.js +28 -0
  7. package/dist/agents/chat/outputParser.cjs +19 -0
  8. package/dist/agents/chat/outputParser.d.ts +19 -0
  9. package/dist/agents/chat/outputParser.js +19 -0
  10. package/dist/agents/chat_convo/index.cjs +25 -0
  11. package/dist/agents/chat_convo/index.d.ts +32 -0
  12. package/dist/agents/chat_convo/index.js +25 -0
  13. package/dist/agents/chat_convo/outputParser.cjs +42 -0
  14. package/dist/agents/chat_convo/outputParser.d.ts +42 -0
  15. package/dist/agents/chat_convo/outputParser.js +42 -0
  16. package/dist/agents/executor.cjs +9 -0
  17. package/dist/agents/executor.d.ts +12 -0
  18. package/dist/agents/executor.js +9 -0
  19. package/dist/agents/initialize.d.ts +5 -0
  20. package/dist/agents/mrkl/index.cjs +20 -0
  21. package/dist/agents/mrkl/index.d.ts +25 -0
  22. package/dist/agents/mrkl/index.js +20 -0
  23. package/dist/agents/mrkl/outputParser.cjs +15 -0
  24. package/dist/agents/mrkl/outputParser.d.ts +15 -0
  25. package/dist/agents/mrkl/outputParser.js +15 -0
  26. package/dist/agents/openai/index.cjs +46 -0
  27. package/dist/agents/openai/index.d.ts +40 -0
  28. package/dist/agents/openai/index.js +46 -0
  29. package/dist/agents/structured_chat/index.cjs +35 -0
  30. package/dist/agents/structured_chat/index.d.ts +41 -0
  31. package/dist/agents/structured_chat/index.js +35 -0
  32. package/dist/agents/structured_chat/outputParser.cjs +44 -0
  33. package/dist/agents/structured_chat/outputParser.d.ts +48 -0
  34. package/dist/agents/structured_chat/outputParser.js +44 -0
  35. package/dist/agents/toolkits/aws_sfn.cjs +5 -0
  36. package/dist/agents/toolkits/aws_sfn.d.ts +9 -0
  37. package/dist/agents/toolkits/aws_sfn.js +5 -0
  38. package/dist/agents/toolkits/base.cjs +5 -0
  39. package/dist/agents/toolkits/base.d.ts +5 -0
  40. package/dist/agents/toolkits/base.js +5 -0
  41. package/dist/agents/toolkits/conversational_retrieval/openai_functions.cjs +10 -0
  42. package/dist/agents/toolkits/conversational_retrieval/openai_functions.d.ts +10 -0
  43. package/dist/agents/toolkits/conversational_retrieval/openai_functions.js +10 -0
  44. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.cjs +17 -0
  45. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +21 -0
  46. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.js +17 -0
  47. package/dist/agents/toolkits/json/json.cjs +15 -0
  48. package/dist/agents/toolkits/json/json.d.ts +15 -0
  49. package/dist/agents/toolkits/json/json.js +15 -0
  50. package/dist/agents/toolkits/openapi/openapi.cjs +21 -0
  51. package/dist/agents/toolkits/openapi/openapi.d.ts +21 -0
  52. package/dist/agents/toolkits/openapi/openapi.js +21 -0
  53. package/dist/agents/toolkits/sql/sql.cjs +4 -0
  54. package/dist/agents/toolkits/sql/sql.d.ts +8 -0
  55. package/dist/agents/toolkits/sql/sql.js +4 -0
  56. package/dist/agents/toolkits/vectorstore/vectorstore.cjs +10 -0
  57. package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +14 -0
  58. package/dist/agents/toolkits/vectorstore/vectorstore.js +10 -0
  59. package/dist/agents/toolkits/zapier/zapier.cjs +12 -0
  60. package/dist/agents/toolkits/zapier/zapier.d.ts +12 -0
  61. package/dist/agents/toolkits/zapier/zapier.js +12 -0
  62. package/dist/agents/types.cjs +5 -0
  63. package/dist/agents/types.d.ts +28 -0
  64. package/dist/agents/types.js +5 -0
  65. package/dist/cache/index.cjs +21 -0
  66. package/dist/cache/index.d.ts +21 -0
  67. package/dist/cache/index.js +21 -0
  68. package/dist/cache/ioredis.cjs +16 -0
  69. package/dist/cache/ioredis.d.ts +16 -0
  70. package/dist/cache/ioredis.js +16 -0
  71. package/dist/cache/redis.cjs +21 -0
  72. package/dist/cache/redis.d.ts +25 -0
  73. package/dist/cache/redis.js +21 -0
  74. package/dist/callbacks/base.cjs +29 -0
  75. package/dist/callbacks/base.d.ts +35 -0
  76. package/dist/callbacks/base.js +30 -1
  77. package/dist/callbacks/handlers/console.cjs +87 -0
  78. package/dist/callbacks/handlers/console.d.ts +87 -0
  79. package/dist/callbacks/handlers/console.js +87 -0
  80. package/dist/callbacks/handlers/initialize.cjs +12 -0
  81. package/dist/callbacks/handlers/initialize.d.ts +12 -0
  82. package/dist/callbacks/handlers/initialize.js +12 -0
  83. package/dist/callbacks/manager.cjs +9 -0
  84. package/dist/callbacks/manager.d.ts +9 -0
  85. package/dist/callbacks/manager.js +9 -0
  86. package/dist/callbacks/promises.cjs +9 -0
  87. package/dist/callbacks/promises.d.ts +4 -0
  88. package/dist/callbacks/promises.js +9 -0
  89. package/dist/chains/analyze_documents_chain.cjs +3 -0
  90. package/dist/chains/analyze_documents_chain.d.ts +5 -0
  91. package/dist/chains/analyze_documents_chain.js +3 -0
  92. package/dist/chains/api/api_chain.cjs +12 -0
  93. package/dist/chains/api/api_chain.d.ts +19 -0
  94. package/dist/chains/api/api_chain.js +12 -0
  95. package/dist/chains/base.cjs +6 -0
  96. package/dist/chains/base.d.ts +6 -0
  97. package/dist/chains/base.js +6 -0
  98. package/dist/chains/chat_vector_db_chain.cjs +8 -0
  99. package/dist/chains/chat_vector_db_chain.d.ts +11 -0
  100. package/dist/chains/chat_vector_db_chain.js +8 -0
  101. package/dist/chains/combine_docs_chain.cjs +9 -0
  102. package/dist/chains/combine_docs_chain.d.ts +13 -0
  103. package/dist/chains/combine_docs_chain.js +9 -0
  104. package/dist/chains/constitutional_ai/constitutional_chain.cjs +20 -0
  105. package/dist/chains/constitutional_ai/constitutional_chain.d.ts +21 -0
  106. package/dist/chains/constitutional_ai/constitutional_chain.js +20 -0
  107. package/dist/chains/constitutional_ai/constitutional_principle.cjs +4 -0
  108. package/dist/chains/constitutional_ai/constitutional_principle.d.ts +4 -0
  109. package/dist/chains/constitutional_ai/constitutional_principle.js +4 -0
  110. package/dist/chains/conversation.cjs +7 -0
  111. package/dist/chains/conversation.d.ts +5 -0
  112. package/dist/chains/conversation.js +7 -0
  113. package/dist/chains/conversational_retrieval_chain.cjs +24 -0
  114. package/dist/chains/conversational_retrieval_chain.d.ts +27 -1
  115. package/dist/chains/conversational_retrieval_chain.js +24 -0
  116. package/dist/chains/llm_chain.cjs +3 -0
  117. package/dist/chains/llm_chain.d.ts +4 -0
  118. package/dist/chains/llm_chain.js +3 -0
  119. package/dist/chains/openai_functions/extraction.cjs +21 -0
  120. package/dist/chains/openai_functions/extraction.d.ts +15 -0
  121. package/dist/chains/openai_functions/extraction.js +21 -0
  122. package/dist/chains/openai_functions/openapi.cjs +30 -0
  123. package/dist/chains/openai_functions/openapi.d.ts +3 -0
  124. package/dist/chains/openai_functions/openapi.js +30 -0
  125. package/dist/chains/openai_functions/structured_output.cjs +12 -0
  126. package/dist/chains/openai_functions/structured_output.d.ts +18 -0
  127. package/dist/chains/openai_functions/structured_output.js +12 -0
  128. package/dist/chains/openai_functions/tagging.cjs +24 -0
  129. package/dist/chains/openai_functions/tagging.d.ts +21 -0
  130. package/dist/chains/openai_functions/tagging.js +24 -0
  131. package/dist/chains/openai_moderation.cjs +8 -0
  132. package/dist/chains/openai_moderation.d.ts +9 -0
  133. package/dist/chains/openai_moderation.js +8 -0
  134. package/dist/chains/query_constructor/index.cjs +17 -0
  135. package/dist/chains/query_constructor/index.d.ts +20 -0
  136. package/dist/chains/query_constructor/index.js +17 -0
  137. package/dist/chains/query_constructor/ir.cjs +24 -0
  138. package/dist/chains/query_constructor/ir.d.ts +71 -0
  139. package/dist/chains/query_constructor/ir.js +24 -0
  140. package/dist/chains/query_constructor/parser.cjs +21 -0
  141. package/dist/chains/query_constructor/parser.d.ts +25 -0
  142. package/dist/chains/query_constructor/parser.js +21 -0
  143. package/dist/chains/question_answering/load.cjs +21 -0
  144. package/dist/chains/question_answering/load.d.ts +34 -0
  145. package/dist/chains/question_answering/load.js +21 -0
  146. package/dist/chains/retrieval_qa.cjs +15 -0
  147. package/dist/chains/retrieval_qa.d.ts +16 -0
  148. package/dist/chains/retrieval_qa.js +15 -0
  149. package/dist/chains/router/llm_router.cjs +16 -0
  150. package/dist/chains/router/llm_router.d.ts +24 -0
  151. package/dist/chains/router/llm_router.js +16 -0
  152. package/dist/chains/router/multi_prompt.cjs +19 -0
  153. package/dist/chains/router/multi_prompt.d.ts +19 -0
  154. package/dist/chains/router/multi_prompt.js +19 -0
  155. package/dist/chains/router/multi_retrieval_qa.cjs +22 -0
  156. package/dist/chains/router/multi_retrieval_qa.d.ts +27 -0
  157. package/dist/chains/router/multi_retrieval_qa.js +22 -0
  158. package/dist/chains/router/multi_route.cjs +13 -0
  159. package/dist/chains/router/multi_route.d.ts +26 -0
  160. package/dist/chains/router/multi_route.js +13 -0
  161. package/dist/chains/sequential_chain.cjs +6 -0
  162. package/dist/chains/sequential_chain.d.ts +8 -0
  163. package/dist/chains/sequential_chain.js +6 -0
  164. package/dist/chains/serde.d.ts +58 -0
  165. package/dist/chains/sql_db/sql_db_chain.cjs +16 -0
  166. package/dist/chains/sql_db/sql_db_chain.d.ts +19 -0
  167. package/dist/chains/sql_db/sql_db_chain.js +16 -0
  168. package/dist/chains/summarization/load.d.ts +4 -0
  169. package/dist/chains/transform.cjs +9 -0
  170. package/dist/chains/transform.d.ts +12 -0
  171. package/dist/chains/transform.js +9 -0
  172. package/dist/chains/vector_db_qa.cjs +18 -0
  173. package/dist/chains/vector_db_qa.d.ts +22 -0
  174. package/dist/chains/vector_db_qa.js +18 -0
  175. package/dist/chat_models/anthropic.cjs +27 -4
  176. package/dist/chat_models/anthropic.d.ts +15 -0
  177. package/dist/chat_models/anthropic.js +27 -4
  178. package/dist/chat_models/baiduwenxin.cjs +19 -13
  179. package/dist/chat_models/baiduwenxin.d.ts +19 -3
  180. package/dist/chat_models/baiduwenxin.js +19 -13
  181. package/dist/chat_models/base.cjs +61 -0
  182. package/dist/chat_models/base.d.ts +73 -0
  183. package/dist/chat_models/base.js +61 -0
  184. package/dist/chat_models/googlepalm.cjs +12 -0
  185. package/dist/chat_models/googlepalm.d.ts +8 -0
  186. package/dist/chat_models/googlepalm.js +12 -0
  187. package/dist/chat_models/googlevertexai.cjs +41 -0
  188. package/dist/chat_models/googlevertexai.d.ts +51 -0
  189. package/dist/chat_models/googlevertexai.js +41 -0
  190. package/dist/chat_models/ollama.cjs +14 -0
  191. package/dist/chat_models/ollama.d.ts +16 -0
  192. package/dist/chat_models/ollama.js +14 -0
  193. package/dist/chat_models/openai.cjs +19 -5
  194. package/dist/chat_models/openai.d.ts +7 -5
  195. package/dist/chat_models/openai.js +19 -5
  196. package/dist/document_loaders/base.cjs +10 -0
  197. package/dist/document_loaders/base.d.ts +17 -0
  198. package/dist/document_loaders/base.js +10 -0
  199. package/dist/document_loaders/fs/buffer.cjs +21 -0
  200. package/dist/document_loaders/fs/buffer.d.ts +28 -0
  201. package/dist/document_loaders/fs/buffer.js +21 -0
  202. package/dist/document_loaders/fs/csv.cjs +19 -0
  203. package/dist/document_loaders/fs/csv.d.ts +19 -0
  204. package/dist/document_loaders/fs/csv.js +19 -0
  205. package/dist/document_loaders/fs/directory.cjs +21 -0
  206. package/dist/document_loaders/fs/directory.d.ts +29 -0
  207. package/dist/document_loaders/fs/directory.js +21 -0
  208. package/dist/document_loaders/fs/docx.cjs +16 -0
  209. package/dist/document_loaders/fs/docx.d.ts +16 -0
  210. package/dist/document_loaders/fs/docx.js +16 -0
  211. package/dist/document_loaders/fs/epub.cjs +16 -0
  212. package/dist/document_loaders/fs/epub.d.ts +16 -0
  213. package/dist/document_loaders/fs/epub.js +16 -0
  214. package/dist/document_loaders/fs/json.cjs +40 -0
  215. package/dist/document_loaders/fs/json.d.ts +40 -0
  216. package/dist/document_loaders/fs/json.js +40 -0
  217. package/dist/document_loaders/fs/notion.cjs +6 -0
  218. package/dist/document_loaders/fs/notion.d.ts +6 -0
  219. package/dist/document_loaders/fs/notion.js +6 -0
  220. package/dist/document_loaders/fs/pdf.cjs +21 -0
  221. package/dist/document_loaders/fs/pdf.d.ts +21 -0
  222. package/dist/document_loaders/fs/pdf.js +21 -0
  223. package/dist/document_loaders/fs/srt.cjs +19 -0
  224. package/dist/document_loaders/fs/srt.d.ts +19 -0
  225. package/dist/document_loaders/fs/srt.js +19 -0
  226. package/dist/document_loaders/fs/text.cjs +34 -0
  227. package/dist/document_loaders/fs/text.d.ts +34 -0
  228. package/dist/document_loaders/fs/text.js +34 -0
  229. package/dist/document_loaders/fs/unstructured.cjs +14 -0
  230. package/dist/document_loaders/fs/unstructured.d.ts +26 -0
  231. package/dist/document_loaders/fs/unstructured.js +14 -0
  232. package/dist/document_loaders/web/apify_dataset.cjs +11 -0
  233. package/dist/document_loaders/web/apify_dataset.d.ts +15 -0
  234. package/dist/document_loaders/web/apify_dataset.js +11 -0
  235. package/dist/document_loaders/web/azure_blob_storage_container.cjs +13 -0
  236. package/dist/document_loaders/web/azure_blob_storage_container.d.ts +26 -0
  237. package/dist/document_loaders/web/azure_blob_storage_container.js +13 -0
  238. package/dist/document_loaders/web/azure_blob_storage_file.cjs +12 -0
  239. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +21 -0
  240. package/dist/document_loaders/web/azure_blob_storage_file.js +12 -0
  241. package/dist/document_loaders/web/cheerio.cjs +21 -0
  242. package/dist/document_loaders/web/cheerio.d.ts +26 -0
  243. package/dist/document_loaders/web/cheerio.js +21 -0
  244. package/dist/document_loaders/web/college_confidential.cjs +11 -0
  245. package/dist/document_loaders/web/college_confidential.d.ts +11 -0
  246. package/dist/document_loaders/web/college_confidential.js +11 -0
  247. package/dist/document_loaders/web/confluence.cjs +23 -0
  248. package/dist/document_loaders/web/confluence.d.ts +33 -0
  249. package/dist/document_loaders/web/confluence.js +23 -0
  250. package/dist/document_loaders/web/figma.cjs +21 -0
  251. package/dist/document_loaders/web/figma.d.ts +32 -0
  252. package/dist/document_loaders/web/figma.js +21 -0
  253. package/dist/document_loaders/web/gitbook.cjs +33 -0
  254. package/dist/document_loaders/web/gitbook.d.ts +38 -0
  255. package/dist/document_loaders/web/gitbook.js +33 -0
  256. package/dist/document_loaders/web/github.cjs +50 -0
  257. package/dist/document_loaders/web/github.d.ts +53 -0
  258. package/dist/document_loaders/web/github.js +50 -0
  259. package/dist/document_loaders/web/hn.cjs +31 -0
  260. package/dist/document_loaders/web/hn.d.ts +31 -0
  261. package/dist/document_loaders/web/hn.js +31 -0
  262. package/dist/document_loaders/web/imsdb.cjs +14 -0
  263. package/dist/document_loaders/web/imsdb.d.ts +14 -0
  264. package/dist/document_loaders/web/imsdb.js +14 -0
  265. package/dist/document_loaders/web/notionapi.cjs +39 -0
  266. package/dist/document_loaders/web/notionapi.d.ts +43 -0
  267. package/dist/document_loaders/web/notionapi.js +39 -0
  268. package/dist/document_loaders/web/notiondb.cjs +19 -0
  269. package/dist/document_loaders/web/notiondb.d.ts +24 -0
  270. package/dist/document_loaders/web/notiondb.js +19 -0
  271. package/dist/document_loaders/web/playwright.cjs +22 -0
  272. package/dist/document_loaders/web/playwright.d.ts +27 -0
  273. package/dist/document_loaders/web/playwright.js +22 -0
  274. package/dist/document_loaders/web/puppeteer.cjs +20 -0
  275. package/dist/document_loaders/web/puppeteer.d.ts +25 -0
  276. package/dist/document_loaders/web/puppeteer.js +20 -0
  277. package/dist/document_loaders/web/s3.cjs +9 -0
  278. package/dist/document_loaders/web/s3.d.ts +21 -0
  279. package/dist/document_loaders/web/s3.js +9 -0
  280. package/dist/document_loaders/web/serpapi.cjs +4 -0
  281. package/dist/document_loaders/web/serpapi.d.ts +8 -0
  282. package/dist/document_loaders/web/serpapi.js +4 -0
  283. package/dist/document_loaders/web/sonix_audio.cjs +10 -0
  284. package/dist/document_loaders/web/sonix_audio.d.ts +10 -0
  285. package/dist/document_loaders/web/sonix_audio.js +10 -0
  286. package/dist/document_loaders/web/sort_xyz_blockchain.cjs +10 -0
  287. package/dist/document_loaders/web/sort_xyz_blockchain.d.ts +17 -0
  288. package/dist/document_loaders/web/sort_xyz_blockchain.js +10 -0
  289. package/dist/document_loaders/web/youtube.cjs +23 -0
  290. package/dist/document_loaders/web/youtube.d.ts +27 -0
  291. package/dist/document_loaders/web/youtube.js +23 -0
  292. package/dist/document_transformers/html_to_text.cjs +6 -0
  293. package/dist/document_transformers/html_to_text.d.ts +4 -0
  294. package/dist/document_transformers/html_to_text.js +6 -0
  295. package/dist/document_transformers/mozilla_readability.cjs +7 -0
  296. package/dist/document_transformers/mozilla_readability.d.ts +5 -0
  297. package/dist/document_transformers/mozilla_readability.js +7 -0
  298. package/dist/document_transformers/openai_functions.cjs +6 -0
  299. package/dist/document_transformers/openai_functions.d.ts +4 -0
  300. package/dist/document_transformers/openai_functions.js +6 -0
  301. package/dist/embeddings/base.cjs +4 -0
  302. package/dist/embeddings/base.d.ts +21 -0
  303. package/dist/embeddings/base.js +4 -0
  304. package/dist/embeddings/cache_backed.d.ts +4 -0
  305. package/dist/embeddings/cohere.d.ts +4 -0
  306. package/dist/embeddings/fake.cjs +33 -0
  307. package/dist/embeddings/fake.d.ts +37 -0
  308. package/dist/embeddings/fake.js +33 -0
  309. package/dist/embeddings/googlepalm.cjs +18 -0
  310. package/dist/embeddings/googlepalm.d.ts +22 -0
  311. package/dist/embeddings/googlepalm.js +18 -0
  312. package/dist/embeddings/googlevertexai.cjs +15 -0
  313. package/dist/embeddings/googlevertexai.d.ts +20 -0
  314. package/dist/embeddings/googlevertexai.js +15 -0
  315. package/dist/embeddings/hf.cjs +20 -0
  316. package/dist/embeddings/hf.d.ts +24 -0
  317. package/dist/embeddings/hf.js +20 -0
  318. package/dist/embeddings/openai.cjs +25 -0
  319. package/dist/embeddings/openai.d.ts +29 -0
  320. package/dist/embeddings/openai.js +25 -0
  321. package/dist/embeddings/tensorflow.cjs +27 -0
  322. package/dist/embeddings/tensorflow.d.ts +31 -0
  323. package/dist/embeddings/tensorflow.js +27 -0
  324. package/dist/evaluation/qa/eval_chain.cjs +3 -0
  325. package/dist/evaluation/qa/eval_chain.d.ts +1 -0
  326. package/dist/evaluation/qa/eval_chain.js +3 -0
  327. package/dist/experimental/autogpt/agent.cjs +21 -0
  328. package/dist/experimental/autogpt/agent.d.ts +24 -0
  329. package/dist/experimental/autogpt/agent.js +21 -0
  330. package/dist/experimental/autogpt/output_parser.cjs +24 -0
  331. package/dist/experimental/autogpt/output_parser.d.ts +24 -0
  332. package/dist/experimental/autogpt/output_parser.js +24 -0
  333. package/dist/experimental/autogpt/prompt.cjs +25 -0
  334. package/dist/experimental/autogpt/prompt.d.ts +28 -0
  335. package/dist/experimental/autogpt/prompt.js +25 -0
  336. package/dist/experimental/autogpt/prompt_generator.cjs +32 -0
  337. package/dist/experimental/autogpt/prompt_generator.d.ts +32 -0
  338. package/dist/experimental/autogpt/prompt_generator.js +32 -0
  339. package/dist/experimental/autogpt/schema.d.ts +11 -0
  340. package/dist/experimental/babyagi/agent.cjs +68 -0
  341. package/dist/experimental/babyagi/agent.d.ts +76 -0
  342. package/dist/experimental/babyagi/agent.js +68 -0
  343. package/dist/experimental/babyagi/task_creation.cjs +13 -0
  344. package/dist/experimental/babyagi/task_creation.d.ts +11 -0
  345. package/dist/experimental/babyagi/task_creation.js +13 -0
  346. package/dist/experimental/babyagi/task_execution.cjs +12 -0
  347. package/dist/experimental/babyagi/task_execution.d.ts +10 -0
  348. package/dist/experimental/babyagi/task_execution.js +12 -0
  349. package/dist/experimental/babyagi/task_prioritization.cjs +11 -0
  350. package/dist/experimental/babyagi/task_prioritization.d.ts +9 -0
  351. package/dist/experimental/babyagi/task_prioritization.js +11 -0
  352. package/dist/experimental/generative_agents/generative_agent.cjs +77 -0
  353. package/dist/experimental/generative_agents/generative_agent.d.ts +80 -0
  354. package/dist/experimental/generative_agents/generative_agent.js +77 -0
  355. package/dist/experimental/generative_agents/generative_agent_memory.cjs +116 -0
  356. package/dist/experimental/generative_agents/generative_agent_memory.d.ts +114 -0
  357. package/dist/experimental/generative_agents/generative_agent_memory.js +116 -0
  358. package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +46 -0
  359. package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +58 -0
  360. package/dist/experimental/multimodal_embeddings/googlevertexai.js +46 -0
  361. package/dist/experimental/plan_and_execute/agent_executor.cjs +35 -0
  362. package/dist/experimental/plan_and_execute/agent_executor.d.ts +38 -0
  363. package/dist/experimental/plan_and_execute/agent_executor.js +35 -0
  364. package/dist/experimental/plan_and_execute/base.cjs +26 -0
  365. package/dist/experimental/plan_and_execute/base.d.ts +38 -0
  366. package/dist/experimental/plan_and_execute/base.js +26 -0
  367. package/dist/experimental/plan_and_execute/outputParser.cjs +18 -0
  368. package/dist/experimental/plan_and_execute/outputParser.d.ts +18 -0
  369. package/dist/experimental/plan_and_execute/outputParser.js +18 -0
  370. package/dist/llms/ai21.cjs +13 -0
  371. package/dist/llms/ai21.d.ts +19 -0
  372. package/dist/llms/ai21.js +13 -0
  373. package/dist/llms/aleph_alpha.cjs +10 -0
  374. package/dist/llms/aleph_alpha.d.ts +13 -0
  375. package/dist/llms/aleph_alpha.js +10 -0
  376. package/dist/llms/base.cjs +32 -0
  377. package/dist/llms/base.d.ts +32 -0
  378. package/dist/llms/base.js +32 -0
  379. package/dist/llms/bedrock.cjs +21 -0
  380. package/dist/llms/bedrock.d.ts +9 -0
  381. package/dist/llms/bedrock.js +21 -0
  382. package/dist/llms/cohere.cjs +7 -0
  383. package/dist/llms/cohere.d.ts +8 -0
  384. package/dist/llms/cohere.js +7 -0
  385. package/dist/llms/googlevertexai.cjs +23 -0
  386. package/dist/llms/googlevertexai.d.ts +38 -0
  387. package/dist/llms/googlevertexai.js +23 -0
  388. package/dist/llms/hf.cjs +4 -0
  389. package/dist/llms/hf.d.ts +8 -0
  390. package/dist/llms/hf.js +4 -0
  391. package/dist/llms/ollama.cjs +7 -0
  392. package/dist/llms/ollama.d.ts +5 -0
  393. package/dist/llms/ollama.js +7 -0
  394. package/dist/llms/openai-chat.cjs +35 -4
  395. package/dist/llms/openai-chat.d.ts +28 -4
  396. package/dist/llms/openai-chat.js +35 -4
  397. package/dist/llms/openai.cjs +26 -6
  398. package/dist/llms/openai.d.ts +11 -3
  399. package/dist/llms/openai.js +26 -6
  400. package/dist/llms/replicate.cjs +9 -0
  401. package/dist/llms/replicate.d.ts +12 -0
  402. package/dist/llms/replicate.js +9 -0
  403. package/dist/llms/sagemaker_endpoint.cjs +11 -0
  404. package/dist/llms/sagemaker_endpoint.d.ts +17 -0
  405. package/dist/llms/sagemaker_endpoint.js +11 -0
  406. package/dist/load/index.cjs +7 -1
  407. package/dist/load/index.js +7 -1
  408. package/dist/load/serializable.cjs +42 -3
  409. package/dist/load/serializable.d.ts +16 -0
  410. package/dist/load/serializable.js +40 -2
  411. package/dist/memory/base.cjs +11 -0
  412. package/dist/memory/base.d.ts +40 -0
  413. package/dist/memory/base.js +11 -0
  414. package/dist/memory/buffer_memory.cjs +19 -0
  415. package/dist/memory/buffer_memory.d.ts +22 -0
  416. package/dist/memory/buffer_memory.js +19 -0
  417. package/dist/memory/buffer_window_memory.cjs +15 -0
  418. package/dist/memory/buffer_window_memory.d.ts +18 -0
  419. package/dist/memory/buffer_window_memory.js +15 -0
  420. package/dist/memory/chat_memory.cjs +16 -0
  421. package/dist/memory/chat_memory.d.ts +19 -0
  422. package/dist/memory/chat_memory.js +16 -0
  423. package/dist/memory/combined_memory.cjs +28 -0
  424. package/dist/memory/combined_memory.d.ts +33 -0
  425. package/dist/memory/combined_memory.js +28 -0
  426. package/dist/memory/entity_memory.cjs +21 -0
  427. package/dist/memory/entity_memory.d.ts +24 -0
  428. package/dist/memory/entity_memory.js +21 -0
  429. package/dist/memory/motorhead_memory.cjs +25 -0
  430. package/dist/memory/motorhead_memory.d.ts +29 -0
  431. package/dist/memory/motorhead_memory.js +25 -0
  432. package/dist/memory/stores/entity/in_memory.cjs +29 -0
  433. package/dist/memory/stores/entity/in_memory.d.ts +29 -0
  434. package/dist/memory/stores/entity/in_memory.js +29 -0
  435. package/dist/memory/summary.cjs +31 -0
  436. package/dist/memory/summary.d.ts +39 -0
  437. package/dist/memory/summary.js +31 -0
  438. package/dist/memory/summary_buffer.cjs +33 -0
  439. package/dist/memory/summary_buffer.d.ts +37 -0
  440. package/dist/memory/summary_buffer.js +33 -0
  441. package/dist/memory/vector_store.cjs +22 -0
  442. package/dist/memory/vector_store.d.ts +26 -0
  443. package/dist/memory/vector_store.js +22 -0
  444. package/dist/memory/zep.cjs +22 -0
  445. package/dist/memory/zep.d.ts +27 -0
  446. package/dist/memory/zep.js +22 -0
  447. package/dist/output_parsers/combining.cjs +15 -0
  448. package/dist/output_parsers/combining.d.ts +19 -0
  449. package/dist/output_parsers/combining.js +15 -0
  450. package/dist/output_parsers/expression.cjs +12 -0
  451. package/dist/output_parsers/expression.d.ts +12 -0
  452. package/dist/output_parsers/expression.js +12 -0
  453. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.cjs +18 -0
  454. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.d.ts +18 -0
  455. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.js +18 -0
  456. package/dist/output_parsers/expression_type_handlers/base.cjs +68 -0
  457. package/dist/output_parsers/expression_type_handlers/base.d.ts +79 -0
  458. package/dist/output_parsers/expression_type_handlers/base.js +68 -0
  459. package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.cjs +18 -0
  460. package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.d.ts +18 -0
  461. package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.js +18 -0
  462. package/dist/output_parsers/expression_type_handlers/call_expression_handler.cjs +22 -0
  463. package/dist/output_parsers/expression_type_handlers/call_expression_handler.d.ts +22 -0
  464. package/dist/output_parsers/expression_type_handlers/call_expression_handler.js +22 -0
  465. package/dist/output_parsers/expression_type_handlers/factory.cjs +20 -0
  466. package/dist/output_parsers/expression_type_handlers/factory.d.ts +20 -0
  467. package/dist/output_parsers/expression_type_handlers/factory.js +20 -0
  468. package/dist/output_parsers/expression_type_handlers/identifier_handler.cjs +19 -0
  469. package/dist/output_parsers/expression_type_handlers/identifier_handler.d.ts +19 -0
  470. package/dist/output_parsers/expression_type_handlers/identifier_handler.js +19 -0
  471. package/dist/output_parsers/expression_type_handlers/member_expression_handler.cjs +17 -0
  472. package/dist/output_parsers/expression_type_handlers/member_expression_handler.d.ts +17 -0
  473. package/dist/output_parsers/expression_type_handlers/member_expression_handler.js +17 -0
  474. package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.cjs +16 -0
  475. package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.d.ts +16 -0
  476. package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.js +16 -0
  477. package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.cjs +16 -0
  478. package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.d.ts +16 -0
  479. package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.js +16 -0
  480. package/dist/output_parsers/expression_type_handlers/property_assignment_handler.cjs +17 -0
  481. package/dist/output_parsers/expression_type_handlers/property_assignment_handler.d.ts +17 -0
  482. package/dist/output_parsers/expression_type_handlers/property_assignment_handler.js +17 -0
  483. package/dist/output_parsers/expression_type_handlers/string_literal_handler.cjs +16 -0
  484. package/dist/output_parsers/expression_type_handlers/string_literal_handler.d.ts +16 -0
  485. package/dist/output_parsers/expression_type_handlers/string_literal_handler.js +16 -0
  486. package/dist/output_parsers/expression_type_handlers/types.d.ts +50 -0
  487. package/dist/output_parsers/fix.cjs +28 -0
  488. package/dist/output_parsers/fix.d.ts +26 -0
  489. package/dist/output_parsers/fix.js +28 -0
  490. package/dist/output_parsers/list.cjs +27 -0
  491. package/dist/output_parsers/list.d.ts +25 -0
  492. package/dist/output_parsers/list.js +27 -0
  493. package/dist/output_parsers/noop.cjs +21 -0
  494. package/dist/output_parsers/noop.d.ts +19 -0
  495. package/dist/output_parsers/noop.js +21 -0
  496. package/dist/output_parsers/openai_functions.cjs +40 -0
  497. package/dist/output_parsers/openai_functions.d.ts +37 -0
  498. package/dist/output_parsers/openai_functions.js +40 -0
  499. package/dist/output_parsers/regex.cjs +15 -0
  500. package/dist/output_parsers/regex.d.ts +16 -0
  501. package/dist/output_parsers/regex.js +15 -0
  502. package/dist/output_parsers/router.cjs +15 -0
  503. package/dist/output_parsers/router.d.ts +19 -0
  504. package/dist/output_parsers/router.js +15 -0
  505. package/dist/output_parsers/structured.cjs +36 -0
  506. package/dist/output_parsers/structured.d.ts +38 -0
  507. package/dist/output_parsers/structured.js +36 -0
  508. package/dist/prompts/base.cjs +26 -0
  509. package/dist/prompts/base.d.ts +36 -0
  510. package/dist/prompts/base.js +26 -0
  511. package/dist/prompts/chat.cjs +69 -0
  512. package/dist/prompts/chat.d.ts +76 -0
  513. package/dist/prompts/chat.js +69 -0
  514. package/dist/prompts/few_shot.cjs +5 -0
  515. package/dist/prompts/few_shot.d.ts +5 -0
  516. package/dist/prompts/few_shot.js +5 -0
  517. package/dist/prompts/pipeline.cjs +29 -0
  518. package/dist/prompts/pipeline.d.ts +35 -0
  519. package/dist/prompts/pipeline.js +29 -0
  520. package/dist/prompts/prompt.cjs +13 -0
  521. package/dist/prompts/prompt.d.ts +11 -0
  522. package/dist/prompts/prompt.js +13 -0
  523. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +32 -0
  524. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +33 -0
  525. package/dist/prompts/selectors/LengthBasedExampleSelector.js +32 -0
  526. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +31 -0
  527. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +35 -0
  528. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +31 -0
  529. package/dist/prompts/selectors/conditional.cjs +30 -0
  530. package/dist/prompts/selectors/conditional.d.ts +37 -0
  531. package/dist/prompts/selectors/conditional.js +30 -0
  532. package/dist/prompts/serde.d.ts +24 -0
  533. package/dist/prompts/template.d.ts +17 -0
  534. package/dist/retrievers/amazon_kendra.cjs +65 -0
  535. package/dist/retrievers/amazon_kendra.d.ts +67 -0
  536. package/dist/retrievers/amazon_kendra.js +65 -0
  537. package/dist/retrievers/contextual_compression.cjs +8 -0
  538. package/dist/retrievers/contextual_compression.d.ts +11 -0
  539. package/dist/retrievers/contextual_compression.js +8 -0
  540. package/dist/retrievers/databerry.cjs +8 -0
  541. package/dist/retrievers/databerry.d.ts +10 -0
  542. package/dist/retrievers/databerry.js +8 -0
  543. package/dist/retrievers/document_compressors/chain_extract.cjs +18 -0
  544. package/dist/retrievers/document_compressors/chain_extract.d.ts +22 -0
  545. package/dist/retrievers/document_compressors/chain_extract.js +18 -0
  546. package/dist/retrievers/document_compressors/index.d.ts +9 -0
  547. package/dist/retrievers/hyde.cjs +12 -0
  548. package/dist/retrievers/hyde.d.ts +18 -0
  549. package/dist/retrievers/hyde.js +12 -0
  550. package/dist/retrievers/metal.cjs +10 -0
  551. package/dist/retrievers/metal.d.ts +13 -0
  552. package/dist/retrievers/metal.js +10 -0
  553. package/dist/retrievers/parent_document.cjs +20 -1
  554. package/dist/retrievers/parent_document.d.ts +16 -0
  555. package/dist/retrievers/parent_document.js +20 -1
  556. package/dist/retrievers/remote/base.cjs +4 -0
  557. package/dist/retrievers/remote/base.d.ts +28 -0
  558. package/dist/retrievers/remote/base.js +4 -0
  559. package/dist/retrievers/remote/chatgpt-plugin.cjs +17 -0
  560. package/dist/retrievers/remote/chatgpt-plugin.d.ts +21 -0
  561. package/dist/retrievers/remote/chatgpt-plugin.js +17 -0
  562. package/dist/retrievers/remote/remote-retriever.cjs +20 -0
  563. package/dist/retrievers/remote/remote-retriever.d.ts +20 -0
  564. package/dist/retrievers/remote/remote-retriever.js +20 -0
  565. package/dist/retrievers/self_query/base.cjs +28 -0
  566. package/dist/retrievers/self_query/base.d.ts +45 -0
  567. package/dist/retrievers/self_query/base.js +28 -0
  568. package/dist/retrievers/self_query/chroma.cjs +6 -0
  569. package/dist/retrievers/self_query/chroma.d.ts +6 -0
  570. package/dist/retrievers/self_query/chroma.js +6 -0
  571. package/dist/retrievers/self_query/functional.cjs +40 -0
  572. package/dist/retrievers/self_query/functional.d.ts +49 -0
  573. package/dist/retrievers/self_query/functional.js +40 -0
  574. package/dist/retrievers/self_query/index.cjs +17 -0
  575. package/dist/retrievers/self_query/index.d.ts +19 -0
  576. package/dist/retrievers/self_query/index.js +17 -0
  577. package/dist/retrievers/self_query/pinecone.cjs +7 -0
  578. package/dist/retrievers/self_query/pinecone.d.ts +7 -0
  579. package/dist/retrievers/self_query/pinecone.js +7 -0
  580. package/dist/retrievers/self_query/supabase.cjs +91 -7
  581. package/dist/retrievers/self_query/supabase.d.ts +69 -2
  582. package/dist/retrievers/self_query/supabase.js +92 -8
  583. package/dist/retrievers/self_query/supabase_utils.cjs +255 -0
  584. package/dist/retrievers/self_query/supabase_utils.d.ts +102 -0
  585. package/dist/retrievers/self_query/supabase_utils.js +250 -0
  586. package/dist/retrievers/self_query/utils.cjs +36 -3
  587. package/dist/retrievers/self_query/utils.d.ts +20 -0
  588. package/dist/retrievers/self_query/utils.js +32 -2
  589. package/dist/retrievers/self_query/weaviate.cjs +45 -14
  590. package/dist/retrievers/self_query/weaviate.d.ts +42 -0
  591. package/dist/retrievers/self_query/weaviate.js +43 -12
  592. package/dist/retrievers/supabase.cjs +33 -0
  593. package/dist/retrievers/supabase.d.ts +31 -0
  594. package/dist/retrievers/supabase.js +33 -0
  595. package/dist/retrievers/time_weighted.cjs +11 -0
  596. package/dist/retrievers/time_weighted.d.ts +13 -0
  597. package/dist/retrievers/time_weighted.js +11 -0
  598. package/dist/retrievers/vespa.cjs +21 -0
  599. package/dist/retrievers/vespa.d.ts +19 -0
  600. package/dist/retrievers/vespa.js +21 -0
  601. package/dist/retrievers/zep.cjs +7 -0
  602. package/dist/retrievers/zep.d.ts +9 -0
  603. package/dist/retrievers/zep.js +7 -0
  604. package/dist/schema/document.cjs +7 -0
  605. package/dist/schema/document.d.ts +7 -0
  606. package/dist/schema/document.js +7 -0
  607. package/dist/schema/index.cjs +100 -0
  608. package/dist/schema/index.d.ts +80 -0
  609. package/dist/schema/index.js +100 -0
  610. package/dist/schema/output_parser.cjs +49 -0
  611. package/dist/schema/output_parser.d.ts +53 -0
  612. package/dist/schema/output_parser.js +49 -0
  613. package/dist/schema/query_constructor.cjs +5 -0
  614. package/dist/schema/query_constructor.d.ts +5 -0
  615. package/dist/schema/query_constructor.js +5 -0
  616. package/dist/schema/retriever.cjs +18 -0
  617. package/dist/schema/retriever.d.ts +18 -0
  618. package/dist/schema/retriever.js +18 -0
  619. package/dist/schema/runnable.cjs +25 -7
  620. package/dist/schema/runnable.d.ts +6 -0
  621. package/dist/schema/runnable.js +25 -7
  622. package/dist/schema/storage.d.ts +20 -0
  623. package/dist/storage/encoder_backed.cjs +27 -0
  624. package/dist/storage/encoder_backed.d.ts +27 -0
  625. package/dist/storage/encoder_backed.js +27 -0
  626. package/dist/storage/in_memory.cjs +25 -0
  627. package/dist/storage/in_memory.d.ts +25 -0
  628. package/dist/storage/in_memory.js +25 -0
  629. package/dist/storage/ioredis.cjs +25 -0
  630. package/dist/storage/ioredis.d.ts +25 -0
  631. package/dist/storage/ioredis.js +25 -0
  632. package/dist/stores/doc/gcs.cjs +28 -0
  633. package/dist/stores/doc/gcs.d.ts +33 -0
  634. package/dist/stores/doc/gcs.js +28 -0
  635. package/dist/stores/doc/in_memory.cjs +27 -0
  636. package/dist/stores/doc/in_memory.d.ts +27 -0
  637. package/dist/stores/doc/in_memory.js +27 -0
  638. package/dist/stores/file/in_memory.cjs +20 -0
  639. package/dist/stores/file/in_memory.d.ts +20 -0
  640. package/dist/stores/file/in_memory.js +20 -0
  641. package/dist/stores/file/node.cjs +15 -0
  642. package/dist/stores/file/node.d.ts +15 -0
  643. package/dist/stores/file/node.js +15 -0
  644. package/dist/stores/message/dynamodb.cjs +17 -0
  645. package/dist/stores/message/dynamodb.d.ts +23 -0
  646. package/dist/stores/message/dynamodb.js +17 -0
  647. package/dist/stores/message/firestore.cjs +19 -0
  648. package/dist/stores/message/firestore.d.ts +24 -0
  649. package/dist/stores/message/firestore.js +19 -0
  650. package/dist/stores/message/in_memory.cjs +19 -0
  651. package/dist/stores/message/in_memory.d.ts +19 -0
  652. package/dist/stores/message/in_memory.js +19 -0
  653. package/dist/stores/message/ioredis.cjs +17 -0
  654. package/dist/stores/message/ioredis.d.ts +22 -0
  655. package/dist/stores/message/ioredis.js +17 -0
  656. package/dist/stores/message/momento.cjs +18 -0
  657. package/dist/stores/message/momento.d.ts +18 -0
  658. package/dist/stores/message/momento.js +18 -0
  659. package/dist/stores/message/planetscale.cjs +26 -0
  660. package/dist/stores/message/planetscale.d.ts +30 -0
  661. package/dist/stores/message/planetscale.js +26 -0
  662. package/dist/stores/message/redis.cjs +24 -0
  663. package/dist/stores/message/redis.d.ts +27 -0
  664. package/dist/stores/message/redis.js +24 -0
  665. package/dist/stores/message/upstash_redis.cjs +17 -0
  666. package/dist/stores/message/upstash_redis.d.ts +21 -0
  667. package/dist/stores/message/upstash_redis.js +17 -0
  668. package/dist/stores/message/utils.cjs +21 -0
  669. package/dist/stores/message/utils.d.ts +21 -0
  670. package/dist/stores/message/utils.js +21 -0
  671. package/dist/stores/message/xata.cjs +25 -0
  672. package/dist/stores/message/xata.d.ts +29 -0
  673. package/dist/stores/message/xata.js +25 -0
  674. package/dist/text_splitter.cjs +9 -0
  675. package/dist/text_splitter.d.ts +3 -0
  676. package/dist/text_splitter.js +9 -0
  677. package/dist/tools/IFTTTWebhook.cjs +9 -0
  678. package/dist/tools/IFTTTWebhook.d.ts +7 -0
  679. package/dist/tools/IFTTTWebhook.js +9 -0
  680. package/dist/tools/aiplugin.cjs +15 -0
  681. package/dist/tools/aiplugin.d.ts +17 -0
  682. package/dist/tools/aiplugin.js +15 -0
  683. package/dist/tools/aws_lambda.cjs +9 -0
  684. package/dist/tools/aws_lambda.d.ts +7 -0
  685. package/dist/tools/aws_lambda.js +9 -0
  686. package/dist/tools/aws_sfn.cjs +28 -0
  687. package/dist/tools/aws_sfn.d.ts +22 -0
  688. package/dist/tools/aws_sfn.js +28 -0
  689. package/dist/tools/base.cjs +22 -0
  690. package/dist/tools/base.d.ts +25 -0
  691. package/dist/tools/base.js +22 -0
  692. package/dist/tools/bingserpapi.cjs +13 -0
  693. package/dist/tools/bingserpapi.d.ts +11 -0
  694. package/dist/tools/bingserpapi.js +13 -0
  695. package/dist/tools/brave_search.cjs +9 -0
  696. package/dist/tools/brave_search.d.ts +11 -0
  697. package/dist/tools/brave_search.js +9 -0
  698. package/dist/tools/calculator.cjs +7 -0
  699. package/dist/tools/calculator.d.ts +5 -0
  700. package/dist/tools/calculator.js +7 -0
  701. package/dist/tools/chain.cjs +9 -0
  702. package/dist/tools/chain.d.ts +12 -0
  703. package/dist/tools/chain.js +9 -0
  704. package/dist/tools/convert_to_openai.cjs +6 -0
  705. package/dist/tools/convert_to_openai.d.ts +6 -0
  706. package/dist/tools/convert_to_openai.js +6 -0
  707. package/dist/tools/dadjokeapi.cjs +9 -0
  708. package/dist/tools/dadjokeapi.d.ts +7 -0
  709. package/dist/tools/dadjokeapi.js +9 -0
  710. package/dist/tools/dataforseo_api_search.cjs +3 -0
  711. package/dist/tools/dataforseo_api_search.d.ts +10 -0
  712. package/dist/tools/dataforseo_api_search.js +3 -0
  713. package/dist/tools/dynamic.cjs +12 -0
  714. package/dist/tools/dynamic.d.ts +14 -0
  715. package/dist/tools/dynamic.js +12 -0
  716. package/dist/tools/fs.cjs +14 -0
  717. package/dist/tools/fs.d.ts +16 -0
  718. package/dist/tools/fs.js +14 -0
  719. package/dist/tools/google_custom_search.cjs +8 -0
  720. package/dist/tools/google_custom_search.d.ts +9 -0
  721. package/dist/tools/google_custom_search.js +8 -0
  722. package/dist/tools/json.cjs +29 -1
  723. package/dist/tools/json.d.ts +24 -0
  724. package/dist/tools/json.js +29 -1
  725. package/dist/tools/requests.cjs +19 -2
  726. package/dist/tools/requests.d.ts +17 -0
  727. package/dist/tools/requests.js +19 -2
  728. package/dist/tools/searxng_search.cjs +10 -0
  729. package/dist/tools/searxng_search.d.ts +11 -0
  730. package/dist/tools/searxng_search.js +10 -0
  731. package/dist/tools/serpapi.cjs +10 -0
  732. package/dist/tools/serpapi.d.ts +8 -0
  733. package/dist/tools/serpapi.js +10 -0
  734. package/dist/tools/serper.cjs +8 -0
  735. package/dist/tools/serper.d.ts +10 -0
  736. package/dist/tools/serper.js +8 -0
  737. package/dist/tools/sql.cjs +37 -0
  738. package/dist/tools/sql.d.ts +36 -0
  739. package/dist/tools/sql.js +37 -0
  740. package/dist/tools/vectorstore.cjs +14 -0
  741. package/dist/tools/vectorstore.d.ts +15 -0
  742. package/dist/tools/vectorstore.js +14 -0
  743. package/dist/tools/webbrowser.cjs +9 -0
  744. package/dist/tools/webbrowser.d.ts +13 -0
  745. package/dist/tools/webbrowser.js +9 -0
  746. package/dist/tools/wikipedia_query_run.cjs +19 -0
  747. package/dist/tools/wikipedia_query_run.d.ts +25 -0
  748. package/dist/tools/wikipedia_query_run.js +19 -0
  749. package/dist/tools/zapier.cjs +15 -0
  750. package/dist/tools/zapier.d.ts +13 -0
  751. package/dist/tools/zapier.js +15 -0
  752. package/dist/vectorstores/analyticdb.cjs +76 -0
  753. package/dist/vectorstores/analyticdb.d.ts +80 -0
  754. package/dist/vectorstores/analyticdb.js +76 -0
  755. package/dist/vectorstores/base.cjs +16 -0
  756. package/dist/vectorstores/base.d.ts +27 -0
  757. package/dist/vectorstores/base.js +16 -0
  758. package/dist/vectorstores/chroma.cjs +73 -0
  759. package/dist/vectorstores/chroma.d.ts +84 -0
  760. package/dist/vectorstores/chroma.js +73 -0
  761. package/dist/vectorstores/elasticsearch.cjs +74 -0
  762. package/dist/vectorstores/elasticsearch.d.ts +90 -0
  763. package/dist/vectorstores/elasticsearch.js +74 -0
  764. package/dist/vectorstores/faiss.cjs +65 -0
  765. package/dist/vectorstores/faiss.d.ts +69 -0
  766. package/dist/vectorstores/faiss.js +65 -0
  767. package/dist/vectorstores/hnswlib.cjs +71 -0
  768. package/dist/vectorstores/hnswlib.d.ts +80 -0
  769. package/dist/vectorstores/hnswlib.js +71 -0
  770. package/dist/vectorstores/lancedb.cjs +38 -0
  771. package/dist/vectorstores/lancedb.d.ts +42 -0
  772. package/dist/vectorstores/lancedb.js +38 -0
  773. package/dist/vectorstores/memory.cjs +56 -0
  774. package/dist/vectorstores/memory.d.ts +66 -0
  775. package/dist/vectorstores/memory.js +56 -0
  776. package/dist/vectorstores/milvus.cjs +91 -7
  777. package/dist/vectorstores/milvus.d.ts +80 -1
  778. package/dist/vectorstores/milvus.js +91 -7
  779. package/dist/vectorstores/mongo.cjs +45 -0
  780. package/dist/vectorstores/mongo.d.ts +49 -0
  781. package/dist/vectorstores/mongo.js +45 -0
  782. package/dist/vectorstores/mongodb_atlas.cjs +48 -0
  783. package/dist/vectorstores/mongodb_atlas.d.ts +59 -0
  784. package/dist/vectorstores/mongodb_atlas.js +48 -0
  785. package/dist/vectorstores/myscale.cjs +66 -0
  786. package/dist/vectorstores/myscale.d.ts +80 -0
  787. package/dist/vectorstores/myscale.js +66 -0
  788. package/dist/vectorstores/opensearch.cjs +60 -0
  789. package/dist/vectorstores/opensearch.d.ts +74 -0
  790. package/dist/vectorstores/opensearch.js +60 -0
  791. package/dist/vectorstores/pinecone.cjs +54 -0
  792. package/dist/vectorstores/pinecone.d.ts +58 -0
  793. package/dist/vectorstores/pinecone.js +54 -0
  794. package/dist/vectorstores/prisma.cjs +66 -0
  795. package/dist/vectorstores/prisma.d.ts +66 -0
  796. package/dist/vectorstores/prisma.js +66 -0
  797. package/dist/vectorstores/qdrant.cjs +60 -0
  798. package/dist/vectorstores/qdrant.d.ts +66 -0
  799. package/dist/vectorstores/qdrant.js +60 -0
  800. package/dist/vectorstores/redis.cjs +62 -0
  801. package/dist/vectorstores/redis.d.ts +88 -0
  802. package/dist/vectorstores/redis.js +62 -0
  803. package/dist/vectorstores/singlestore.cjs +46 -0
  804. package/dist/vectorstores/singlestore.d.ts +46 -0
  805. package/dist/vectorstores/singlestore.js +46 -0
  806. package/dist/vectorstores/supabase.cjs +50 -0
  807. package/dist/vectorstores/supabase.d.ts +54 -2
  808. package/dist/vectorstores/supabase.js +50 -0
  809. package/dist/vectorstores/tigris.cjs +49 -0
  810. package/dist/vectorstores/tigris.d.ts +53 -0
  811. package/dist/vectorstores/tigris.js +49 -0
  812. package/dist/vectorstores/typeorm.cjs +71 -0
  813. package/dist/vectorstores/typeorm.d.ts +76 -0
  814. package/dist/vectorstores/typeorm.js +71 -0
  815. package/dist/vectorstores/typesense.cjs +5 -0
  816. package/dist/vectorstores/typesense.d.ts +5 -0
  817. package/dist/vectorstores/typesense.js +5 -0
  818. package/dist/vectorstores/usearch.cjs +50 -0
  819. package/dist/vectorstores/usearch.d.ts +55 -0
  820. package/dist/vectorstores/usearch.js +50 -0
  821. package/dist/vectorstores/vectara.cjs +104 -0
  822. package/dist/vectorstores/vectara.d.ts +72 -0
  823. package/dist/vectorstores/vectara.js +104 -0
  824. package/dist/vectorstores/weaviate.cjs +61 -0
  825. package/dist/vectorstores/weaviate.d.ts +70 -0
  826. package/dist/vectorstores/weaviate.js +61 -0
  827. package/dist/vectorstores/xata.cjs +36 -0
  828. package/dist/vectorstores/xata.d.ts +43 -0
  829. package/dist/vectorstores/xata.js +36 -0
  830. package/dist/vectorstores/zep.d.ts +11 -0
  831. package/package.json +2 -2
@@ -4,7 +4,15 @@ exports.GenerativeAgent = void 0;
4
4
  const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
5
5
  const index_js_1 = require("../../prompts/index.cjs");
6
6
  const base_js_1 = require("../../chains/base.cjs");
7
+ /**
8
+ * Implementation of a generative agent that can learn and form new memories over
9
+ * time. It extends the BaseChain class, which is a generic
10
+ * sequence of calls to components, including other chains.
11
+ */
7
12
  class GenerativeAgent extends base_js_1.BaseChain {
13
+ static lc_name() {
14
+ return "GenerativeAgent";
15
+ }
8
16
  // TODO: Add support for daily summaries
9
17
  // private dailySummaries: string[] = []; // summary of the events in the plan that the agent took.
10
18
  _chainType() {
@@ -93,12 +101,23 @@ class GenerativeAgent extends base_js_1.BaseChain {
93
101
  // this.dailySummaries = config.dailySummaries ?? this.dailySummaries;
94
102
  }
95
103
  // LLM methods
104
+ /**
105
+ * Parses a newline-separated string into a list of strings.
106
+ * @param text The string to parse.
107
+ * @returns An array of strings parsed from the input text.
108
+ */
96
109
  parseList(text) {
97
110
  // parse a newline-seperated string into a list of strings
98
111
  const lines = text.trim().split("\n");
99
112
  const result = lines.map((line) => line.replace(/^\s*\d+\.\s*/, "").trim());
100
113
  return result;
101
114
  }
115
+ /**
116
+ * Creates a new LLMChain with the given prompt and the agent's language
117
+ * model, verbosity, output key, and memory.
118
+ * @param prompt The prompt to use for the LLMChain.
119
+ * @returns A new LLMChain instance.
120
+ */
102
121
  chain(prompt) {
103
122
  const chain = new llm_chain_js_1.LLMChain({
104
123
  llm: this.llm,
@@ -109,6 +128,12 @@ class GenerativeAgent extends base_js_1.BaseChain {
109
128
  });
110
129
  return chain;
111
130
  }
131
+ /**
132
+ * Extracts the observed entity from the given observation.
133
+ * @param observation The observation to extract the entity from.
134
+ * @param runManager Optional CallbackManagerForChainRun instance.
135
+ * @returns The extracted entity as a string.
136
+ */
112
137
  async getEntityFromObservations(observation, runManager) {
113
138
  const prompt = index_js_1.PromptTemplate.fromTemplate("What is the observed entity in the following observation? {observation}" +
114
139
  "\nEntity=");
@@ -117,6 +142,13 @@ class GenerativeAgent extends base_js_1.BaseChain {
117
142
  }, runManager?.getChild("entity_extractor"));
118
143
  return result.output;
119
144
  }
145
+ /**
146
+ * Extracts the action of the given entity from the given observation.
147
+ * @param observation The observation to extract the action from.
148
+ * @param entityName The name of the entity to extract the action for.
149
+ * @param runManager Optional CallbackManagerForChainRun instance.
150
+ * @returns The extracted action as a string.
151
+ */
120
152
  async getEntityAction(observation, entityName, runManager) {
121
153
  const prompt = index_js_1.PromptTemplate.fromTemplate("What is the {entity} doing in the following observation? {observation}" +
122
154
  "\nThe {entity} is");
@@ -127,6 +159,12 @@ class GenerativeAgent extends base_js_1.BaseChain {
127
159
  const trimmedResult = result.output.trim();
128
160
  return trimmedResult;
129
161
  }
162
+ /**
163
+ * Summarizes memories that are most relevant to an observation.
164
+ * @param observation The observation to summarize related memories for.
165
+ * @param runManager Optional CallbackManagerForChainRun instance.
166
+ * @returns The summarized memories as a string.
167
+ */
130
168
  async summarizeRelatedMemories(observation, runManager) {
131
169
  // summarize memories that are most relevant to an observation
132
170
  const prompt = index_js_1.PromptTemplate.fromTemplate(`
@@ -209,6 +247,12 @@ Relevant context:`);
209
247
  const regex = new RegExp(`^${this.name} `);
210
248
  return text.replace(regex, "").trim();
211
249
  }
250
+ /**
251
+ * Generates a reaction to the given observation.
252
+ * @param observation The observation to generate a reaction for.
253
+ * @param now Optional current date.
254
+ * @returns A boolean indicating whether to continue the dialogue and the output string.
255
+ */
212
256
  async generateReaction(observation, now) {
213
257
  const callToActionTemplate = `Should {agent_name} react to the observation, and if so,` +
214
258
  ` what would be an appropriate reaction? Respond in one line.` +
@@ -222,6 +266,12 @@ Relevant context:`);
222
266
  });
223
267
  return [continue_dialogue, output];
224
268
  }
269
+ /**
270
+ * Generates a dialogue response to the given observation.
271
+ * @param observation The observation to generate a dialogue response for.
272
+ * @param now Optional current date.
273
+ * @returns A boolean indicating whether to continue the dialogue and the output string.
274
+ */
225
275
  async generateDialogueResponse(observation, now) {
226
276
  const callToActionTemplate = `What would ${this.name} say? To end the conversation, write: GOODBYE: "what to say". Otherwise to continue the conversation, write: SAY: "what to say next"\n\n`;
227
277
  const { output, continue_dialogue } = await this.call({
@@ -235,6 +285,14 @@ Relevant context:`);
235
285
  // Each dialog or response prompt includes a header
236
286
  // summarizing the agent's self-description. This is
237
287
  // updated periodically through probing it's memories
288
+ /**
289
+ * Gets the agent's summary, which includes the agent's name, age, traits,
290
+ * and a summary of the agent's core characteristics. The summary is
291
+ * updated periodically through probing the agent's memories.
292
+ * @param config Optional configuration object with current date and a boolean to force refresh.
293
+ * @param runManager Optional CallbackManagerForChainRun instance.
294
+ * @returns The agent's summary as a string.
295
+ */
238
296
  async getSummary(config, runManager) {
239
297
  const { now = new Date(), forceRefresh = false } = config ?? {};
240
298
  const sinceRefresh = Math.floor((now.getTime() - this.lastRefreshed.getTime()) / 1000);
@@ -255,6 +313,12 @@ Relevant context:`);
255
313
  Innate traits: ${this.traits}
256
314
  ${this.summary}`;
257
315
  }
316
+ /**
317
+ * Computes the agent's summary by summarizing the agent's core
318
+ * characteristics given the agent's relevant memories.
319
+ * @param runManager Optional CallbackManagerForChainRun instance.
320
+ * @returns The computed summary as a string.
321
+ */
258
322
  async computeAgentSummary(runManager) {
259
323
  const prompt = index_js_1.PromptTemplate.fromTemplate("How would you summarize {name}'s core characteristics given the following statements:\n" +
260
324
  "----------" +
@@ -269,6 +333,11 @@ ${this.summary}`;
269
333
  }, runManager?.getChild("compute_agent_summary"));
270
334
  return result.output.trim();
271
335
  }
336
+ /**
337
+ * Returns a full header of the agent's status, summary, and current time.
338
+ * @param config Optional configuration object with current date and a boolean to force refresh.
339
+ * @returns The full header as a string.
340
+ */
272
341
  getFullHeader(config = {}) {
273
342
  const { now = new Date(), forceRefresh = false } = config;
274
343
  // return a full header of the agent's status, summary, and current time.
@@ -283,6 +352,14 @@ ${this.summary}`;
283
352
  });
284
353
  return `${summary}\nIt is ${currentTimeString}.\n${this.name}'s status: ${this.status}`;
285
354
  }
355
+ /**
356
+ * Adds a memory to the agent's long-term memory.
357
+ * @param memoryContent The content of the memory to add.
358
+ * @param now Optional current date.
359
+ * @param metadata Optional metadata for the memory.
360
+ * @param callbacks Optional Callbacks instance.
361
+ * @returns The result of adding the memory to the agent's long-term memory.
362
+ */
286
363
  async addMemory(memoryContent, now, metadata, callbacks) {
287
364
  return this.longTermMemory.addMemory(memoryContent, now, metadata, callbacks);
288
365
  }
@@ -5,6 +5,11 @@ import { GenerativeAgentMemory } from "./generative_agent_memory.js";
5
5
  import { ChainValues } from "../../schema/index.js";
6
6
  import { BaseChain } from "../../chains/base.js";
7
7
  import { CallbackManagerForChainRun, Callbacks } from "../../callbacks/manager.js";
8
+ /**
9
+ * Configuration for the GenerativeAgent class. Defines the character's
10
+ * name, optional age, permanent traits, status, verbosity, and summary
11
+ * refresh seconds.
12
+ */
8
13
  export type GenerativeAgentConfig = {
9
14
  name: string;
10
15
  age?: number;
@@ -13,7 +18,13 @@ export type GenerativeAgentConfig = {
13
18
  verbose?: boolean;
14
19
  summaryRefreshSeconds?: number;
15
20
  };
21
+ /**
22
+ * Implementation of a generative agent that can learn and form new memories over
23
+ * time. It extends the BaseChain class, which is a generic
24
+ * sequence of calls to components, including other chains.
25
+ */
16
26
  export declare class GenerativeAgent extends BaseChain {
27
+ static lc_name(): string;
17
28
  name: string;
18
29
  age?: number;
19
30
  traits: string;
@@ -28,23 +39,92 @@ export declare class GenerativeAgent extends BaseChain {
28
39
  get inputKeys(): string[];
29
40
  get outputKeys(): string[];
30
41
  constructor(llm: BaseLanguageModel, longTermMemory: GenerativeAgentMemory, config: GenerativeAgentConfig);
42
+ /**
43
+ * Parses a newline-separated string into a list of strings.
44
+ * @param text The string to parse.
45
+ * @returns An array of strings parsed from the input text.
46
+ */
31
47
  parseList(text: string): string[];
48
+ /**
49
+ * Creates a new LLMChain with the given prompt and the agent's language
50
+ * model, verbosity, output key, and memory.
51
+ * @param prompt The prompt to use for the LLMChain.
52
+ * @returns A new LLMChain instance.
53
+ */
32
54
  chain(prompt: PromptTemplate): LLMChain;
55
+ /**
56
+ * Extracts the observed entity from the given observation.
57
+ * @param observation The observation to extract the entity from.
58
+ * @param runManager Optional CallbackManagerForChainRun instance.
59
+ * @returns The extracted entity as a string.
60
+ */
33
61
  getEntityFromObservations(observation: string, runManager?: CallbackManagerForChainRun): Promise<string>;
62
+ /**
63
+ * Extracts the action of the given entity from the given observation.
64
+ * @param observation The observation to extract the action from.
65
+ * @param entityName The name of the entity to extract the action for.
66
+ * @param runManager Optional CallbackManagerForChainRun instance.
67
+ * @returns The extracted action as a string.
68
+ */
34
69
  getEntityAction(observation: string, entityName: string, runManager?: CallbackManagerForChainRun): Promise<string>;
70
+ /**
71
+ * Summarizes memories that are most relevant to an observation.
72
+ * @param observation The observation to summarize related memories for.
73
+ * @param runManager Optional CallbackManagerForChainRun instance.
74
+ * @returns The summarized memories as a string.
75
+ */
35
76
  summarizeRelatedMemories(observation: string, runManager?: CallbackManagerForChainRun): Promise<string>;
36
77
  _call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
37
78
  private _cleanResponse;
79
+ /**
80
+ * Generates a reaction to the given observation.
81
+ * @param observation The observation to generate a reaction for.
82
+ * @param now Optional current date.
83
+ * @returns A boolean indicating whether to continue the dialogue and the output string.
84
+ */
38
85
  generateReaction(observation: string, now?: Date): Promise<[boolean, string]>;
86
+ /**
87
+ * Generates a dialogue response to the given observation.
88
+ * @param observation The observation to generate a dialogue response for.
89
+ * @param now Optional current date.
90
+ * @returns A boolean indicating whether to continue the dialogue and the output string.
91
+ */
39
92
  generateDialogueResponse(observation: string, now?: Date): Promise<[boolean, string]>;
93
+ /**
94
+ * Gets the agent's summary, which includes the agent's name, age, traits,
95
+ * and a summary of the agent's core characteristics. The summary is
96
+ * updated periodically through probing the agent's memories.
97
+ * @param config Optional configuration object with current date and a boolean to force refresh.
98
+ * @param runManager Optional CallbackManagerForChainRun instance.
99
+ * @returns The agent's summary as a string.
100
+ */
40
101
  getSummary(config?: {
41
102
  now?: Date;
42
103
  forceRefresh?: boolean;
43
104
  }, runManager?: CallbackManagerForChainRun): Promise<string>;
105
+ /**
106
+ * Computes the agent's summary by summarizing the agent's core
107
+ * characteristics given the agent's relevant memories.
108
+ * @param runManager Optional CallbackManagerForChainRun instance.
109
+ * @returns The computed summary as a string.
110
+ */
44
111
  computeAgentSummary(runManager?: CallbackManagerForChainRun): Promise<string>;
112
+ /**
113
+ * Returns a full header of the agent's status, summary, and current time.
114
+ * @param config Optional configuration object with current date and a boolean to force refresh.
115
+ * @returns The full header as a string.
116
+ */
45
117
  getFullHeader(config?: {
46
118
  now?: Date;
47
119
  forceRefresh?: boolean;
48
120
  }): string;
121
+ /**
122
+ * Adds a memory to the agent's long-term memory.
123
+ * @param memoryContent The content of the memory to add.
124
+ * @param now Optional current date.
125
+ * @param metadata Optional metadata for the memory.
126
+ * @param callbacks Optional Callbacks instance.
127
+ * @returns The result of adding the memory to the agent's long-term memory.
128
+ */
49
129
  addMemory(memoryContent: string, now?: Date, metadata?: Record<string, unknown>, callbacks?: Callbacks): Promise<ChainValues>;
50
130
  }
@@ -1,7 +1,15 @@
1
1
  import { LLMChain } from "../../chains/llm_chain.js";
2
2
  import { PromptTemplate } from "../../prompts/index.js";
3
3
  import { BaseChain } from "../../chains/base.js";
4
+ /**
5
+ * Implementation of a generative agent that can learn and form new memories over
6
+ * time. It extends the BaseChain class, which is a generic
7
+ * sequence of calls to components, including other chains.
8
+ */
4
9
  export class GenerativeAgent extends BaseChain {
10
+ static lc_name() {
11
+ return "GenerativeAgent";
12
+ }
5
13
  // TODO: Add support for daily summaries
6
14
  // private dailySummaries: string[] = []; // summary of the events in the plan that the agent took.
7
15
  _chainType() {
@@ -90,12 +98,23 @@ export class GenerativeAgent extends BaseChain {
90
98
  // this.dailySummaries = config.dailySummaries ?? this.dailySummaries;
91
99
  }
92
100
  // LLM methods
101
+ /**
102
+ * Parses a newline-separated string into a list of strings.
103
+ * @param text The string to parse.
104
+ * @returns An array of strings parsed from the input text.
105
+ */
93
106
  parseList(text) {
94
107
  // parse a newline-seperated string into a list of strings
95
108
  const lines = text.trim().split("\n");
96
109
  const result = lines.map((line) => line.replace(/^\s*\d+\.\s*/, "").trim());
97
110
  return result;
98
111
  }
112
+ /**
113
+ * Creates a new LLMChain with the given prompt and the agent's language
114
+ * model, verbosity, output key, and memory.
115
+ * @param prompt The prompt to use for the LLMChain.
116
+ * @returns A new LLMChain instance.
117
+ */
99
118
  chain(prompt) {
100
119
  const chain = new LLMChain({
101
120
  llm: this.llm,
@@ -106,6 +125,12 @@ export class GenerativeAgent extends BaseChain {
106
125
  });
107
126
  return chain;
108
127
  }
128
+ /**
129
+ * Extracts the observed entity from the given observation.
130
+ * @param observation The observation to extract the entity from.
131
+ * @param runManager Optional CallbackManagerForChainRun instance.
132
+ * @returns The extracted entity as a string.
133
+ */
109
134
  async getEntityFromObservations(observation, runManager) {
110
135
  const prompt = PromptTemplate.fromTemplate("What is the observed entity in the following observation? {observation}" +
111
136
  "\nEntity=");
@@ -114,6 +139,13 @@ export class GenerativeAgent extends BaseChain {
114
139
  }, runManager?.getChild("entity_extractor"));
115
140
  return result.output;
116
141
  }
142
+ /**
143
+ * Extracts the action of the given entity from the given observation.
144
+ * @param observation The observation to extract the action from.
145
+ * @param entityName The name of the entity to extract the action for.
146
+ * @param runManager Optional CallbackManagerForChainRun instance.
147
+ * @returns The extracted action as a string.
148
+ */
117
149
  async getEntityAction(observation, entityName, runManager) {
118
150
  const prompt = PromptTemplate.fromTemplate("What is the {entity} doing in the following observation? {observation}" +
119
151
  "\nThe {entity} is");
@@ -124,6 +156,12 @@ export class GenerativeAgent extends BaseChain {
124
156
  const trimmedResult = result.output.trim();
125
157
  return trimmedResult;
126
158
  }
159
+ /**
160
+ * Summarizes memories that are most relevant to an observation.
161
+ * @param observation The observation to summarize related memories for.
162
+ * @param runManager Optional CallbackManagerForChainRun instance.
163
+ * @returns The summarized memories as a string.
164
+ */
127
165
  async summarizeRelatedMemories(observation, runManager) {
128
166
  // summarize memories that are most relevant to an observation
129
167
  const prompt = PromptTemplate.fromTemplate(`
@@ -206,6 +244,12 @@ Relevant context:`);
206
244
  const regex = new RegExp(`^${this.name} `);
207
245
  return text.replace(regex, "").trim();
208
246
  }
247
+ /**
248
+ * Generates a reaction to the given observation.
249
+ * @param observation The observation to generate a reaction for.
250
+ * @param now Optional current date.
251
+ * @returns A boolean indicating whether to continue the dialogue and the output string.
252
+ */
209
253
  async generateReaction(observation, now) {
210
254
  const callToActionTemplate = `Should {agent_name} react to the observation, and if so,` +
211
255
  ` what would be an appropriate reaction? Respond in one line.` +
@@ -219,6 +263,12 @@ Relevant context:`);
219
263
  });
220
264
  return [continue_dialogue, output];
221
265
  }
266
+ /**
267
+ * Generates a dialogue response to the given observation.
268
+ * @param observation The observation to generate a dialogue response for.
269
+ * @param now Optional current date.
270
+ * @returns A boolean indicating whether to continue the dialogue and the output string.
271
+ */
222
272
  async generateDialogueResponse(observation, now) {
223
273
  const callToActionTemplate = `What would ${this.name} say? To end the conversation, write: GOODBYE: "what to say". Otherwise to continue the conversation, write: SAY: "what to say next"\n\n`;
224
274
  const { output, continue_dialogue } = await this.call({
@@ -232,6 +282,14 @@ Relevant context:`);
232
282
  // Each dialog or response prompt includes a header
233
283
  // summarizing the agent's self-description. This is
234
284
  // updated periodically through probing it's memories
285
+ /**
286
+ * Gets the agent's summary, which includes the agent's name, age, traits,
287
+ * and a summary of the agent's core characteristics. The summary is
288
+ * updated periodically through probing the agent's memories.
289
+ * @param config Optional configuration object with current date and a boolean to force refresh.
290
+ * @param runManager Optional CallbackManagerForChainRun instance.
291
+ * @returns The agent's summary as a string.
292
+ */
235
293
  async getSummary(config, runManager) {
236
294
  const { now = new Date(), forceRefresh = false } = config ?? {};
237
295
  const sinceRefresh = Math.floor((now.getTime() - this.lastRefreshed.getTime()) / 1000);
@@ -252,6 +310,12 @@ Relevant context:`);
252
310
  Innate traits: ${this.traits}
253
311
  ${this.summary}`;
254
312
  }
313
+ /**
314
+ * Computes the agent's summary by summarizing the agent's core
315
+ * characteristics given the agent's relevant memories.
316
+ * @param runManager Optional CallbackManagerForChainRun instance.
317
+ * @returns The computed summary as a string.
318
+ */
255
319
  async computeAgentSummary(runManager) {
256
320
  const prompt = PromptTemplate.fromTemplate("How would you summarize {name}'s core characteristics given the following statements:\n" +
257
321
  "----------" +
@@ -266,6 +330,11 @@ ${this.summary}`;
266
330
  }, runManager?.getChild("compute_agent_summary"));
267
331
  return result.output.trim();
268
332
  }
333
+ /**
334
+ * Returns a full header of the agent's status, summary, and current time.
335
+ * @param config Optional configuration object with current date and a boolean to force refresh.
336
+ * @returns The full header as a string.
337
+ */
269
338
  getFullHeader(config = {}) {
270
339
  const { now = new Date(), forceRefresh = false } = config;
271
340
  // return a full header of the agent's status, summary, and current time.
@@ -280,6 +349,14 @@ ${this.summary}`;
280
349
  });
281
350
  return `${summary}\nIt is ${currentTimeString}.\n${this.name}'s status: ${this.status}`;
282
351
  }
352
+ /**
353
+ * Adds a memory to the agent's long-term memory.
354
+ * @param memoryContent The content of the memory to add.
355
+ * @param now Optional current date.
356
+ * @param metadata Optional metadata for the memory.
357
+ * @param callbacks Optional Callbacks instance.
358
+ * @returns The result of adding the memory to the agent's long-term memory.
359
+ */
283
360
  async addMemory(memoryContent, now, metadata, callbacks) {
284
361
  return this.longTermMemory.addMemory(memoryContent, now, metadata, callbacks);
285
362
  }
@@ -6,7 +6,17 @@ const index_js_1 = require("../../prompts/index.cjs");
6
6
  const base_js_1 = require("../../chains/base.cjs");
7
7
  const document_js_1 = require("../../document.cjs");
8
8
  const base_js_2 = require("../../memory/base.cjs");
9
+ /**
10
+ * Class that manages the memory of a generative agent in LangChain. It
11
+ * extends the `BaseChain` class and has methods for adding observations
12
+ * or memories to the agent's memory, scoring the importance of a memory,
13
+ * reflecting on recent events to add synthesized memories, and generating
14
+ * insights on a topic of reflection based on pertinent memories.
15
+ */
9
16
  class GenerativeAgentMemoryChain extends base_js_1.BaseChain {
17
+ static lc_name() {
18
+ return "GenerativeAgentMemoryChain";
19
+ }
10
20
  constructor(llm, memoryRetriever, config) {
11
21
  super();
12
22
  Object.defineProperty(this, "reflecting", {
@@ -66,6 +76,11 @@ class GenerativeAgentMemoryChain extends base_js_1.BaseChain {
66
76
  get outputKeys() {
67
77
  return ["output"];
68
78
  }
79
+ /**
80
+ * Method that creates a new LLMChain with the given prompt.
81
+ * @param prompt The PromptTemplate to use for the new LLMChain.
82
+ * @returns A new LLMChain instance.
83
+ */
69
84
  chain(prompt) {
70
85
  const chain = new llm_chain_js_1.LLMChain({
71
86
  llm: this.llm,
@@ -102,6 +117,13 @@ class GenerativeAgentMemoryChain extends base_js_1.BaseChain {
102
117
  }
103
118
  return { output: importanceScore };
104
119
  }
120
+ /**
121
+ * Method that pauses the agent to reflect on recent events and generate
122
+ * new insights.
123
+ * @param now The current date.
124
+ * @param runManager The CallbackManagerForChainRun to use for the reflection.
125
+ * @returns An array of new insights as strings.
126
+ */
105
127
  async pauseToReflect(now, runManager) {
106
128
  if (this.verbose) {
107
129
  console.log("Pausing to reflect...");
@@ -124,6 +146,12 @@ class GenerativeAgentMemoryChain extends base_js_1.BaseChain {
124
146
  }
125
147
  return newInsights;
126
148
  }
149
+ /**
150
+ * Method that scores the importance of a given memory.
151
+ * @param memoryContent The content of the memory to score.
152
+ * @param runManager The CallbackManagerForChainRun to use for scoring.
153
+ * @returns The importance score of the memory as a number.
154
+ */
127
155
  async scoreMemoryImportance(memoryContent, runManager) {
128
156
  // score the absolute importance of a given memory
129
157
  const prompt = index_js_1.PromptTemplate.fromTemplate("On the scale of 1 to 10, where 1 is purely mundane" +
@@ -148,6 +176,13 @@ class GenerativeAgentMemoryChain extends base_js_1.BaseChain {
148
176
  return 0.0;
149
177
  }
150
178
  }
179
+ /**
180
+ * Method that retrieves the topics of reflection based on the last K
181
+ * memories.
182
+ * @param lastK The number of most recent memories to consider for generating topics.
183
+ * @param runManager The CallbackManagerForChainRun to use for retrieving topics.
184
+ * @returns An array of topics of reflection as strings.
185
+ */
151
186
  async getTopicsOfReflection(lastK, runManager) {
152
187
  const prompt = index_js_1.PromptTemplate.fromTemplate("{observations}\n\n" +
153
188
  "Given only the information above, what are the 3 most salient" +
@@ -160,6 +195,14 @@ class GenerativeAgentMemoryChain extends base_js_1.BaseChain {
160
195
  const result = await this.chain(prompt).run(observationStr, runManager?.getChild("reflection_topics"));
161
196
  return GenerativeAgentMemoryChain.parseList(result);
162
197
  }
198
+ /**
199
+ * Method that generates insights on a given topic of reflection based on
200
+ * pertinent memories.
201
+ * @param topic The topic of reflection.
202
+ * @param now The current date.
203
+ * @param runManager The CallbackManagerForChainRun to use for generating insights.
204
+ * @returns An array of insights as strings.
205
+ */
163
206
  async getInsightsOnTopic(topic, now, runManager) {
164
207
  // generate insights on a topic of reflection, based on pertinent memories
165
208
  const prompt = index_js_1.PromptTemplate.fromTemplate("Statements about {topic}\n" +
@@ -176,15 +219,34 @@ class GenerativeAgentMemoryChain extends base_js_1.BaseChain {
176
219
  }, runManager?.getChild("reflection_insights"));
177
220
  return GenerativeAgentMemoryChain.parseList(result.output); // added output
178
221
  }
222
+ /**
223
+ * Method that parses a newline-separated string into a list of strings.
224
+ * @param text The newline-separated string to parse.
225
+ * @returns An array of strings.
226
+ */
179
227
  static parseList(text) {
180
228
  // parse a newine seperates string into a list of strings
181
229
  return text.split("\n").map((s) => s.trim());
182
230
  }
183
231
  // TODO: Mock "now" to simulate different times
232
+ /**
233
+ * Method that fetches memories related to a given observation.
234
+ * @param observation The observation to fetch memories for.
235
+ * @param _now The current date.
236
+ * @param runManager The CallbackManagerForChainRun to use for fetching memories.
237
+ * @returns An array of Document instances representing the fetched memories.
238
+ */
184
239
  async fetchMemories(observation, _now, runManager) {
185
240
  return this.memoryRetriever.getRelevantDocuments(observation, runManager?.getChild("memory_retriever"));
186
241
  }
187
242
  }
243
+ /**
244
+ * Class that manages the memory of a generative agent in LangChain. It
245
+ * extends the `BaseMemory` class and has methods for adding a memory,
246
+ * formatting memories, getting memories until a token limit is reached,
247
+ * loading memory variables, saving the context of a model run to memory,
248
+ * and clearing memory contents.
249
+ */
188
250
  class GenerativeAgentMemory extends base_js_2.BaseMemory {
189
251
  constructor(llm, memoryRetriever, config) {
190
252
  super();
@@ -277,15 +339,31 @@ class GenerativeAgentMemory extends base_js_2.BaseMemory {
277
339
  importanceWeight: config?.importanceWeight,
278
340
  });
279
341
  }
342
+ /**
343
+ * Method that returns the key for relevant memories.
344
+ * @returns The key for relevant memories as a string.
345
+ */
280
346
  getRelevantMemoriesKey() {
281
347
  return this.relevantMemoriesKey;
282
348
  }
349
+ /**
350
+ * Method that returns the key for the most recent memories token.
351
+ * @returns The key for the most recent memories token as a string.
352
+ */
283
353
  getMostRecentMemoriesTokenKey() {
284
354
  return this.mostRecentMemoriesTokenKey;
285
355
  }
356
+ /**
357
+ * Method that returns the key for adding a memory.
358
+ * @returns The key for adding a memory as a string.
359
+ */
286
360
  getAddMemoryKey() {
287
361
  return this.addMemoryKey;
288
362
  }
363
+ /**
364
+ * Method that returns the key for the current time.
365
+ * @returns The key for the current time as a string.
366
+ */
289
367
  getCurrentTimeKey() {
290
368
  return this.nowKey;
291
369
  }
@@ -293,9 +371,22 @@ class GenerativeAgentMemory extends base_js_2.BaseMemory {
293
371
  // Return an array of memory keys
294
372
  return [this.relevantMemoriesKey, this.mostRecentMemoriesKey];
295
373
  }
374
+ /**
375
+ * Method that adds a memory to the agent's memory.
376
+ * @param memoryContent The content of the memory to add.
377
+ * @param now The current date.
378
+ * @param metadata The metadata for the memory.
379
+ * @param callbacks The Callbacks to use for adding the memory.
380
+ * @returns The result of the memory addition.
381
+ */
296
382
  async addMemory(memoryContent, now, metadata, callbacks) {
297
383
  return this.memoryChain.call({ memory_content: memoryContent, now, memory_metadata: metadata }, callbacks);
298
384
  }
385
+ /**
386
+ * Method that formats the given relevant memories in detail.
387
+ * @param relevantMemories The relevant memories to format.
388
+ * @returns The formatted memories as a string.
389
+ */
299
390
  formatMemoriesDetail(relevantMemories) {
300
391
  if (!relevantMemories.length) {
301
392
  return "No relevant information.";
@@ -320,12 +411,22 @@ class GenerativeAgentMemory extends base_js_2.BaseMemory {
320
411
  const joinedContent = content.map((mem) => `${mem}`).join("\n");
321
412
  return joinedContent;
322
413
  }
414
+ /**
415
+ * Method that formats the given relevant memories in a simple manner.
416
+ * @param relevantMemories The relevant memories to format.
417
+ * @returns The formatted memories as a string.
418
+ */
323
419
  formatMemoriesSimple(relevantMemories) {
324
420
  const joinedContent = relevantMemories
325
421
  .map((mem) => `${mem.pageContent}`)
326
422
  .join("; ");
327
423
  return joinedContent;
328
424
  }
425
+ /**
426
+ * Method that retrieves memories until a token limit is reached.
427
+ * @param consumedTokens The number of tokens consumed so far.
428
+ * @returns The memories as a string.
429
+ */
329
430
  async getMemoriesUntilLimit(consumedTokens) {
330
431
  // reduce the number of tokens in the documents
331
432
  const result = [];
@@ -351,6 +452,11 @@ class GenerativeAgentMemory extends base_js_2.BaseMemory {
351
452
  // input keys this memory class will load dynamically
352
453
  return [];
353
454
  }
455
+ /**
456
+ * Method that loads memory variables based on the given inputs.
457
+ * @param inputs The inputs to use for loading memory variables.
458
+ * @returns An object containing the loaded memory variables.
459
+ */
354
460
  async loadMemoryVariables(inputs) {
355
461
  const queries = inputs[this.queriesKey];
356
462
  const now = inputs[this.nowKey];
@@ -369,6 +475,12 @@ class GenerativeAgentMemory extends base_js_2.BaseMemory {
369
475
  }
370
476
  return {};
371
477
  }
478
+ /**
479
+ * Method that saves the context of a model run to memory.
480
+ * @param _inputs The inputs of the model run.
481
+ * @param outputs The outputs of the model run.
482
+ * @returns Nothing.
483
+ */
372
484
  async saveContext(_inputs, outputs) {
373
485
  // save the context of this model run to memory
374
486
  const mem = outputs[this.addMemoryKey];
@@ -377,6 +489,10 @@ class GenerativeAgentMemory extends base_js_2.BaseMemory {
377
489
  await this.addMemory(mem, now, {});
378
490
  }
379
491
  }
492
+ /**
493
+ * Method that clears the memory contents.
494
+ * @returns Nothing.
495
+ */
380
496
  clear() {
381
497
  // TODO: clear memory contents
382
498
  }