freestyle-sandboxes 0.0.92 → 0.0.94

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.
@@ -1,5 +1,7 @@
1
- import { F as FreestyleExecuteScriptParamsConfiguration } from '../types.gen-CG8tIO9M.js';
2
- import { z } from 'zod';
1
+ import { F as FreestyleExecuteScriptParamsConfiguration } from '../types.gen--Oxc46AH.js';
2
+ import * as z3 from 'zod/v3';
3
+ import { z } from 'zod/v3';
4
+ import * as z4 from 'zod/v4/core';
3
5
 
4
6
  type AgentAction = {
5
7
  tool: string;
@@ -11,6 +13,18 @@ type AgentFinish = {
11
13
  log: string;
12
14
  };
13
15
 
16
+ type InteropZodType<Output = any, Input = Output> = z3.ZodType<Output, z3.ZodTypeDef, Input> | z4.$ZodType<Output, Input>;
17
+ type InferInteropZodInput<T> = T extends z3.ZodType<unknown, z3.ZodTypeDef, infer Input> ? Input : T extends z4.$ZodType<unknown, infer Input> ? Input : T extends {
18
+ _zod: {
19
+ input: infer Input;
20
+ };
21
+ } ? Input : never;
22
+ type InferInteropZodOutput<T> = T extends z3.ZodType<infer Output, z3.ZodTypeDef, unknown> ? Output : T extends z4.$ZodType<infer Output, unknown> ? Output : T extends {
23
+ _zod: {
24
+ output: infer Output;
25
+ };
26
+ } ? Output : never;
27
+
14
28
  type ChainValues = Record<string, any>;
15
29
 
16
30
  interface SerializedFields {
@@ -94,7 +108,7 @@ interface StoredMessageData {
94
108
  name: string | undefined;
95
109
  tool_call_id: string | undefined;
96
110
  additional_kwargs?: Record<string, any>;
97
- /** Response metadata. For example: response headers, logprobs, token counts. */
111
+ /** Response metadata. For example: response headers, logprobs, token counts, model name. */
98
112
  response_metadata?: Record<string, any>;
99
113
  id?: string;
100
114
  }
@@ -148,7 +162,7 @@ type BaseMessageFields = {
148
162
  tool_calls?: OpenAIToolCall[];
149
163
  [key: string]: unknown;
150
164
  };
151
- /** Response metadata. For example: response headers, logprobs, token counts. */
165
+ /** Response metadata. For example: response headers, logprobs, token counts, model name. */
152
166
  response_metadata?: Record<string, any>;
153
167
  /**
154
168
  * An optional unique identifier for the message. This should ideally be
@@ -166,8 +180,7 @@ declare abstract class BaseMessage extends Serializable implements BaseMessageFi
166
180
  lc_serializable: boolean;
167
181
  get lc_aliases(): Record<string, string>;
168
182
  /**
169
- * @deprecated
170
- * Use {@link BaseMessage.content} instead.
183
+ * Get text content of the message.
171
184
  */
172
185
  get text(): string;
173
186
  /** The content of the message. */
@@ -176,7 +189,7 @@ declare abstract class BaseMessage extends Serializable implements BaseMessageFi
176
189
  name?: string;
177
190
  /** Additional keyword arguments */
178
191
  additional_kwargs: NonNullable<BaseMessageFields["additional_kwargs"]>;
179
- /** Response metadata. For example: response headers, logprobs, token counts. */
192
+ /** Response metadata. For example: response headers, logprobs, token counts, model name. */
180
193
  response_metadata: NonNullable<BaseMessageFields["response_metadata"]>;
181
194
  /**
182
195
  * An optional unique identifier for the message. This should ideally be
@@ -546,73 +559,140 @@ declare abstract class BaseCallbackHandler extends BaseCallbackHandlerMethodsCla
546
559
  * Called at the start of an LLM or Chat Model run, with the prompt(s)
547
560
  * and the run ID.
548
561
  */
549
- handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;
562
+ handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
563
+ Promise<any> | any;
550
564
  /**
551
565
  * Called when an LLM/ChatModel in `streaming` mode produces a new token
552
566
  */
553
- handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, fields?: HandleLLMNewTokenCallbackFields | undefined): any;
567
+ handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: HandleLLMNewTokenCallbackFields): // eslint-disable-next-line @typescript-eslint/no-explicit-any
568
+ Promise<any> | any;
554
569
  /**
555
570
  * Called if an LLM/ChatModel run encounters an error
556
571
  */
557
- handleLLMError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, extraParams?: Record<string, unknown> | undefined): any;
572
+ handleLLMError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
573
+ Promise<any> | any;
558
574
  /**
559
575
  * Called at the end of an LLM/ChatModel run, with the output and the run ID.
560
576
  */
561
- handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, extraParams?: Record<string, unknown> | undefined): any;
577
+ handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
578
+ Promise<any> | any;
562
579
  /**
563
580
  * Called at the start of a Chat Model run, with the prompt(s)
564
581
  * and the run ID.
565
582
  */
566
- handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;
583
+ handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
584
+ Promise<any> | any;
567
585
  /**
568
586
  * Called at the start of a Chain run, with the chain name and inputs
569
587
  * and the run ID.
570
588
  */
571
- handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runType?: string | undefined, runName?: string | undefined): any;
589
+ handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runType?: string, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
590
+ Promise<any> | any;
572
591
  /**
573
592
  * Called if a Chain run encounters an error
574
593
  */
575
- handleChainError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {
576
- inputs?: Record<string, unknown> | undefined;
577
- } | undefined): any;
594
+ handleChainError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
595
+ inputs?: Record<string, unknown>;
596
+ }): // eslint-disable-next-line @typescript-eslint/no-explicit-any
597
+ Promise<any> | any;
578
598
  /**
579
599
  * Called at the end of a Chain run, with the outputs and the run ID.
580
600
  */
581
- handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {
582
- inputs?: Record<string, unknown> | undefined;
583
- } | undefined): any;
601
+ handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
602
+ inputs?: Record<string, unknown>;
603
+ }): // eslint-disable-next-line @typescript-eslint/no-explicit-any
604
+ Promise<any> | any;
584
605
  /**
585
606
  * Called at the start of a Tool run, with the tool name and input
586
607
  * and the run ID.
587
608
  */
588
- handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;
609
+ handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
610
+ Promise<any> | any;
589
611
  /**
590
612
  * Called if a Tool run encounters an error
591
613
  */
592
- handleToolError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
614
+ handleToolError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
615
+ Promise<any> | any;
593
616
  /**
594
617
  * Called at the end of a Tool run, with the tool output and the run ID.
595
618
  */
596
- handleToolEnd?(output: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
597
- handleText?(text: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
619
+ handleToolEnd?(output: any, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
620
+ Promise<any> | any;
621
+ handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
598
622
  /**
599
623
  * Called when an agent is about to execute an action,
600
624
  * with the action and the run ID.
601
625
  */
602
- handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
626
+ handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
603
627
  /**
604
628
  * Called when an agent finishes execution, before it exits.
605
629
  * with the final output and the run ID.
606
630
  */
607
- handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
608
- handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
609
- handleRetrieverEnd?(documents: DocumentInterface<Record<string, any>>[], runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
610
- handleRetrieverError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
611
- handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[] | undefined, metadata?: Record<string, any> | undefined): any;
631
+ handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
632
+ handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
633
+ Promise<any> | any;
634
+ handleRetrieverEnd?(documents: DocumentInterface[], runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
635
+ Promise<any> | any;
636
+ handleRetrieverError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
637
+ Promise<any> | any;
638
+ handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
639
+ Promise<any> | any;
612
640
  };
613
641
  }
614
642
 
643
+ type ResponseCallback = (response?: Response) => Promise<boolean>;
644
+ interface AsyncCallerParams {
645
+ /**
646
+ * The maximum number of concurrent calls that can be made.
647
+ * Defaults to `Infinity`, which means no limit.
648
+ */
649
+ maxConcurrency?: number;
650
+ /**
651
+ * The maximum number of retries that can be made for a single call,
652
+ * with an exponential backoff between each attempt. Defaults to 6.
653
+ */
654
+ maxRetries?: number;
655
+ onFailedResponseHook?: ResponseCallback;
656
+ debug?: boolean;
657
+ }
658
+
659
+ interface TracerSession {
660
+ tenant_id: string;
661
+ id: string;
662
+ start_time: number;
663
+ end_time?: number;
664
+ description?: string;
665
+ name?: string;
666
+ /** Extra metadata for the project. */
667
+ extra?: KVMap;
668
+ reference_dataset_id?: string;
669
+ }
670
+ interface TracerSessionResult extends TracerSession {
671
+ run_count?: number;
672
+ latency_p50?: number;
673
+ latency_p99?: number;
674
+ total_tokens?: number;
675
+ prompt_tokens?: number;
676
+ completion_tokens?: number;
677
+ last_run_start_time?: number;
678
+ feedback_stats?: Record<string, unknown>;
679
+ run_facets?: KVMap[];
680
+ }
615
681
  type KVMap = Record<string, any>;
682
+ type ScoreType = number | boolean | null;
683
+ type ValueType = number | boolean | string | object | null;
684
+ type DataType = "kv" | "llm" | "chat";
685
+ interface BaseExample {
686
+ dataset_id: string;
687
+ inputs: KVMap;
688
+ outputs?: KVMap;
689
+ metadata?: KVMap;
690
+ source_run_id?: string;
691
+ }
692
+ interface AttachmentInfo {
693
+ presigned_url: string;
694
+ mime_type?: string;
695
+ }
616
696
  type AttachmentData = Uint8Array | ArrayBuffer;
617
697
  type AttachmentDescription = {
618
698
  mimeType: string;
@@ -632,11 +712,11 @@ interface BaseRun {
632
712
  /** A human-readable name for the run. */
633
713
  name: string;
634
714
  /** The epoch time at which the run started, if available. */
635
- start_time?: number;
715
+ start_time?: number | string;
636
716
  /** Specifies the type of run (tool, chain, llm, etc.). */
637
717
  run_type: string;
638
718
  /** The epoch time at which the run ended, if applicable. */
639
- end_time?: number;
719
+ end_time?: number | string;
640
720
  /** Any additional metadata or settings for the run. */
641
721
  extra?: KVMap;
642
722
  /** Error message, captured if the run faces any issues. */
@@ -658,28 +738,1495 @@ interface BaseRun {
658
738
  /** Unique ID assigned to every run within this nested trace. **/
659
739
  trace_id?: string;
660
740
  /**
661
- * The dotted order for the run.
662
- *
663
- * This is a string composed of {time}{run-uuid}.* so that a trace can be
664
- * sorted in the order it was executed.
665
- *
666
- * Example:
667
- * - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
668
- * - Children:
669
- * - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
670
- * - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
741
+ * The dotted order for the run.
742
+ *
743
+ * This is a string composed of {time}{run-uuid}.* so that a trace can be
744
+ * sorted in the order it was executed.
745
+ *
746
+ * Example:
747
+ * - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
748
+ * - Children:
749
+ * - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
750
+ * - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
751
+ */
752
+ dotted_order?: string;
753
+ /**
754
+ * Attachments associated with the run.
755
+ * Each entry is a tuple of [mime_type, bytes]
756
+ */
757
+ attachments?: Attachments;
758
+ }
759
+ type S3URL = {
760
+ ROOT: {
761
+ /** A pre-signed URL */
762
+ presigned_url: string;
763
+ /** The S3 path to the object in storage */
764
+ s3_url: string;
765
+ };
766
+ };
767
+ /**
768
+ * Describes properties of a run when loaded from the database.
769
+ * Extends the BaseRun interface.
770
+ */
771
+ interface Run$1 extends BaseRun {
772
+ /** A unique identifier for the run, mandatory when loaded from DB. */
773
+ id: string;
774
+ /** The ID of the project that owns this run. */
775
+ session_id?: string;
776
+ /** IDs of any child runs spawned by this run. */
777
+ child_run_ids?: string[];
778
+ /** Child runs, loaded explicitly via a heavier query. */
779
+ child_runs?: Run$1[];
780
+ /** Stats capturing feedback for this run. */
781
+ feedback_stats?: KVMap;
782
+ /** The URL path where this run is accessible within the app. */
783
+ app_path?: string;
784
+ /** The manifest ID that correlates with this run. */
785
+ manifest_id?: string;
786
+ /** The current status of the run, such as 'success'. */
787
+ status?: string;
788
+ /** Number of tokens used in the prompt. */
789
+ prompt_tokens?: number;
790
+ /** Number of tokens generated in the completion. */
791
+ completion_tokens?: number;
792
+ /** Total token count, combining prompt and completion. */
793
+ total_tokens?: number;
794
+ /** Time when the first token was processed. */
795
+ first_token_time?: number;
796
+ /** IDs of parent runs, if multiple exist. */
797
+ parent_run_ids?: string[];
798
+ /** Whether the run is included in a dataset. */
799
+ in_dataset?: boolean;
800
+ /** The output S3 URLs */
801
+ outputs_s3_urls?: S3URL;
802
+ /** The input S3 URLs */
803
+ inputs_s3_urls?: S3URL;
804
+ }
805
+ interface RunCreate extends BaseRun {
806
+ revision_id?: string;
807
+ child_runs?: this[];
808
+ session_name?: string;
809
+ }
810
+ interface RunUpdate {
811
+ id?: string;
812
+ end_time?: number | string;
813
+ extra?: KVMap;
814
+ tags?: string[];
815
+ error?: string;
816
+ inputs?: KVMap;
817
+ outputs?: KVMap;
818
+ parent_run_id?: string;
819
+ reference_example_id?: string;
820
+ events?: KVMap[];
821
+ session_id?: string;
822
+ session_name?: string;
823
+ /** Unique ID assigned to every run within this nested trace. **/
824
+ trace_id?: string;
825
+ /**
826
+ * The dotted order for the run.
827
+ *
828
+ * This is a string composed of {time}{run-uuid}.* so that a trace can be
829
+ * sorted in the order it was executed.
830
+ *
831
+ * Example:
832
+ * - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
833
+ * - Children:
834
+ * - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
835
+ * - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
836
+ */
837
+ dotted_order?: string;
838
+ /**
839
+ * Attachments associated with the run.
840
+ * Each entry is a tuple of [mime_type, bytes]
841
+ */
842
+ attachments?: Attachments;
843
+ }
844
+ interface ExampleCreate {
845
+ id?: string;
846
+ inputs: KVMap;
847
+ outputs?: KVMap;
848
+ metadata?: KVMap;
849
+ split?: string | string[];
850
+ attachments?: Attachments;
851
+ created_at?: string;
852
+ dataset_id?: string;
853
+ dataset_name?: string;
854
+ source_run_id?: string;
855
+ use_source_run_io?: boolean;
856
+ use_source_run_attachments?: string[];
857
+ }
858
+ interface ExampleUpdate {
859
+ id: string;
860
+ inputs?: KVMap;
861
+ outputs?: KVMap;
862
+ metadata?: KVMap;
863
+ split?: string | string[];
864
+ attachments?: Attachments;
865
+ attachments_operations?: KVMap;
866
+ dataset_id?: string;
867
+ }
868
+ interface ExampleUpdateWithoutId extends Omit<ExampleUpdate, "id"> {
869
+ }
870
+ interface UploadExamplesResponse {
871
+ count: number;
872
+ example_ids: string[];
873
+ }
874
+ interface UpdateExamplesResponse extends UploadExamplesResponse {
875
+ }
876
+ interface Example extends BaseExample {
877
+ id: string;
878
+ created_at: string;
879
+ modified_at?: string;
880
+ source_run_id?: string;
881
+ runs: Run$1[];
882
+ attachments?: Record<string, AttachmentInfo>;
883
+ split?: string | string[];
884
+ }
885
+ interface ExampleSearch extends BaseExample {
886
+ id: string;
887
+ }
888
+ interface BaseDataset {
889
+ name: string;
890
+ description: string;
891
+ tenant_id: string;
892
+ data_type?: DataType;
893
+ inputs_schema_definition?: KVMap;
894
+ outputs_schema_definition?: KVMap;
895
+ }
896
+ interface Dataset extends BaseDataset {
897
+ id: string;
898
+ created_at: string;
899
+ modified_at: string;
900
+ example_count?: number;
901
+ session_count?: number;
902
+ last_session_start_time?: number;
903
+ }
904
+ interface DatasetShareSchema {
905
+ dataset_id: string;
906
+ share_token: string;
907
+ url: string;
908
+ }
909
+ interface DatasetVersion {
910
+ tags?: string[];
911
+ as_of: string;
912
+ }
913
+ interface FeedbackSourceBase {
914
+ type: string;
915
+ metadata?: KVMap;
916
+ }
917
+ interface APIFeedbackSource extends FeedbackSourceBase {
918
+ type: "api";
919
+ }
920
+ interface ModelFeedbackSource extends FeedbackSourceBase {
921
+ type: "model";
922
+ }
923
+ interface FeedbackBase {
924
+ created_at: string;
925
+ modified_at: string;
926
+ run_id: string;
927
+ key: string;
928
+ score: ScoreType;
929
+ value: ValueType;
930
+ comment: string | null;
931
+ correction: string | object | null;
932
+ feedback_source: APIFeedbackSource | ModelFeedbackSource | KVMap | null;
933
+ }
934
+ interface Feedback extends FeedbackBase {
935
+ id: string;
936
+ }
937
+ interface LangChainBaseMessage {
938
+ _getType: () => string;
939
+ content: string;
940
+ additional_kwargs?: KVMap;
941
+ }
942
+ interface FeedbackIngestToken {
943
+ id: string;
944
+ url: string;
945
+ expires_at: string;
946
+ }
947
+ interface TimeDelta {
948
+ days?: number;
949
+ hours?: number;
950
+ minutes?: number;
951
+ }
952
+ interface FeedbackCategory {
953
+ value: number;
954
+ label?: string | null;
955
+ }
956
+ /**
957
+ * Represents the configuration for feedback.
958
+ * This determines how the LangSmith service interprets feedback
959
+ * values of the associated key.
960
+ */
961
+ interface FeedbackConfig {
962
+ /**
963
+ * The type of feedback.
964
+ * - "continuous": Feedback with a continuous numeric.
965
+ * - "categorical": Feedback with a categorical value (classes)
966
+ * - "freeform": Feedback with a freeform text value (notes).
967
+ */
968
+ type: "continuous" | "categorical" | "freeform";
969
+ /**
970
+ * The minimum value for continuous feedback.
971
+ */
972
+ min?: number | null;
973
+ /**
974
+ * The maximum value for continuous feedback.
975
+ */
976
+ max?: number | null;
977
+ /**
978
+ * The categories for categorical feedback.
979
+ * Each category can be a string or an object with additional properties.
980
+ *
981
+ * If feedback is categorical, this defines the valid categories the server will accept.
982
+ * Not applicable to continuous or freeform feedback types.
983
+ */
984
+ categories?: FeedbackCategory[] | null;
985
+ }
986
+ interface DatasetDiffInfo {
987
+ examples_modified: string[];
988
+ examples_added: string[];
989
+ examples_removed: string[];
990
+ }
991
+ interface ComparativeExperiment {
992
+ id: string;
993
+ name: string;
994
+ description: string;
995
+ tenant_id: string;
996
+ created_at: string;
997
+ modified_at: string;
998
+ reference_dataset_id: string;
999
+ extra?: Record<string, unknown>;
1000
+ experiments_info?: Array<Record<string, unknown>>;
1001
+ feedback_stats?: Record<string, unknown>;
1002
+ }
1003
+ interface PromptCommit {
1004
+ owner: string;
1005
+ repo: string;
1006
+ commit_hash: string;
1007
+ manifest: Record<string, any>;
1008
+ examples: Array<Record<any, any>>;
1009
+ }
1010
+ interface Prompt {
1011
+ repo_handle: string;
1012
+ description?: string;
1013
+ readme?: string;
1014
+ id: string;
1015
+ tenant_id: string;
1016
+ created_at: string;
1017
+ updated_at: string;
1018
+ is_public: boolean;
1019
+ is_archived: boolean;
1020
+ tags: string[];
1021
+ original_repo_id?: string;
1022
+ upstream_repo_id?: string;
1023
+ owner?: string;
1024
+ full_name: string;
1025
+ num_likes: number;
1026
+ num_downloads: number;
1027
+ num_views: number;
1028
+ liked_by_auth_user: boolean;
1029
+ last_commit_hash?: string;
1030
+ num_commits: number;
1031
+ original_repo_full_name?: string;
1032
+ upstream_repo_full_name?: string;
1033
+ }
1034
+ type PromptSortField = "num_downloads" | "num_views" | "updated_at" | "num_likes";
1035
+ interface LikePromptResponse {
1036
+ likes: number;
1037
+ }
1038
+ interface LangSmithSettings {
1039
+ id: string;
1040
+ display_name: string;
1041
+ created_at: string;
1042
+ tenant_handle?: string;
1043
+ }
1044
+ interface AnnotationQueue {
1045
+ /** The unique identifier of the annotation queue. */
1046
+ id: string;
1047
+ /** The name of the annotation queue. */
1048
+ name: string;
1049
+ /** An optional description of the annotation queue. */
1050
+ description?: string;
1051
+ /** The timestamp when the annotation queue was created. */
1052
+ created_at: string;
1053
+ /** The timestamp when the annotation queue was last updated. */
1054
+ updated_at: string;
1055
+ /** The ID of the tenant associated with the annotation queue. */
1056
+ tenant_id: string;
1057
+ }
1058
+ interface AnnotationQueueWithDetails extends AnnotationQueue {
1059
+ /** The rubric instructions for the annotation queue. */
1060
+ rubric_instructions?: string;
1061
+ }
1062
+ interface RunWithAnnotationQueueInfo extends BaseRun {
1063
+ /** The last time this run was reviewed. */
1064
+ last_reviewed_time?: string;
1065
+ /** The time this run was added to the queue. */
1066
+ added_at?: string;
1067
+ }
1068
+
1069
+ interface RunTreeConfig {
1070
+ name: string;
1071
+ run_type?: string;
1072
+ id?: string;
1073
+ project_name?: string;
1074
+ parent_run?: RunTree;
1075
+ parent_run_id?: string;
1076
+ child_runs?: RunTree[];
1077
+ start_time?: number | string;
1078
+ end_time?: number | string;
1079
+ extra?: KVMap;
1080
+ metadata?: KVMap;
1081
+ tags?: string[];
1082
+ error?: string;
1083
+ serialized?: object;
1084
+ inputs?: KVMap;
1085
+ outputs?: KVMap;
1086
+ reference_example_id?: string;
1087
+ client?: Client;
1088
+ tracingEnabled?: boolean;
1089
+ on_end?: (runTree: RunTree) => void;
1090
+ execution_order?: number;
1091
+ child_execution_order?: number;
1092
+ trace_id?: string;
1093
+ dotted_order?: string;
1094
+ attachments?: Attachments;
1095
+ replicas?: Replica[];
1096
+ }
1097
+ interface RunnableConfigLike {
1098
+ /**
1099
+ * Tags for this call and any sub-calls (eg. a Chain calling an LLM).
1100
+ * You can use these to filter calls.
1101
+ */
1102
+ tags?: string[];
1103
+ /**
1104
+ * Metadata for this call and any sub-calls (eg. a Chain calling an LLM).
1105
+ * Keys should be strings, values should be JSON-serializable.
1106
+ */
1107
+ metadata?: Record<string, unknown>;
1108
+ /**
1109
+ * Callbacks for this call and any sub-calls (eg. a Chain calling an LLM).
1110
+ * Tags are passed to all callbacks, metadata is passed to handle*Start callbacks.
1111
+ */
1112
+ callbacks?: any;
1113
+ }
1114
+ interface HeadersLike {
1115
+ get(name: string): string | null;
1116
+ set(name: string, value: string): void;
1117
+ }
1118
+ type ProjectReplica = [string, KVMap | undefined];
1119
+ type WriteReplica = {
1120
+ apiUrl?: string;
1121
+ apiKey?: string;
1122
+ projectName?: string;
1123
+ updates?: KVMap | undefined;
1124
+ fromEnv?: boolean;
1125
+ };
1126
+ type Replica = ProjectReplica | WriteReplica;
1127
+ declare class RunTree implements BaseRun {
1128
+ private static sharedClient;
1129
+ id: string;
1130
+ name: RunTreeConfig["name"];
1131
+ run_type: string;
1132
+ project_name: string;
1133
+ parent_run?: RunTree;
1134
+ parent_run_id?: string;
1135
+ child_runs: RunTree[];
1136
+ start_time: number;
1137
+ end_time?: number;
1138
+ extra: KVMap;
1139
+ tags?: string[];
1140
+ error?: string;
1141
+ serialized: object;
1142
+ inputs: KVMap;
1143
+ outputs?: KVMap;
1144
+ reference_example_id?: string;
1145
+ client: Client;
1146
+ events?: KVMap[] | undefined;
1147
+ trace_id: string;
1148
+ dotted_order: string;
1149
+ tracingEnabled?: boolean;
1150
+ execution_order: number;
1151
+ child_execution_order: number;
1152
+ /**
1153
+ * Attachments associated with the run.
1154
+ * Each entry is a tuple of [mime_type, bytes]
1155
+ */
1156
+ attachments?: Attachments;
1157
+ /**
1158
+ * Projects to replicate this run to with optional updates.
1159
+ */
1160
+ replicas?: WriteReplica[];
1161
+ private _serialized_start_time;
1162
+ constructor(originalConfig: RunTreeConfig | RunTree);
1163
+ set metadata(metadata: KVMap);
1164
+ get metadata(): KVMap;
1165
+ private static getDefaultConfig;
1166
+ static getSharedClient(): Client;
1167
+ createChild(config: RunTreeConfig): RunTree;
1168
+ end(outputs?: KVMap, error?: string, endTime?: number, metadata?: KVMap): Promise<void>;
1169
+ private _convertToCreate;
1170
+ private _remapForProject;
1171
+ postRun(excludeChildRuns?: boolean): Promise<void>;
1172
+ patchRun(): Promise<void>;
1173
+ toJSON(): RunCreate & {
1174
+ id: string;
1175
+ };
1176
+ /**
1177
+ * Add an event to the run tree.
1178
+ * @param event - A single event or string to add
1179
+ */
1180
+ addEvent(event: RunEvent | string): void;
1181
+ static fromRunnableConfig(parentConfig: RunnableConfigLike, props: RunTreeConfig): RunTree;
1182
+ static fromDottedOrder(dottedOrder: string): RunTree | undefined;
1183
+ static fromHeaders(headers: Record<string, string | string[]> | HeadersLike, inheritArgs?: RunTreeConfig): RunTree | undefined;
1184
+ toHeaders(headers?: HeadersLike): {
1185
+ "langsmith-trace": string;
1186
+ baggage: string;
1187
+ };
1188
+ }
1189
+ interface RunEvent {
1190
+ name?: string;
1191
+ time?: string;
1192
+ message?: string;
1193
+ kwargs?: Record<string, unknown>;
1194
+ [key: string]: unknown;
1195
+ }
1196
+
1197
+ /**
1198
+ * Represents the result of an evaluation.
1199
+ */
1200
+ type EvaluationResult = {
1201
+ /**
1202
+ * The key associated with the evaluation result.
1203
+ */
1204
+ key: string;
1205
+ /**
1206
+ * The score of the evaluation result.
1207
+ */
1208
+ score?: ScoreType;
1209
+ /**
1210
+ * The value of the evaluation result.
1211
+ */
1212
+ value?: ValueType;
1213
+ /**
1214
+ * A comment associated with the evaluation result.
1215
+ */
1216
+ comment?: string;
1217
+ /**
1218
+ * A correction record associated with the evaluation result.
1219
+ */
1220
+ correction?: Record<string, unknown>;
1221
+ /**
1222
+ * Information about the evaluator.
1223
+ */
1224
+ evaluatorInfo?: Record<string, unknown>;
1225
+ /**
1226
+ * The source run ID of the evaluation result.
1227
+ * If set, a link to the source run will be available in the UI.
1228
+ */
1229
+ sourceRunId?: string;
1230
+ /**
1231
+ * The target run ID of the evaluation result.
1232
+ * If this is not set, the target run ID is assumed to be
1233
+ * the root of the trace.
1234
+ */
1235
+ targetRunId?: string;
1236
+ /**
1237
+ * The feedback config associated with the evaluation result.
1238
+ * If set, this will be used to define how a feedback key
1239
+ * should be interpreted.
1240
+ */
1241
+ feedbackConfig?: FeedbackConfig;
1242
+ };
1243
+ /**
1244
+ * Batch evaluation results, if your evaluator wishes
1245
+ * to return multiple scores.
1246
+ */
1247
+ type EvaluationResults = {
1248
+ /**
1249
+ * The evaluation results.
1250
+ */
1251
+ results: Array<EvaluationResult>;
1252
+ };
1253
+ interface RunEvaluator {
1254
+ evaluateRun(run: Run$1, example?: Example, options?: Partial<RunTreeConfig>): Promise<EvaluationResult | EvaluationResults>;
1255
+ }
1256
+
1257
+ interface ClientConfig {
1258
+ apiUrl?: string;
1259
+ apiKey?: string;
1260
+ callerOptions?: AsyncCallerParams;
1261
+ timeout_ms?: number;
1262
+ webUrl?: string;
1263
+ anonymizer?: (values: KVMap) => KVMap | Promise<KVMap>;
1264
+ hideInputs?: boolean | ((inputs: KVMap) => KVMap | Promise<KVMap>);
1265
+ hideOutputs?: boolean | ((outputs: KVMap) => KVMap | Promise<KVMap>);
1266
+ autoBatchTracing?: boolean;
1267
+ batchSizeBytesLimit?: number;
1268
+ blockOnRootRunFinalization?: boolean;
1269
+ traceBatchConcurrency?: number;
1270
+ fetchOptions?: RequestInit;
1271
+ /**
1272
+ * Whether to require manual .flush() calls before sending traces.
1273
+ * Useful if encountering network rate limits at trace high volumes.
1274
+ */
1275
+ manualFlushMode?: boolean;
1276
+ tracingSamplingRate?: number;
1277
+ /**
1278
+ * Enable debug mode for the client. If set, all sent HTTP requests will be logged.
1279
+ */
1280
+ debug?: boolean;
1281
+ }
1282
+ /**
1283
+ * Represents the parameters for listing runs (spans) from the Langsmith server.
1284
+ */
1285
+ interface ListRunsParams {
1286
+ /**
1287
+ * The ID or IDs of the project(s) to filter by.
1288
+ */
1289
+ projectId?: string | string[];
1290
+ /**
1291
+ * The name or names of the project(s) to filter by.
1292
+ */
1293
+ projectName?: string | string[];
1294
+ /**
1295
+ * The ID of the trace to filter by.
1296
+ */
1297
+ traceId?: string;
1298
+ /**
1299
+ * isRoot - Whether to only include root runs.
1300
+ * */
1301
+ isRoot?: boolean;
1302
+ /**
1303
+ * The execution order to filter by.
1304
+ */
1305
+ executionOrder?: number;
1306
+ /**
1307
+ * The ID of the parent run to filter by.
1308
+ */
1309
+ parentRunId?: string;
1310
+ /**
1311
+ * The order by run start date
1312
+ */
1313
+ order?: "asc" | "desc";
1314
+ /**
1315
+ * The ID of the reference example to filter by.
1316
+ */
1317
+ referenceExampleId?: string;
1318
+ /**
1319
+ * The start time to filter by.
1320
+ */
1321
+ startTime?: Date;
1322
+ /**
1323
+ * The run type to filter by.
1324
+ */
1325
+ runType?: string;
1326
+ /**
1327
+ * Indicates whether to filter by error runs.
1328
+ */
1329
+ error?: boolean;
1330
+ /**
1331
+ * The ID or IDs of the runs to filter by.
1332
+ */
1333
+ id?: string[];
1334
+ /**
1335
+ * The maximum number of runs to retrieve.
1336
+ */
1337
+ limit?: number;
1338
+ /**
1339
+ * The query string to filter by.
1340
+ */
1341
+ query?: string;
1342
+ /**
1343
+ * The filter string to apply.
1344
+ *
1345
+ * Run Filtering:
1346
+ * Listing runs with query params is useful for simple queries, but doesn't support many common needs, such as filtering by metadata, tags, or other fields.
1347
+ * LangSmith supports a filter query language to permit more complex filtering operations when fetching runs. This guide will provide a high level overview of the grammar as well as a few examples of when it can be useful.
1348
+ * If you'd prefer a more visual guide, you can get a taste of the language by viewing the table of runs on any of your projects' pages. We provide some recommended filters to get you started that you can copy and use the SDK.
1349
+ *
1350
+ * Grammar:
1351
+ * The filtering grammar is based on common comparators on fields in the run object. Supported comparators include:
1352
+ * - gte (greater than or equal to)
1353
+ * - gt (greater than)
1354
+ * - lte (less than or equal to)
1355
+ * - lt (less than)
1356
+ * - eq (equal to)
1357
+ * - neq (not equal to)
1358
+ * - has (check if run contains a tag or metadata json blob)
1359
+ * - search (search for a substring in a string field)
1360
+ */
1361
+ filter?: string;
1362
+ /**
1363
+ * Filter to apply to the ROOT run in the trace tree. This is meant to be used in conjunction with the regular
1364
+ * `filter` parameter to let you filter runs by attributes of the root run within a trace. Example is filtering by
1365
+ * feedback assigned to the trace.
1366
+ */
1367
+ traceFilter?: string;
1368
+ /**
1369
+ * Filter to apply to OTHER runs in the trace tree, including sibling and child runs. This is meant to be used in
1370
+ * conjunction with the regular `filter` parameter to let you filter runs by attributes of any run within a trace.
1371
+ */
1372
+ treeFilter?: string;
1373
+ /**
1374
+ * The values to include in the response.
1375
+ */
1376
+ select?: string[];
1377
+ }
1378
+ interface GroupRunsParams {
1379
+ /**
1380
+ * The ID or IDs of the project(s) to filter by.
1381
+ */
1382
+ projectId?: string;
1383
+ /**
1384
+ * The ID or IDs of the project(s) to filter by.
1385
+ */
1386
+ projectName?: string;
1387
+ /**
1388
+ * @example "conversation"
1389
+ */
1390
+ groupBy: string;
1391
+ /**
1392
+ * The filter string to apply.
1393
+ *
1394
+ * Run Filtering:
1395
+ * Listing runs with query params is useful for simple queries, but doesn't support many common needs, such as filtering by metadata, tags, or other fields.
1396
+ * LangSmith supports a filter query language to permit more complex filtering operations when fetching runs. This guide will provide a high level overview of the grammar as well as a few examples of when it can be useful.
1397
+ * If you'd prefer a more visual guide, you can get a taste of the language by viewing the table of runs on any of your projects' pages. We provide some recommended filters to get you started that you can copy and use the SDK.
1398
+ *
1399
+ * Grammar:
1400
+ * The filtering grammar is based on common comparators on fields in the run object. Supported comparators include:
1401
+ * - gte (greater than or equal to)
1402
+ * - gt (greater than)
1403
+ * - lte (less than or equal to)
1404
+ * - lt (less than)
1405
+ * - eq (equal to)
1406
+ * - neq (not equal to)
1407
+ * - has (check if run contains a tag or metadata json blob)
1408
+ * - search (search for a substring in a string field)
1409
+ */
1410
+ filter?: string;
1411
+ /**
1412
+ * The start time to filter by.
1413
+ */
1414
+ startTime?: Date;
1415
+ /**
1416
+ * The end time to filter by.
1417
+ */
1418
+ endTime?: Date;
1419
+ /**
1420
+ * The maximum number of runs to retrieve.
1421
+ */
1422
+ limit?: number;
1423
+ /**
1424
+ * The maximum number of runs to retrieve.
1425
+ */
1426
+ offset?: number;
1427
+ }
1428
+ interface UploadCSVParams {
1429
+ csvFile: Blob;
1430
+ fileName: string;
1431
+ inputKeys: string[];
1432
+ outputKeys: string[];
1433
+ description?: string;
1434
+ dataType?: DataType;
1435
+ name?: string;
1436
+ }
1437
+ interface CreateRunParams {
1438
+ name: string;
1439
+ inputs: KVMap;
1440
+ run_type: string;
1441
+ id?: string;
1442
+ start_time?: number | string;
1443
+ end_time?: number | string;
1444
+ extra?: KVMap;
1445
+ error?: string;
1446
+ serialized?: object;
1447
+ outputs?: KVMap;
1448
+ reference_example_id?: string;
1449
+ child_runs?: RunCreate[];
1450
+ parent_run_id?: string;
1451
+ project_name?: string;
1452
+ revision_id?: string;
1453
+ trace_id?: string;
1454
+ dotted_order?: string;
1455
+ attachments?: Attachments;
1456
+ }
1457
+ interface ProjectOptions {
1458
+ projectName?: string;
1459
+ projectId?: string;
1460
+ }
1461
+ type RecordStringAny = Record<string, any>;
1462
+ type FeedbackSourceType = "model" | "api" | "app";
1463
+ type CreateExampleOptions = {
1464
+ /** The ID of the dataset to create the example in. */
1465
+ datasetId?: string;
1466
+ /** The name of the dataset to create the example in (if dataset ID is not provided). */
1467
+ datasetName?: string;
1468
+ /** The creation date of the example. */
1469
+ createdAt?: Date;
1470
+ /** A unique identifier for the example. */
1471
+ exampleId?: string;
1472
+ /** Additional metadata associated with the example. */
1473
+ metadata?: KVMap;
1474
+ /** The split(s) to assign the example to. */
1475
+ split?: string | string[];
1476
+ /** The ID of the source run associated with this example. */
1477
+ sourceRunId?: string;
1478
+ /** Whether to use the inputs and outputs from the source run. */
1479
+ useSourceRunIO?: boolean;
1480
+ /** Which attachments from the source run to use. */
1481
+ useSourceRunAttachments?: string[];
1482
+ /** Attachments for the example */
1483
+ attachments?: Attachments;
1484
+ };
1485
+ type CreateProjectParams = {
1486
+ projectName: string;
1487
+ description?: string | null;
1488
+ metadata?: RecordStringAny | null;
1489
+ upsert?: boolean;
1490
+ projectExtra?: RecordStringAny | null;
1491
+ referenceDatasetId?: string | null;
1492
+ };
1493
+ type Thread = {
1494
+ filter: string;
1495
+ count: number;
1496
+ total_tokens: number;
1497
+ total_cost: number | null;
1498
+ min_start_time: string;
1499
+ max_start_time: string;
1500
+ latency_p50: number;
1501
+ latency_p99: number;
1502
+ feedback_stats: any | null;
1503
+ group_key: string;
1504
+ first_inputs: string;
1505
+ last_outputs: string;
1506
+ last_error: string | null;
1507
+ };
1508
+ declare class Client implements LangSmithTracingClientInterface {
1509
+ private apiKey?;
1510
+ private apiUrl;
1511
+ private webUrl?;
1512
+ private caller;
1513
+ private batchIngestCaller;
1514
+ private timeout_ms;
1515
+ private _tenantId;
1516
+ private hideInputs?;
1517
+ private hideOutputs?;
1518
+ private tracingSampleRate?;
1519
+ private filteredPostUuids;
1520
+ private autoBatchTracing;
1521
+ private autoBatchQueue;
1522
+ private autoBatchTimeout;
1523
+ private autoBatchAggregationDelayMs;
1524
+ private batchSizeBytesLimit?;
1525
+ private fetchOptions;
1526
+ private settings;
1527
+ private blockOnRootRunFinalization;
1528
+ private traceBatchConcurrency;
1529
+ private _serverInfo;
1530
+ private _getServerInfoPromise?;
1531
+ private manualFlushMode;
1532
+ private langSmithToOTELTranslator?;
1533
+ private multipartStreamingDisabled;
1534
+ debug: boolean;
1535
+ constructor(config?: ClientConfig);
1536
+ static getDefaultClientConfig(): {
1537
+ apiUrl: string;
1538
+ apiKey?: string;
1539
+ webUrl?: string;
1540
+ hideInputs?: boolean;
1541
+ hideOutputs?: boolean;
1542
+ };
1543
+ getHostUrl(): string;
1544
+ private get headers();
1545
+ private _getPlatformEndpointPath;
1546
+ private processInputs;
1547
+ private processOutputs;
1548
+ private prepareRunCreateOrUpdateInputs;
1549
+ private _getResponse;
1550
+ private _get;
1551
+ private _getPaginated;
1552
+ private _getCursorPaginatedList;
1553
+ private _shouldSample;
1554
+ private _filterForSampling;
1555
+ private _getBatchSizeLimitBytes;
1556
+ private _getMultiPartSupport;
1557
+ private drainAutoBatchQueue;
1558
+ private _processBatch;
1559
+ private _sendBatchToOTELTranslator;
1560
+ private processRunOperation;
1561
+ protected _getServerInfo(): Promise<any>;
1562
+ protected _ensureServerInfo(): Promise<Record<string, any>>;
1563
+ protected _getSettings(): Promise<LangSmithSettings>;
1564
+ /**
1565
+ * Flushes current queued traces.
1566
+ */
1567
+ flush(): Promise<void>;
1568
+ private _cloneCurrentOTELContext;
1569
+ createRun(run: CreateRunParams, options?: {
1570
+ apiKey?: string;
1571
+ apiUrl?: string;
1572
+ }): Promise<void>;
1573
+ /**
1574
+ * Batch ingest/upsert multiple runs in the Langsmith system.
1575
+ * @param runs
1576
+ */
1577
+ batchIngestRuns({ runCreates, runUpdates, }: {
1578
+ runCreates?: RunCreate[];
1579
+ runUpdates?: RunUpdate[];
1580
+ }, options?: {
1581
+ apiKey?: string;
1582
+ apiUrl?: string;
1583
+ }): Promise<void>;
1584
+ private _postBatchIngestRuns;
1585
+ /**
1586
+ * Batch ingest/upsert multiple runs in the Langsmith system.
1587
+ * @param runs
1588
+ */
1589
+ multipartIngestRuns({ runCreates, runUpdates, }: {
1590
+ runCreates?: RunCreate[];
1591
+ runUpdates?: RunUpdate[];
1592
+ }, options?: {
1593
+ apiKey?: string;
1594
+ apiUrl?: string;
1595
+ }): Promise<void>;
1596
+ private _createNodeFetchBody;
1597
+ private _createMultipartStream;
1598
+ private _sendMultipartRequest;
1599
+ updateRun(runId: string, run: RunUpdate, options?: {
1600
+ apiKey?: string;
1601
+ apiUrl?: string;
1602
+ }): Promise<void>;
1603
+ readRun(runId: string, { loadChildRuns }?: {
1604
+ loadChildRuns: boolean;
1605
+ }): Promise<Run$1>;
1606
+ getRunUrl({ runId, run, projectOpts, }: {
1607
+ runId?: string;
1608
+ run?: Run$1;
1609
+ projectOpts?: ProjectOptions;
1610
+ }): Promise<string>;
1611
+ private _loadChildRuns;
1612
+ /**
1613
+ * List runs from the LangSmith server.
1614
+ * @param projectId - The ID of the project to filter by.
1615
+ * @param projectName - The name of the project to filter by.
1616
+ * @param parentRunId - The ID of the parent run to filter by.
1617
+ * @param traceId - The ID of the trace to filter by.
1618
+ * @param referenceExampleId - The ID of the reference example to filter by.
1619
+ * @param startTime - The start time to filter by.
1620
+ * @param isRoot - Indicates whether to only return root runs.
1621
+ * @param runType - The run type to filter by.
1622
+ * @param error - Indicates whether to filter by error runs.
1623
+ * @param id - The ID of the run to filter by.
1624
+ * @param query - The query string to filter by.
1625
+ * @param filter - The filter string to apply to the run spans.
1626
+ * @param traceFilter - The filter string to apply on the root run of the trace.
1627
+ * @param treeFilter - The filter string to apply on other runs in the trace.
1628
+ * @param limit - The maximum number of runs to retrieve.
1629
+ * @returns {AsyncIterable<Run>} - The runs.
1630
+ *
1631
+ * @example
1632
+ * // List all runs in a project
1633
+ * const projectRuns = client.listRuns({ projectName: "<your_project>" });
1634
+ *
1635
+ * @example
1636
+ * // List LLM and Chat runs in the last 24 hours
1637
+ * const todaysLLMRuns = client.listRuns({
1638
+ * projectName: "<your_project>",
1639
+ * start_time: new Date(Date.now() - 24 * 60 * 60 * 1000),
1640
+ * run_type: "llm",
1641
+ * });
1642
+ *
1643
+ * @example
1644
+ * // List traces in a project
1645
+ * const rootRuns = client.listRuns({
1646
+ * projectName: "<your_project>",
1647
+ * execution_order: 1,
1648
+ * });
1649
+ *
1650
+ * @example
1651
+ * // List runs without errors
1652
+ * const correctRuns = client.listRuns({
1653
+ * projectName: "<your_project>",
1654
+ * error: false,
1655
+ * });
1656
+ *
1657
+ * @example
1658
+ * // List runs by run ID
1659
+ * const runIds = [
1660
+ * "a36092d2-4ad5-4fb4-9c0d-0dba9a2ed836",
1661
+ * "9398e6be-964f-4aa4-8ae9-ad78cd4b7074",
1662
+ * ];
1663
+ * const selectedRuns = client.listRuns({ run_ids: runIds });
1664
+ *
1665
+ * @example
1666
+ * // List all "chain" type runs that took more than 10 seconds and had `total_tokens` greater than 5000
1667
+ * const chainRuns = client.listRuns({
1668
+ * projectName: "<your_project>",
1669
+ * filter: 'and(eq(run_type, "chain"), gt(latency, 10), gt(total_tokens, 5000))',
1670
+ * });
1671
+ *
1672
+ * @example
1673
+ * // List all runs called "extractor" whose root of the trace was assigned feedback "user_score" score of 1
1674
+ * const goodExtractorRuns = client.listRuns({
1675
+ * projectName: "<your_project>",
1676
+ * filter: 'eq(name, "extractor")',
1677
+ * traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
1678
+ * });
1679
+ *
1680
+ * @example
1681
+ * // List all runs that started after a specific timestamp and either have "error" not equal to null or a "Correctness" feedback score equal to 0
1682
+ * const complexRuns = client.listRuns({
1683
+ * projectName: "<your_project>",
1684
+ * filter: 'and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(error, null), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))',
1685
+ * });
1686
+ *
1687
+ * @example
1688
+ * // List all runs where `tags` include "experimental" or "beta" and `latency` is greater than 2 seconds
1689
+ * const taggedRuns = client.listRuns({
1690
+ * projectName: "<your_project>",
1691
+ * filter: 'and(or(has(tags, "experimental"), has(tags, "beta")), gt(latency, 2))',
1692
+ * });
1693
+ */
1694
+ listRuns(props: ListRunsParams): AsyncIterable<Run$1>;
1695
+ listGroupRuns(props: GroupRunsParams): AsyncIterable<Thread>;
1696
+ getRunStats({ id, trace, parentRun, runType, projectNames, projectIds, referenceExampleIds, startTime, endTime, error, query, filter, traceFilter, treeFilter, isRoot, dataSourceType, }: {
1697
+ id?: string[];
1698
+ trace?: string;
1699
+ parentRun?: string;
1700
+ runType?: string;
1701
+ projectNames?: string[];
1702
+ projectIds?: string[];
1703
+ referenceExampleIds?: string[];
1704
+ startTime?: string;
1705
+ endTime?: string;
1706
+ error?: boolean;
1707
+ query?: string;
1708
+ filter?: string;
1709
+ traceFilter?: string;
1710
+ treeFilter?: string;
1711
+ isRoot?: boolean;
1712
+ dataSourceType?: string;
1713
+ }): Promise<any>;
1714
+ shareRun(runId: string, { shareId }?: {
1715
+ shareId?: string;
1716
+ }): Promise<string>;
1717
+ unshareRun(runId: string): Promise<void>;
1718
+ readRunSharedLink(runId: string): Promise<string | undefined>;
1719
+ listSharedRuns(shareToken: string, { runIds, }?: {
1720
+ runIds?: string[];
1721
+ }): Promise<Run$1[]>;
1722
+ readDatasetSharedSchema(datasetId?: string, datasetName?: string): Promise<DatasetShareSchema>;
1723
+ shareDataset(datasetId?: string, datasetName?: string): Promise<DatasetShareSchema>;
1724
+ unshareDataset(datasetId: string): Promise<void>;
1725
+ readSharedDataset(shareToken: string): Promise<Dataset>;
1726
+ /**
1727
+ * Get shared examples.
1728
+ *
1729
+ * @param {string} shareToken The share token to get examples for. A share token is the UUID (or LangSmith URL, including UUID) generated when explicitly marking an example as public.
1730
+ * @param {Object} [options] Additional options for listing the examples.
1731
+ * @param {string[] | undefined} [options.exampleIds] A list of example IDs to filter by.
1732
+ * @returns {Promise<Example[]>} The shared examples.
1733
+ */
1734
+ listSharedExamples(shareToken: string, options?: {
1735
+ exampleIds?: string[];
1736
+ }): Promise<Example[]>;
1737
+ createProject({ projectName, description, metadata, upsert, projectExtra, referenceDatasetId, }: CreateProjectParams): Promise<TracerSession>;
1738
+ updateProject(projectId: string, { name, description, metadata, projectExtra, endTime, }: {
1739
+ name?: string | null;
1740
+ description?: string | null;
1741
+ metadata?: RecordStringAny | null;
1742
+ projectExtra?: RecordStringAny | null;
1743
+ endTime?: string | null;
1744
+ }): Promise<TracerSession>;
1745
+ hasProject({ projectId, projectName, }: {
1746
+ projectId?: string;
1747
+ projectName?: string;
1748
+ }): Promise<boolean>;
1749
+ readProject({ projectId, projectName, includeStats, }: {
1750
+ projectId?: string;
1751
+ projectName?: string;
1752
+ includeStats?: boolean;
1753
+ }): Promise<TracerSessionResult>;
1754
+ getProjectUrl({ projectId, projectName, }: {
1755
+ projectId?: string;
1756
+ projectName?: string;
1757
+ }): Promise<string>;
1758
+ getDatasetUrl({ datasetId, datasetName, }: {
1759
+ datasetId?: string;
1760
+ datasetName?: string;
1761
+ }): Promise<string>;
1762
+ private _getTenantId;
1763
+ listProjects({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, referenceFree, metadata, }?: {
1764
+ projectIds?: string[];
1765
+ name?: string;
1766
+ nameContains?: string;
1767
+ referenceDatasetId?: string;
1768
+ referenceDatasetName?: string;
1769
+ referenceFree?: boolean;
1770
+ metadata?: RecordStringAny;
1771
+ }): AsyncIterable<TracerSession>;
1772
+ deleteProject({ projectId, projectName, }: {
1773
+ projectId?: string;
1774
+ projectName?: string;
1775
+ }): Promise<void>;
1776
+ uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, dataType, name, }: UploadCSVParams): Promise<Dataset>;
1777
+ createDataset(name: string, { description, dataType, inputsSchema, outputsSchema, metadata, }?: {
1778
+ description?: string;
1779
+ dataType?: DataType;
1780
+ inputsSchema?: KVMap;
1781
+ outputsSchema?: KVMap;
1782
+ metadata?: RecordStringAny;
1783
+ }): Promise<Dataset>;
1784
+ readDataset({ datasetId, datasetName, }: {
1785
+ datasetId?: string;
1786
+ datasetName?: string;
1787
+ }): Promise<Dataset>;
1788
+ hasDataset({ datasetId, datasetName, }: {
1789
+ datasetId?: string;
1790
+ datasetName?: string;
1791
+ }): Promise<boolean>;
1792
+ diffDatasetVersions({ datasetId, datasetName, fromVersion, toVersion, }: {
1793
+ datasetId?: string;
1794
+ datasetName?: string;
1795
+ fromVersion: string | Date;
1796
+ toVersion: string | Date;
1797
+ }): Promise<DatasetDiffInfo>;
1798
+ readDatasetOpenaiFinetuning({ datasetId, datasetName, }: {
1799
+ datasetId?: string;
1800
+ datasetName?: string;
1801
+ }): Promise<any[]>;
1802
+ listDatasets({ limit, offset, datasetIds, datasetName, datasetNameContains, metadata, }?: {
1803
+ limit?: number;
1804
+ offset?: number;
1805
+ datasetIds?: string[];
1806
+ datasetName?: string;
1807
+ datasetNameContains?: string;
1808
+ metadata?: RecordStringAny;
1809
+ }): AsyncIterable<Dataset>;
1810
+ /**
1811
+ * Update a dataset
1812
+ * @param props The dataset details to update
1813
+ * @returns The updated dataset
1814
+ */
1815
+ updateDataset(props: {
1816
+ datasetId?: string;
1817
+ datasetName?: string;
1818
+ name?: string;
1819
+ description?: string;
1820
+ }): Promise<Dataset>;
1821
+ /**
1822
+ * Updates a tag on a dataset.
1823
+ *
1824
+ * If the tag is already assigned to a different version of this dataset,
1825
+ * the tag will be moved to the new version. The as_of parameter is used to
1826
+ * determine which version of the dataset to apply the new tags to.
1827
+ *
1828
+ * It must be an exact version of the dataset to succeed. You can
1829
+ * use the "readDatasetVersion" method to find the exact version
1830
+ * to apply the tags to.
1831
+ * @param params.datasetId The ID of the dataset to update. Must be provided if "datasetName" is not provided.
1832
+ * @param params.datasetName The name of the dataset to update. Must be provided if "datasetId" is not provided.
1833
+ * @param params.asOf The timestamp of the dataset to apply the new tags to.
1834
+ * @param params.tag The new tag to apply to the dataset.
1835
+ */
1836
+ updateDatasetTag(props: {
1837
+ datasetId?: string;
1838
+ datasetName?: string;
1839
+ asOf: string | Date;
1840
+ tag: string;
1841
+ }): Promise<void>;
1842
+ deleteDataset({ datasetId, datasetName, }: {
1843
+ datasetId?: string;
1844
+ datasetName?: string;
1845
+ }): Promise<void>;
1846
+ indexDataset({ datasetId, datasetName, tag, }: {
1847
+ datasetId?: string;
1848
+ datasetName?: string;
1849
+ tag?: string;
1850
+ }): Promise<void>;
1851
+ /**
1852
+ * Lets you run a similarity search query on a dataset.
1853
+ *
1854
+ * Requires the dataset to be indexed. Please see the `indexDataset` method to set up indexing.
1855
+ *
1856
+ * @param inputs The input on which to run the similarity search. Must have the
1857
+ * same schema as the dataset.
1858
+ *
1859
+ * @param datasetId The dataset to search for similar examples.
1860
+ *
1861
+ * @param limit The maximum number of examples to return. Will return the top `limit` most
1862
+ * similar examples in order of most similar to least similar. If no similar
1863
+ * examples are found, random examples will be returned.
1864
+ *
1865
+ * @param filter A filter string to apply to the search. Only examples will be returned that
1866
+ * match the filter string. Some examples of filters
1867
+ *
1868
+ * - eq(metadata.mykey, "value")
1869
+ * - and(neq(metadata.my.nested.key, "value"), neq(metadata.mykey, "value"))
1870
+ * - or(eq(metadata.mykey, "value"), eq(metadata.mykey, "othervalue"))
1871
+ *
1872
+ * @returns A list of similar examples.
1873
+ *
1874
+ *
1875
+ * @example
1876
+ * dataset_id = "123e4567-e89b-12d3-a456-426614174000"
1877
+ * inputs = {"text": "How many people live in Berlin?"}
1878
+ * limit = 5
1879
+ * examples = await client.similarExamples(inputs, dataset_id, limit)
1880
+ */
1881
+ similarExamples(inputs: KVMap, datasetId: string, limit: number, { filter, }?: {
1882
+ filter?: string;
1883
+ }): Promise<ExampleSearch[]>;
1884
+ createExample(update: ExampleCreate): Promise<Example>;
1885
+ /**
1886
+ * @deprecated This signature is deprecated, use createExample(update: ExampleCreate) instead
1887
+ */
1888
+ createExample(inputs: KVMap, outputs: KVMap, options: CreateExampleOptions): Promise<Example>;
1889
+ createExamples(uploads: ExampleCreate[]): Promise<Example[]>;
1890
+ /** @deprecated Use the uploads-only overload instead */
1891
+ createExamples(props: {
1892
+ inputs?: Array<KVMap>;
1893
+ outputs?: Array<KVMap>;
1894
+ metadata?: Array<KVMap>;
1895
+ splits?: Array<string | Array<string>>;
1896
+ sourceRunIds?: Array<string>;
1897
+ useSourceRunIOs?: Array<boolean>;
1898
+ useSourceRunAttachments?: Array<string[]>;
1899
+ attachments?: Array<Attachments>;
1900
+ exampleIds?: Array<string>;
1901
+ datasetId?: string;
1902
+ datasetName?: string;
1903
+ }): Promise<Example[]>;
1904
+ createLLMExample(input: string, generation: string | undefined, options: CreateExampleOptions): Promise<Example>;
1905
+ createChatExample(input: KVMap[] | LangChainBaseMessage[], generations: KVMap | LangChainBaseMessage | undefined, options: CreateExampleOptions): Promise<Example>;
1906
+ readExample(exampleId: string): Promise<Example>;
1907
+ listExamples({ datasetId, datasetName, exampleIds, asOf, splits, inlineS3Urls, metadata, limit, offset, filter, includeAttachments, }?: {
1908
+ datasetId?: string;
1909
+ datasetName?: string;
1910
+ exampleIds?: string[];
1911
+ asOf?: string | Date;
1912
+ splits?: string[];
1913
+ inlineS3Urls?: boolean;
1914
+ metadata?: KVMap;
1915
+ limit?: number;
1916
+ offset?: number;
1917
+ filter?: string;
1918
+ includeAttachments?: boolean;
1919
+ }): AsyncIterable<Example>;
1920
+ deleteExample(exampleId: string): Promise<void>;
1921
+ /**
1922
+ * @deprecated This signature is deprecated, use updateExample(update: ExampleUpdate) instead
1923
+ */
1924
+ updateExample(exampleId: string, update: ExampleUpdateWithoutId): Promise<object>;
1925
+ updateExample(update: ExampleUpdate): Promise<object>;
1926
+ updateExamples(update: ExampleUpdate[]): Promise<object>;
1927
+ /**
1928
+ * Get dataset version by closest date or exact tag.
1929
+ *
1930
+ * Use this to resolve the nearest version to a given timestamp or for a given tag.
1931
+ *
1932
+ * @param options The options for getting the dataset version
1933
+ * @param options.datasetId The ID of the dataset
1934
+ * @param options.datasetName The name of the dataset
1935
+ * @param options.asOf The timestamp of the dataset to retrieve
1936
+ * @param options.tag The tag of the dataset to retrieve
1937
+ * @returns The dataset version
1938
+ */
1939
+ readDatasetVersion({ datasetId, datasetName, asOf, tag, }: {
1940
+ datasetId?: string;
1941
+ datasetName?: string;
1942
+ asOf?: string | Date;
1943
+ tag?: string;
1944
+ }): Promise<DatasetVersion>;
1945
+ listDatasetSplits({ datasetId, datasetName, asOf, }: {
1946
+ datasetId?: string;
1947
+ datasetName?: string;
1948
+ asOf?: string | Date;
1949
+ }): Promise<string[]>;
1950
+ updateDatasetSplits({ datasetId, datasetName, splitName, exampleIds, remove, }: {
1951
+ datasetId?: string;
1952
+ datasetName?: string;
1953
+ splitName: string;
1954
+ exampleIds: string[];
1955
+ remove?: boolean;
1956
+ }): Promise<void>;
1957
+ /**
1958
+ * @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
1959
+ */
1960
+ evaluateRun(run: Run$1 | string, evaluator: RunEvaluator, { sourceInfo, loadChildRuns, referenceExample, }?: {
1961
+ sourceInfo?: KVMap;
1962
+ loadChildRuns: boolean;
1963
+ referenceExample?: Example;
1964
+ }): Promise<Feedback>;
1965
+ createFeedback(runId: string | null, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, }: {
1966
+ score?: ScoreType;
1967
+ value?: ValueType;
1968
+ correction?: object;
1969
+ comment?: string;
1970
+ sourceInfo?: object;
1971
+ feedbackSourceType?: FeedbackSourceType;
1972
+ feedbackConfig?: FeedbackConfig;
1973
+ sourceRunId?: string;
1974
+ feedbackId?: string;
1975
+ eager?: boolean;
1976
+ projectId?: string;
1977
+ comparativeExperimentId?: string;
1978
+ }): Promise<Feedback>;
1979
+ updateFeedback(feedbackId: string, { score, value, correction, comment, }: {
1980
+ score?: number | boolean | null;
1981
+ value?: number | boolean | string | object | null;
1982
+ correction?: object | null;
1983
+ comment?: string | null;
1984
+ }): Promise<void>;
1985
+ readFeedback(feedbackId: string): Promise<Feedback>;
1986
+ deleteFeedback(feedbackId: string): Promise<void>;
1987
+ listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, }?: {
1988
+ runIds?: string[];
1989
+ feedbackKeys?: string[];
1990
+ feedbackSourceTypes?: FeedbackSourceType[];
1991
+ }): AsyncIterable<Feedback>;
1992
+ /**
1993
+ * Creates a presigned feedback token and URL.
1994
+ *
1995
+ * The token can be used to authorize feedback metrics without
1996
+ * needing an API key. This is useful for giving browser-based
1997
+ * applications the ability to submit feedback without needing
1998
+ * to expose an API key.
1999
+ *
2000
+ * @param runId The ID of the run.
2001
+ * @param feedbackKey The feedback key.
2002
+ * @param options Additional options for the token.
2003
+ * @param options.expiration The expiration time for the token.
2004
+ *
2005
+ * @returns A promise that resolves to a FeedbackIngestToken.
2006
+ */
2007
+ createPresignedFeedbackToken(runId: string, feedbackKey: string, { expiration, feedbackConfig, }?: {
2008
+ expiration?: string | TimeDelta;
2009
+ feedbackConfig?: FeedbackConfig;
2010
+ }): Promise<FeedbackIngestToken>;
2011
+ createComparativeExperiment({ name, experimentIds, referenceDatasetId, createdAt, description, metadata, id, }: {
2012
+ name: string;
2013
+ experimentIds: Array<string>;
2014
+ referenceDatasetId?: string;
2015
+ createdAt?: Date;
2016
+ description?: string;
2017
+ metadata?: Record<string, unknown>;
2018
+ id?: string;
2019
+ }): Promise<ComparativeExperiment>;
2020
+ /**
2021
+ * Retrieves a list of presigned feedback tokens for a given run ID.
2022
+ * @param runId The ID of the run.
2023
+ * @returns An async iterable of FeedbackIngestToken objects.
2024
+ */
2025
+ listPresignedFeedbackTokens(runId: string): AsyncIterable<FeedbackIngestToken>;
2026
+ _selectEvalResults(results: EvaluationResult | EvaluationResult[] | EvaluationResults): Array<EvaluationResult>;
2027
+ _logEvaluationFeedback(evaluatorResponse: EvaluationResult | EvaluationResult[] | EvaluationResults, run?: Run$1, sourceInfo?: {
2028
+ [key: string]: any;
2029
+ }): Promise<[results: EvaluationResult[], feedbacks: Feedback[]]>;
2030
+ logEvaluationFeedback(evaluatorResponse: EvaluationResult | EvaluationResult[] | EvaluationResults, run?: Run$1, sourceInfo?: {
2031
+ [key: string]: any;
2032
+ }): Promise<EvaluationResult[]>;
2033
+ /**
2034
+ * API for managing annotation queues
2035
+ */
2036
+ /**
2037
+ * List the annotation queues on the LangSmith API.
2038
+ * @param options - The options for listing annotation queues
2039
+ * @param options.queueIds - The IDs of the queues to filter by
2040
+ * @param options.name - The name of the queue to filter by
2041
+ * @param options.nameContains - The substring that the queue name should contain
2042
+ * @param options.limit - The maximum number of queues to return
2043
+ * @returns An iterator of AnnotationQueue objects
2044
+ */
2045
+ listAnnotationQueues(options?: {
2046
+ queueIds?: string[];
2047
+ name?: string;
2048
+ nameContains?: string;
2049
+ limit?: number;
2050
+ }): AsyncIterableIterator<AnnotationQueue>;
2051
+ /**
2052
+ * Create an annotation queue on the LangSmith API.
2053
+ * @param options - The options for creating an annotation queue
2054
+ * @param options.name - The name of the annotation queue
2055
+ * @param options.description - The description of the annotation queue
2056
+ * @param options.queueId - The ID of the annotation queue
2057
+ * @returns The created AnnotationQueue object
2058
+ */
2059
+ createAnnotationQueue(options: {
2060
+ name: string;
2061
+ description?: string;
2062
+ queueId?: string;
2063
+ rubricInstructions?: string;
2064
+ }): Promise<AnnotationQueueWithDetails>;
2065
+ /**
2066
+ * Read an annotation queue with the specified queue ID.
2067
+ * @param queueId - The ID of the annotation queue to read
2068
+ * @returns The AnnotationQueueWithDetails object
2069
+ */
2070
+ readAnnotationQueue(queueId: string): Promise<AnnotationQueueWithDetails>;
2071
+ /**
2072
+ * Update an annotation queue with the specified queue ID.
2073
+ * @param queueId - The ID of the annotation queue to update
2074
+ * @param options - The options for updating the annotation queue
2075
+ * @param options.name - The new name for the annotation queue
2076
+ * @param options.description - The new description for the annotation queue
2077
+ */
2078
+ updateAnnotationQueue(queueId: string, options: {
2079
+ name: string;
2080
+ description?: string;
2081
+ rubricInstructions?: string;
2082
+ }): Promise<void>;
2083
+ /**
2084
+ * Delete an annotation queue with the specified queue ID.
2085
+ * @param queueId - The ID of the annotation queue to delete
671
2086
  */
672
- dotted_order?: string;
2087
+ deleteAnnotationQueue(queueId: string): Promise<void>;
673
2088
  /**
674
- * Attachments associated with the run.
675
- * Each entry is a tuple of [mime_type, bytes]
2089
+ * Add runs to an annotation queue with the specified queue ID.
2090
+ * @param queueId - The ID of the annotation queue
2091
+ * @param runIds - The IDs of the runs to be added to the annotation queue
676
2092
  */
677
- attachments?: Attachments;
2093
+ addRunsToAnnotationQueue(queueId: string, runIds: string[]): Promise<void>;
2094
+ /**
2095
+ * Get a run from an annotation queue at the specified index.
2096
+ * @param queueId - The ID of the annotation queue
2097
+ * @param index - The index of the run to retrieve
2098
+ * @returns A Promise that resolves to a RunWithAnnotationQueueInfo object
2099
+ * @throws {Error} If the run is not found at the given index or for other API-related errors
2100
+ */
2101
+ getRunFromAnnotationQueue(queueId: string, index: number): Promise<RunWithAnnotationQueueInfo>;
2102
+ /**
2103
+ * Delete a run from an an annotation queue.
2104
+ * @param queueId - The ID of the annotation queue to delete the run from
2105
+ * @param queueRunId - The ID of the run to delete from the annotation queue
2106
+ */
2107
+ deleteRunFromAnnotationQueue(queueId: string, queueRunId: string): Promise<void>;
2108
+ /**
2109
+ * Get the size of an annotation queue.
2110
+ * @param queueId - The ID of the annotation queue
2111
+ */
2112
+ getSizeFromAnnotationQueue(queueId: string): Promise<{
2113
+ size: number;
2114
+ }>;
2115
+ protected _currentTenantIsOwner(owner: string): Promise<boolean>;
2116
+ protected _ownerConflictError(action: string, owner: string): Promise<Error>;
2117
+ protected _getLatestCommitHash(promptOwnerAndName: string): Promise<string | undefined>;
2118
+ protected _likeOrUnlikePrompt(promptIdentifier: string, like: boolean): Promise<LikePromptResponse>;
2119
+ protected _getPromptUrl(promptIdentifier: string): Promise<string>;
2120
+ promptExists(promptIdentifier: string): Promise<boolean>;
2121
+ likePrompt(promptIdentifier: string): Promise<LikePromptResponse>;
2122
+ unlikePrompt(promptIdentifier: string): Promise<LikePromptResponse>;
2123
+ listCommits(promptOwnerAndName: string): AsyncIterableIterator<PromptCommit>;
2124
+ listPrompts(options?: {
2125
+ isPublic?: boolean;
2126
+ isArchived?: boolean;
2127
+ sortField?: PromptSortField;
2128
+ query?: string;
2129
+ }): AsyncIterableIterator<Prompt>;
2130
+ getPrompt(promptIdentifier: string): Promise<Prompt | null>;
2131
+ createPrompt(promptIdentifier: string, options?: {
2132
+ description?: string;
2133
+ readme?: string;
2134
+ tags?: string[];
2135
+ isPublic?: boolean;
2136
+ }): Promise<Prompt>;
2137
+ createCommit(promptIdentifier: string, object: any, options?: {
2138
+ parentCommitHash?: string;
2139
+ }): Promise<string>;
2140
+ /**
2141
+ * Update examples with attachments using multipart form data.
2142
+ * @param updates List of ExampleUpdateWithAttachments objects to upsert
2143
+ * @returns Promise with the update response
2144
+ */
2145
+ updateExamplesMultipart(datasetId: string, updates?: ExampleUpdate[]): Promise<UpdateExamplesResponse>;
2146
+ private _updateExamplesMultipart;
2147
+ /**
2148
+ * Upload examples with attachments using multipart form data.
2149
+ * @param uploads List of ExampleUploadWithAttachments objects to upload
2150
+ * @returns Promise with the upload response
2151
+ * @deprecated This method is deprecated and will be removed in future LangSmith versions, please use `createExamples` instead
2152
+ */
2153
+ uploadExamplesMultipart(datasetId: string, uploads?: ExampleCreate[]): Promise<UploadExamplesResponse>;
2154
+ private _uploadExamplesMultipart;
2155
+ updatePrompt(promptIdentifier: string, options?: {
2156
+ description?: string;
2157
+ readme?: string;
2158
+ tags?: string[];
2159
+ isPublic?: boolean;
2160
+ isArchived?: boolean;
2161
+ }): Promise<Record<string, any>>;
2162
+ deletePrompt(promptIdentifier: string): Promise<void>;
2163
+ pullPromptCommit(promptIdentifier: string, options?: {
2164
+ includeModel?: boolean;
2165
+ }): Promise<PromptCommit>;
2166
+ /**
2167
+ * This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
2168
+ * Using this method directly returns the JSON string of the prompt rather than a LangChain object.
2169
+ * @private
2170
+ */
2171
+ _pullPrompt(promptIdentifier: string, options?: {
2172
+ includeModel?: boolean;
2173
+ }): Promise<any>;
2174
+ pushPrompt(promptIdentifier: string, options?: {
2175
+ object?: any;
2176
+ parentCommitHash?: string;
2177
+ isPublic?: boolean;
2178
+ description?: string;
2179
+ readme?: string;
2180
+ tags?: string[];
2181
+ }): Promise<string>;
2182
+ /**
2183
+ * Clone a public dataset to your own langsmith tenant.
2184
+ * This operation is idempotent. If you already have a dataset with the given name,
2185
+ * this function will do nothing.
2186
+
2187
+ * @param {string} tokenOrUrl The token of the public dataset to clone.
2188
+ * @param {Object} [options] Additional options for cloning the dataset.
2189
+ * @param {string} [options.sourceApiUrl] The URL of the langsmith server where the data is hosted. Defaults to the API URL of your current client.
2190
+ * @param {string} [options.datasetName] The name of the dataset to create in your tenant. Defaults to the name of the public dataset.
2191
+ * @returns {Promise<void>}
2192
+ */
2193
+ clonePublicDataset(tokenOrUrl: string, options?: {
2194
+ sourceApiUrl?: string;
2195
+ datasetName?: string;
2196
+ }): Promise<void>;
2197
+ private parseTokenOrUrl;
2198
+ /**
2199
+ * Awaits all pending trace batches. Useful for environments where
2200
+ * you need to be sure that all tracing requests finish before execution ends,
2201
+ * such as serverless environments.
2202
+ *
2203
+ * @example
2204
+ * ```
2205
+ * import { Client } from "langsmith";
2206
+ *
2207
+ * const client = new Client();
2208
+ *
2209
+ * try {
2210
+ * // Tracing happens here
2211
+ * ...
2212
+ * } finally {
2213
+ * await client.awaitPendingTraceBatches();
2214
+ * }
2215
+ * ```
2216
+ *
2217
+ * @returns A promise that resolves once all currently pending traces have sent.
2218
+ */
2219
+ awaitPendingTraceBatches(): Promise<void>;
2220
+ }
2221
+ interface LangSmithTracingClientInterface {
2222
+ createRun: (run: CreateRunParams) => Promise<void>;
2223
+ updateRun: (runId: string, run: RunUpdate) => Promise<void>;
678
2224
  }
679
2225
 
680
2226
  interface Run extends BaseRun {
681
2227
  id: string;
682
2228
  start_time: number;
2229
+ end_time?: number;
683
2230
  execution_order: number;
684
2231
  child_runs: this[];
685
2232
  child_execution_order: number;
@@ -690,39 +2237,47 @@ interface Run extends BaseRun {
690
2237
  }>;
691
2238
  trace_id?: string;
692
2239
  dotted_order?: string;
2240
+ /** @internal */
2241
+ _serialized_start_time?: string;
693
2242
  }
694
2243
  declare abstract class BaseTracer extends BaseCallbackHandler {
2244
+ /** @deprecated Use `runTreeMap` instead. */
695
2245
  protected runMap: Map<string, Run>;
2246
+ protected runTreeMap: Map<string, RunTree>;
2247
+ protected usesRunTreeMap: boolean;
696
2248
  constructor(_fields?: BaseCallbackHandlerInput);
697
2249
  copy(): this;
2250
+ protected getRunById(runId?: string): Run | undefined;
698
2251
  protected stringifyError(error: unknown): string;
699
2252
  protected abstract persistRun(run: Run): Promise<void>;
700
2253
  protected _addChildRun(parentRun: Run, childRun: Run): void;
701
2254
  _addRunToRunMap(run: Run): {
702
2255
  id: string;
703
2256
  start_time: number;
2257
+ end_time?: number;
704
2258
  execution_order: number;
705
2259
  child_runs: Run[];
706
2260
  child_execution_order: number;
707
- events: {
2261
+ events: Array<{
708
2262
  name: string;
709
2263
  time: string;
710
- kwargs?: Record<string, unknown> | undefined;
711
- }[];
712
- trace_id?: string | undefined;
713
- dotted_order?: string | undefined;
2264
+ kwargs?: Record<string, unknown>;
2265
+ }>;
2266
+ trace_id?: string;
2267
+ dotted_order?: string;
2268
+ /** @internal */
2269
+ _serialized_start_time?: string;
714
2270
  name: string;
715
2271
  run_type: string;
716
- end_time?: number | undefined;
717
- extra?: KVMap | undefined;
718
- error?: string | undefined;
719
- serialized?: object | undefined;
2272
+ extra?: KVMap;
2273
+ error?: string;
2274
+ serialized?: object;
720
2275
  inputs: KVMap;
721
- outputs?: KVMap | undefined;
722
- reference_example_id?: string | undefined;
723
- parent_run_id?: string | undefined;
724
- tags?: string[] | undefined;
725
- attachments?: Attachments | undefined;
2276
+ outputs?: KVMap;
2277
+ reference_example_id?: string;
2278
+ parent_run_id?: string;
2279
+ tags?: string[];
2280
+ attachments?: Attachments;
726
2281
  };
727
2282
  protected _endTrace(run: Run): Promise<void>;
728
2283
  protected _getExecutionOrder(parentRunId: string | undefined): number;
@@ -734,28 +2289,30 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
734
2289
  _createRunForLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): {
735
2290
  id: string;
736
2291
  start_time: number;
2292
+ end_time?: number;
737
2293
  execution_order: number;
738
2294
  child_runs: Run[];
739
2295
  child_execution_order: number;
740
- events: {
2296
+ events: Array<{
741
2297
  name: string;
742
2298
  time: string;
743
- kwargs?: Record<string, unknown> | undefined;
744
- }[];
745
- trace_id?: string | undefined;
746
- dotted_order?: string | undefined;
2299
+ kwargs?: Record<string, unknown>;
2300
+ }>;
2301
+ trace_id?: string;
2302
+ dotted_order?: string;
2303
+ /** @internal */
2304
+ _serialized_start_time?: string;
747
2305
  name: string;
748
2306
  run_type: string;
749
- end_time?: number | undefined;
750
- extra?: KVMap | undefined;
751
- error?: string | undefined;
752
- serialized?: object | undefined;
2307
+ extra?: KVMap;
2308
+ error?: string;
2309
+ serialized?: object;
753
2310
  inputs: KVMap;
754
- outputs?: KVMap | undefined;
755
- reference_example_id?: string | undefined;
756
- parent_run_id?: string | undefined;
757
- tags?: string[] | undefined;
758
- attachments?: Attachments | undefined;
2311
+ outputs?: KVMap;
2312
+ reference_example_id?: string;
2313
+ parent_run_id?: string;
2314
+ tags?: string[];
2315
+ attachments?: Attachments;
759
2316
  };
760
2317
  handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
761
2318
  /**
@@ -766,28 +2323,30 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
766
2323
  _createRunForChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): {
767
2324
  id: string;
768
2325
  start_time: number;
2326
+ end_time?: number;
769
2327
  execution_order: number;
770
2328
  child_runs: Run[];
771
2329
  child_execution_order: number;
772
- events: {
2330
+ events: Array<{
773
2331
  name: string;
774
2332
  time: string;
775
- kwargs?: Record<string, unknown> | undefined;
776
- }[];
777
- trace_id?: string | undefined;
778
- dotted_order?: string | undefined;
2333
+ kwargs?: Record<string, unknown>;
2334
+ }>;
2335
+ trace_id?: string;
2336
+ dotted_order?: string;
2337
+ /** @internal */
2338
+ _serialized_start_time?: string;
779
2339
  name: string;
780
2340
  run_type: string;
781
- end_time?: number | undefined;
782
- extra?: KVMap | undefined;
783
- error?: string | undefined;
784
- serialized?: object | undefined;
2341
+ extra?: KVMap;
2342
+ error?: string;
2343
+ serialized?: object;
785
2344
  inputs: KVMap;
786
- outputs?: KVMap | undefined;
787
- reference_example_id?: string | undefined;
788
- parent_run_id?: string | undefined;
789
- tags?: string[] | undefined;
790
- attachments?: Attachments | undefined;
2345
+ outputs?: KVMap;
2346
+ reference_example_id?: string;
2347
+ parent_run_id?: string;
2348
+ tags?: string[];
2349
+ attachments?: Attachments;
791
2350
  };
792
2351
  handleChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
793
2352
  handleLLMEnd(output: LLMResult, runId: string, _parentRunId?: string, _tags?: string[], extraParams?: Record<string, unknown>): Promise<Run>;
@@ -800,28 +2359,30 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
800
2359
  _createRunForChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, runType?: string, name?: string): {
801
2360
  id: string;
802
2361
  start_time: number;
2362
+ end_time?: number;
803
2363
  execution_order: number;
804
2364
  child_runs: Run[];
805
2365
  child_execution_order: number;
806
- events: {
2366
+ events: Array<{
807
2367
  name: string;
808
2368
  time: string;
809
- kwargs?: Record<string, unknown> | undefined;
810
- }[];
811
- trace_id?: string | undefined;
812
- dotted_order?: string | undefined;
2369
+ kwargs?: Record<string, unknown>;
2370
+ }>;
2371
+ trace_id?: string;
2372
+ dotted_order?: string;
2373
+ /** @internal */
2374
+ _serialized_start_time?: string;
813
2375
  name: string;
814
2376
  run_type: string;
815
- end_time?: number | undefined;
816
- extra?: KVMap | undefined;
817
- error?: string | undefined;
818
- serialized?: object | undefined;
2377
+ extra?: KVMap;
2378
+ error?: string;
2379
+ serialized?: object;
819
2380
  inputs: KVMap;
820
- outputs?: KVMap | undefined;
821
- reference_example_id?: string | undefined;
822
- parent_run_id?: string | undefined;
823
- tags?: string[] | undefined;
824
- attachments?: Attachments | undefined;
2381
+ outputs?: KVMap;
2382
+ reference_example_id?: string;
2383
+ parent_run_id?: string;
2384
+ tags?: string[];
2385
+ attachments?: Attachments;
825
2386
  };
826
2387
  handleChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, runType?: string, name?: string): Promise<Run>;
827
2388
  handleChainEnd(outputs: ChainValues, runId: string, _parentRunId?: string, _tags?: string[], kwargs?: {
@@ -838,28 +2399,30 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
838
2399
  _createRunForToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): {
839
2400
  id: string;
840
2401
  start_time: number;
2402
+ end_time?: number;
841
2403
  execution_order: number;
842
2404
  child_runs: Run[];
843
2405
  child_execution_order: number;
844
- events: {
2406
+ events: Array<{
845
2407
  name: string;
846
2408
  time: string;
847
- kwargs?: Record<string, unknown> | undefined;
848
- }[];
849
- trace_id?: string | undefined;
850
- dotted_order?: string | undefined;
2409
+ kwargs?: Record<string, unknown>;
2410
+ }>;
2411
+ trace_id?: string;
2412
+ dotted_order?: string;
2413
+ /** @internal */
2414
+ _serialized_start_time?: string;
851
2415
  name: string;
852
2416
  run_type: string;
853
- end_time?: number | undefined;
854
- extra?: KVMap | undefined;
855
- error?: string | undefined;
856
- serialized?: object | undefined;
2417
+ extra?: KVMap;
2418
+ error?: string;
2419
+ serialized?: object;
857
2420
  inputs: KVMap;
858
- outputs?: KVMap | undefined;
859
- reference_example_id?: string | undefined;
860
- parent_run_id?: string | undefined;
861
- tags?: string[] | undefined;
862
- attachments?: Attachments | undefined;
2421
+ outputs?: KVMap;
2422
+ reference_example_id?: string;
2423
+ parent_run_id?: string;
2424
+ tags?: string[];
2425
+ attachments?: Attachments;
863
2426
  };
864
2427
  handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
865
2428
  handleToolEnd(output: any, runId: string): Promise<Run>;
@@ -874,28 +2437,30 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
874
2437
  _createRunForRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): {
875
2438
  id: string;
876
2439
  start_time: number;
2440
+ end_time?: number;
877
2441
  execution_order: number;
878
2442
  child_runs: Run[];
879
2443
  child_execution_order: number;
880
- events: {
2444
+ events: Array<{
881
2445
  name: string;
882
2446
  time: string;
883
- kwargs?: Record<string, unknown> | undefined;
884
- }[];
885
- trace_id?: string | undefined;
886
- dotted_order?: string | undefined;
2447
+ kwargs?: Record<string, unknown>;
2448
+ }>;
2449
+ trace_id?: string;
2450
+ dotted_order?: string;
2451
+ /** @internal */
2452
+ _serialized_start_time?: string;
887
2453
  name: string;
888
2454
  run_type: string;
889
- end_time?: number | undefined;
890
- extra?: KVMap | undefined;
891
- error?: string | undefined;
892
- serialized?: object | undefined;
2455
+ extra?: KVMap;
2456
+ error?: string;
2457
+ serialized?: object;
893
2458
  inputs: KVMap;
894
- outputs?: KVMap | undefined;
895
- reference_example_id?: string | undefined;
896
- parent_run_id?: string | undefined;
897
- tags?: string[] | undefined;
898
- attachments?: Attachments | undefined;
2459
+ outputs?: KVMap;
2460
+ reference_example_id?: string;
2461
+ parent_run_id?: string;
2462
+ tags?: string[];
2463
+ attachments?: Attachments;
899
2464
  };
900
2465
  handleRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
901
2466
  handleRetrieverEnd(documents: Document<Record<string, unknown>>[], runId: string): Promise<Run>;
@@ -1020,7 +2585,7 @@ declare class CallbackManagerForToolRun extends BaseRunManager implements BaseCa
1020
2585
  *
1021
2586
  * // Example of using LLMChain with OpenAI and a simple prompt
1022
2587
  * const chain = new LLMChain({
1023
- * llm: new ChatOpenAI({ temperature: 0.9 }),
2588
+ * llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0.9 }),
1024
2589
  * prompt,
1025
2590
  * });
1026
2591
  *
@@ -1073,6 +2638,89 @@ declare class CallbackManager extends BaseCallbackManager implements BaseCallbac
1073
2638
  static _configureSync(inheritableHandlers?: Callbacks, localHandlers?: Callbacks, inheritableTags?: string[], localTags?: string[], inheritableMetadata?: Record<string, unknown>, localMetadata?: Record<string, unknown>, options?: CallbackManagerOptions): CallbackManager | undefined;
1074
2639
  }
1075
2640
 
2641
+ interface BaseDataContentBlock {
2642
+ mime_type?: string;
2643
+ metadata?: Record<string, unknown>;
2644
+ }
2645
+ interface URLContentBlock extends BaseDataContentBlock {
2646
+ type: "image" | "audio" | "file";
2647
+ source_type: "url";
2648
+ url: string;
2649
+ }
2650
+ interface Base64ContentBlock extends BaseDataContentBlock {
2651
+ type: "image" | "audio" | "file";
2652
+ source_type: "base64";
2653
+ data: string;
2654
+ }
2655
+ interface PlainTextContentBlock extends BaseDataContentBlock {
2656
+ type: "file" | "text";
2657
+ source_type: "text";
2658
+ text: string;
2659
+ }
2660
+ interface IDContentBlock extends BaseDataContentBlock {
2661
+ type: "image" | "audio" | "file";
2662
+ source_type: "id";
2663
+ id: string;
2664
+ }
2665
+ type DataContentBlock = URLContentBlock | Base64ContentBlock | PlainTextContentBlock | IDContentBlock;
2666
+
2667
+ interface ToolMessageFields extends BaseMessageFields {
2668
+ content: string | (MessageContentComplex | DataContentBlock)[];
2669
+ }
2670
+ interface ToolMessageFieldsWithToolCallId extends ToolMessageFields {
2671
+ /**
2672
+ * Artifact of the Tool execution which is not meant to be sent to the model.
2673
+ *
2674
+ * Should only be specified if it is different from the message content, e.g. if only
2675
+ * a subset of the full tool output is being passed as message content but the full
2676
+ * output is needed in other parts of the code.
2677
+ */
2678
+ artifact?: any;
2679
+ tool_call_id: string;
2680
+ /**
2681
+ * Status of the tool invocation.
2682
+ * @version 0.2.19
2683
+ */
2684
+ status?: "success" | "error";
2685
+ }
2686
+ /**
2687
+ * Marker parameter for objects that tools can return directly.
2688
+ *
2689
+ * If a custom BaseTool is invoked with a ToolCall and the output of custom code is
2690
+ * not an instance of DirectToolOutput, the output will automatically be coerced to
2691
+ * a string and wrapped in a ToolMessage.
2692
+ */
2693
+ interface DirectToolOutput {
2694
+ readonly lc_direct_tool_output: true;
2695
+ }
2696
+ /**
2697
+ * Represents a tool message in a conversation.
2698
+ */
2699
+ declare class ToolMessage extends BaseMessage implements DirectToolOutput {
2700
+ content: string | (MessageContentComplex | DataContentBlock)[];
2701
+ static lc_name(): string;
2702
+ get lc_aliases(): Record<string, string>;
2703
+ lc_direct_tool_output: true;
2704
+ /**
2705
+ * Status of the tool invocation.
2706
+ * @version 0.2.19
2707
+ */
2708
+ status?: "success" | "error";
2709
+ tool_call_id: string;
2710
+ /**
2711
+ * Artifact of the Tool execution which is not meant to be sent to the model.
2712
+ *
2713
+ * Should only be specified if it is different from the message content, e.g. if only
2714
+ * a subset of the full tool output is being passed as message content but the full
2715
+ * output is needed in other parts of the code.
2716
+ */
2717
+ artifact?: any;
2718
+ constructor(fields: ToolMessageFieldsWithToolCallId);
2719
+ constructor(fields: string | ToolMessageFields, tool_call_id: string, name?: string);
2720
+ _getType(): MessageType;
2721
+ static isInstance(message: BaseMessage): message is ToolMessage;
2722
+ get _printableFields(): Record<string, unknown>;
2723
+ }
1076
2724
  /**
1077
2725
  * A call to a tool.
1078
2726
  * @property {string} name - The name of the tool to be called
@@ -1095,7 +2743,7 @@ type RunnableBatchOptions = {
1095
2743
  };
1096
2744
  type RunnableIOSchema = {
1097
2745
  name?: string;
1098
- schema: z.ZodType;
2746
+ schema: InteropZodType;
1099
2747
  };
1100
2748
  /**
1101
2749
  * Base interface implemented by all runnables.
@@ -1458,16 +3106,21 @@ declare abstract class Runnable<RunInput = any, RunOutput = any, CallOptions ext
1458
3106
  * Bind arguments to a Runnable, returning a new Runnable.
1459
3107
  * @param kwargs
1460
3108
  * @returns A new RunnableBinding that, when invoked, will apply the bound args.
3109
+ *
3110
+ * @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
1461
3111
  */
1462
3112
  bind(kwargs: Partial<CallOptions>): Runnable<RunInput, RunOutput, CallOptions>;
1463
3113
  /**
1464
3114
  * Return a new Runnable that maps a list of inputs to a list of outputs,
1465
3115
  * by calling invoke() with each input.
3116
+ *
3117
+ * @deprecated This will be removed in the next breaking release.
1466
3118
  */
1467
3119
  map(): Runnable<RunInput[], RunOutput[], CallOptions>;
1468
3120
  /**
1469
3121
  * Add retry logic to an existing runnable.
1470
- * @param kwargs
3122
+ * @param fields.stopAfterAttempt The number of attempts to retry.
3123
+ * @param fields.onFailedAttempt A function that is called when a retry fails.
1471
3124
  * @returns A new RunnableRetry that, when invoked, will retry according to the parameters.
1472
3125
  */
1473
3126
  withRetry(fields?: {
@@ -1479,7 +3132,7 @@ declare abstract class Runnable<RunInput = any, RunOutput = any, CallOptions ext
1479
3132
  * @param config New configuration parameters to attach to the new runnable.
1480
3133
  * @returns A new RunnableBinding with a config matching what's passed.
1481
3134
  */
1482
- withConfig(config: RunnableConfig): Runnable<RunInput, RunOutput, CallOptions>;
3135
+ withConfig(config: Partial<CallOptions>): Runnable<RunInput, RunOutput, CallOptions>;
1483
3136
  /**
1484
3137
  * Create a new runnable from the current one that will try invoking
1485
3138
  * other passed fallback runnables if the initial invocation fails.
@@ -1733,17 +3386,21 @@ declare abstract class Runnable<RunInput = any, RunOutput = any, CallOptions ext
1733
3386
  asTool<T extends RunInput = RunInput>(fields: {
1734
3387
  name?: string;
1735
3388
  description?: string;
1736
- schema: z.ZodType<T>;
1737
- }): RunnableToolLike<z.ZodType<T | ToolCall>, RunOutput>;
3389
+ schema: InteropZodType<T>;
3390
+ }): RunnableToolLike<InteropZodType<T | ToolCall>, RunOutput>;
1738
3391
  }
1739
3392
  type RunnableBindingArgs<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = {
1740
3393
  bound: Runnable<RunInput, RunOutput, CallOptions>;
3394
+ /**
3395
+ * @deprecated use {@link config} instead
3396
+ */
1741
3397
  kwargs?: Partial<CallOptions>;
1742
3398
  config: RunnableConfig;
1743
- configFactories?: Array<(config: RunnableConfig) => RunnableConfig>;
3399
+ configFactories?: Array<(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>>;
1744
3400
  };
1745
3401
  /**
1746
- * A runnable that delegates calls to another runnable with a set of kwargs.
3402
+ * Wraps a runnable and applies partial config upon invocation.
3403
+ *
1747
3404
  * @example
1748
3405
  * ```typescript
1749
3406
  * import {
@@ -1793,8 +3450,15 @@ declare class RunnableBinding<RunInput, RunOutput, CallOptions extends RunnableC
1793
3450
  constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>);
1794
3451
  getName(suffix?: string | undefined): string;
1795
3452
  _mergeConfig(...options: (Partial<CallOptions> | RunnableConfig | undefined)[]): Promise<Partial<CallOptions>>;
3453
+ /**
3454
+ * Binds the runnable with the specified arguments.
3455
+ * @param kwargs The arguments to bind the runnable with.
3456
+ * @returns A new instance of the `RunnableBinding` class that is bound with the specified arguments.
3457
+ *
3458
+ * @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
3459
+ */
1796
3460
  bind(kwargs: Partial<CallOptions>): RunnableBinding<RunInput, RunOutput, CallOptions>;
1797
- withConfig(config: RunnableConfig): Runnable<RunInput, RunOutput, CallOptions>;
3461
+ withConfig(config: Partial<CallOptions>): Runnable<RunInput, RunOutput, CallOptions>;
1798
3462
  withRetry(fields?: {
1799
3463
  stopAfterAttempt?: number;
1800
3464
  onFailedAttempt?: RunnableRetryFailedAttemptHandler;
@@ -1807,7 +3471,7 @@ declare class RunnableBinding<RunInput, RunOutput, CallOptions extends RunnableC
1807
3471
  returnExceptions: true;
1808
3472
  }): Promise<(RunOutput | Error)[]>;
1809
3473
  batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
1810
- _streamIterator(input: RunInput, options?: Partial<CallOptions> | undefined): AsyncGenerator<Awaited<RunOutput>, void, unknown>;
3474
+ _streamIterator(input: RunInput, options?: Partial<CallOptions> | undefined): AsyncGenerator<Awaited<RunOutput>, void, any>;
1811
3475
  stream(input: RunInput, options?: Partial<CallOptions> | undefined): Promise<IterableReadableStream<RunOutput>>;
1812
3476
  transform(generator: AsyncGenerator<RunInput>, options?: Partial<CallOptions>): AsyncGenerator<RunOutput>;
1813
3477
  streamEvents(input: RunInput, options: Partial<CallOptions> & {
@@ -1998,13 +3662,13 @@ declare class RunnableWithFallbacks<RunInput, RunOutput> extends Runnable<RunInp
1998
3662
  }): Promise<(RunOutput | Error)[]>;
1999
3663
  batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
2000
3664
  }
2001
- interface RunnableToolLikeArgs<RunInput extends z.ZodType = z.ZodType, RunOutput = unknown> extends Omit<RunnableBindingArgs<z.infer<RunInput>, RunOutput>, "config"> {
3665
+ interface RunnableToolLikeArgs<RunInput extends InteropZodType = InteropZodType, RunOutput = unknown> extends Omit<RunnableBindingArgs<InferInteropZodOutput<RunInput>, RunOutput>, "config"> {
2002
3666
  name: string;
2003
3667
  description?: string;
2004
3668
  schema: RunInput;
2005
3669
  config?: RunnableConfig;
2006
3670
  }
2007
- declare class RunnableToolLike<RunInput extends z.ZodType = z.ZodType, RunOutput = unknown> extends RunnableBinding<z.infer<RunInput>, RunOutput> {
3671
+ declare class RunnableToolLike<RunInput extends InteropZodType = InteropZodType, RunOutput = unknown> extends RunnableBinding<InferInteropZodOutput<RunInput>, RunOutput> {
2008
3672
  name: string;
2009
3673
  description?: string;
2010
3674
  schema: RunInput;
@@ -2012,6 +3676,196 @@ declare class RunnableToolLike<RunInput extends z.ZodType = z.ZodType, RunOutput
2012
3676
  static lc_name(): string;
2013
3677
  }
2014
3678
 
3679
+ type JsonSchema7AnyType = {};
3680
+
3681
+ type ErrorMessages<T extends JsonSchema7TypeUnion, OmitProperties extends string = ""> = Partial<Omit<{
3682
+ [key in keyof T]: string;
3683
+ }, OmitProperties | "type" | "errorMessages">>;
3684
+
3685
+ type JsonSchema7ArrayType = {
3686
+ type: "array";
3687
+ items?: JsonSchema7Type;
3688
+ minItems?: number;
3689
+ maxItems?: number;
3690
+ errorMessages?: ErrorMessages<JsonSchema7ArrayType, "items">;
3691
+ };
3692
+
3693
+ type JsonSchema7BigintType = {
3694
+ type: "integer";
3695
+ format: "int64";
3696
+ minimum?: BigInt;
3697
+ exclusiveMinimum?: BigInt;
3698
+ maximum?: BigInt;
3699
+ exclusiveMaximum?: BigInt;
3700
+ multipleOf?: BigInt;
3701
+ errorMessage?: ErrorMessages<JsonSchema7BigintType>;
3702
+ };
3703
+
3704
+ type JsonSchema7BooleanType = {
3705
+ type: "boolean";
3706
+ };
3707
+
3708
+ type JsonSchema7NumberType = {
3709
+ type: "number" | "integer";
3710
+ minimum?: number;
3711
+ exclusiveMinimum?: number;
3712
+ maximum?: number;
3713
+ exclusiveMaximum?: number;
3714
+ multipleOf?: number;
3715
+ errorMessage?: ErrorMessages<JsonSchema7NumberType>;
3716
+ };
3717
+
3718
+ type JsonSchema7DateType = {
3719
+ type: "integer" | "string";
3720
+ format: "unix-time" | "date-time" | "date";
3721
+ minimum?: number;
3722
+ maximum?: number;
3723
+ errorMessage?: ErrorMessages<JsonSchema7NumberType>;
3724
+ } | {
3725
+ anyOf: JsonSchema7DateType[];
3726
+ };
3727
+
3728
+ type JsonSchema7EnumType = {
3729
+ type: "string";
3730
+ enum: string[];
3731
+ };
3732
+
3733
+ type JsonSchema7AllOfType = {
3734
+ allOf: JsonSchema7Type[];
3735
+ unevaluatedProperties?: boolean;
3736
+ };
3737
+
3738
+ type JsonSchema7LiteralType = {
3739
+ type: "string" | "number" | "integer" | "boolean";
3740
+ const: string | number | boolean;
3741
+ } | {
3742
+ type: "object" | "array";
3743
+ };
3744
+
3745
+ type JsonSchema7StringType = {
3746
+ type: "string";
3747
+ minLength?: number;
3748
+ maxLength?: number;
3749
+ format?: "email" | "idn-email" | "uri" | "uuid" | "date-time" | "ipv4" | "ipv6" | "date" | "time" | "duration";
3750
+ pattern?: string;
3751
+ allOf?: {
3752
+ pattern: string;
3753
+ errorMessage?: ErrorMessages<{
3754
+ pattern: string;
3755
+ }>;
3756
+ }[];
3757
+ anyOf?: {
3758
+ format: string;
3759
+ errorMessage?: ErrorMessages<{
3760
+ format: string;
3761
+ }>;
3762
+ }[];
3763
+ errorMessage?: ErrorMessages<JsonSchema7StringType>;
3764
+ contentEncoding?: string;
3765
+ };
3766
+
3767
+ type JsonSchema7RecordPropertyNamesType = Omit<JsonSchema7StringType, "type"> | Omit<JsonSchema7EnumType, "type">;
3768
+ type JsonSchema7RecordType = {
3769
+ type: "object";
3770
+ additionalProperties?: JsonSchema7Type | true;
3771
+ propertyNames?: JsonSchema7RecordPropertyNamesType;
3772
+ };
3773
+
3774
+ type JsonSchema7MapType = {
3775
+ type: "array";
3776
+ maxItems: 125;
3777
+ items: {
3778
+ type: "array";
3779
+ items: [JsonSchema7Type, JsonSchema7Type];
3780
+ minItems: 2;
3781
+ maxItems: 2;
3782
+ };
3783
+ };
3784
+
3785
+ type JsonSchema7NativeEnumType = {
3786
+ type: "string" | "number" | ["string", "number"];
3787
+ enum: (string | number)[];
3788
+ };
3789
+
3790
+ type JsonSchema7NeverType = {
3791
+ not: {};
3792
+ };
3793
+
3794
+ type JsonSchema7NullType = {
3795
+ type: "null";
3796
+ };
3797
+
3798
+ type JsonSchema7NullableType = {
3799
+ anyOf: [JsonSchema7Type, JsonSchema7NullType];
3800
+ } | {
3801
+ type: [string, "null"];
3802
+ };
3803
+
3804
+ type JsonSchema7ObjectType = {
3805
+ type: "object";
3806
+ properties: Record<string, JsonSchema7Type>;
3807
+ additionalProperties?: boolean | JsonSchema7Type;
3808
+ required?: string[];
3809
+ };
3810
+
3811
+ type JsonSchema7SetType = {
3812
+ type: "array";
3813
+ uniqueItems: true;
3814
+ items?: JsonSchema7Type;
3815
+ minItems?: number;
3816
+ maxItems?: number;
3817
+ errorMessage?: ErrorMessages<JsonSchema7SetType>;
3818
+ };
3819
+
3820
+ type JsonSchema7TupleType = {
3821
+ type: "array";
3822
+ minItems: number;
3823
+ items: JsonSchema7Type[];
3824
+ } & ({
3825
+ maxItems: number;
3826
+ } | {
3827
+ additionalItems?: JsonSchema7Type;
3828
+ });
3829
+
3830
+ type JsonSchema7UndefinedType = {
3831
+ not: {};
3832
+ };
3833
+
3834
+ declare const primitiveMappings: {
3835
+ readonly ZodString: "string";
3836
+ readonly ZodNumber: "number";
3837
+ readonly ZodBigInt: "integer";
3838
+ readonly ZodBoolean: "boolean";
3839
+ readonly ZodNull: "null";
3840
+ };
3841
+ type JsonSchema7Primitive = (typeof primitiveMappings)[keyof typeof primitiveMappings];
3842
+ type JsonSchema7UnionType = JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType;
3843
+ type JsonSchema7PrimitiveUnionType = {
3844
+ type: JsonSchema7Primitive | JsonSchema7Primitive[];
3845
+ } | {
3846
+ type: JsonSchema7Primitive | JsonSchema7Primitive[];
3847
+ enum: (string | number | bigint | boolean | null)[];
3848
+ };
3849
+ type JsonSchema7AnyOfType = {
3850
+ anyOf: JsonSchema7Type[];
3851
+ };
3852
+
3853
+ type JsonSchema7UnknownType = {};
3854
+
3855
+ type JsonSchema7RefType = {
3856
+ $ref: string;
3857
+ };
3858
+ type JsonSchema7Meta = {
3859
+ title?: string;
3860
+ default?: any;
3861
+ description?: string;
3862
+ markdownDescription?: string;
3863
+ };
3864
+ type JsonSchema7TypeUnion = JsonSchema7StringType | JsonSchema7ArrayType | JsonSchema7NumberType | JsonSchema7BigintType | JsonSchema7BooleanType | JsonSchema7DateType | JsonSchema7EnumType | JsonSchema7LiteralType | JsonSchema7NativeEnumType | JsonSchema7NullType | JsonSchema7NumberType | JsonSchema7ObjectType | JsonSchema7RecordType | JsonSchema7TupleType | JsonSchema7UnionType | JsonSchema7UndefinedType | JsonSchema7RefType | JsonSchema7NeverType | JsonSchema7MapType | JsonSchema7AnyType | JsonSchema7NullableType | JsonSchema7AllOfType | JsonSchema7UnknownType | JsonSchema7SetType;
3865
+ type JsonSchema7Type = JsonSchema7TypeUnion & JsonSchema7Meta;
3866
+
3867
+ type JSONSchema = JsonSchema7Type;
3868
+
2015
3869
  interface BaseLangChainParams {
2016
3870
  verbose?: boolean;
2017
3871
  callbacks?: Callbacks;
@@ -2036,8 +3890,31 @@ declare abstract class BaseLangChain<RunInput, RunOutput, CallOptions extends Ru
2036
3890
  }
2037
3891
 
2038
3892
  type ResponseFormat = "content" | "content_and_artifact" | string;
2039
- type ToolReturnType = any;
2040
- type ZodObjectAny = z.ZodObject<any, any, any, any>;
3893
+ type ToolOutputType = any;
3894
+ /**
3895
+ * Conditional type that determines the return type of the {@link StructuredTool.invoke} method.
3896
+ * - If the input is a ToolCall, it returns a ToolMessage
3897
+ * - If the config is a runnable config and contains a toolCall property, it returns a ToolMessage
3898
+ * - Otherwise, it returns the original output type
3899
+ */
3900
+ type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToolOutput ? TOutput : TConfig extends {
3901
+ toolCall: {
3902
+ id: string;
3903
+ };
3904
+ } ? ToolMessage : TConfig extends {
3905
+ toolCall: {
3906
+ id: undefined;
3907
+ };
3908
+ } ? TOutput : TConfig extends {
3909
+ toolCall: {
3910
+ id?: string;
3911
+ };
3912
+ } ? TOutput | ToolMessage : TInput extends ToolCall ? ToolMessage : TOutput;
3913
+ /**
3914
+ * Base type that establishes the types of input schemas that can be used for LangChain tool
3915
+ * definitions.
3916
+ */
3917
+ type ToolInputSchemaBase = z.ZodTypeAny | JSONSchema;
2041
3918
  /**
2042
3919
  * Parameters for the Tool classes.
2043
3920
  */
@@ -2052,6 +3929,10 @@ interface ToolParams extends BaseLangChainParams {
2052
3929
  * @default "content"
2053
3930
  */
2054
3931
  responseFormat?: ResponseFormat;
3932
+ /**
3933
+ * Default config object for the tool runnable.
3934
+ */
3935
+ defaultConfig?: ToolRunnableConfig;
2055
3936
  /**
2056
3937
  * Whether to show full details in the thrown parsing errors.
2057
3938
  *
@@ -2062,13 +3943,146 @@ interface ToolParams extends BaseLangChainParams {
2062
3943
  type ToolRunnableConfig<ConfigurableFieldType extends Record<string, any> = Record<string, any>> = RunnableConfig<ConfigurableFieldType> & {
2063
3944
  toolCall?: ToolCall;
2064
3945
  };
3946
+ /**
3947
+ * Utility type that resolves the output type of a tool input schema.
3948
+ *
3949
+ * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur
3950
+ * during parsing. When using JSONSchema, input and output types are the same.
3951
+ *
3952
+ * The input type for a given schema should match the structure of the arguments that the LLM
3953
+ * generates as part of its {@link ToolCall}. The output type will be the type that results from
3954
+ * applying any transforms defined in your schema. If there are no transforms, the input and output
3955
+ * types will be the same.
3956
+ */
3957
+ type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JSONSchema ? unknown : never;
3958
+ /**
3959
+ * Utility type that resolves the input type of a tool input schema.
3960
+ *
3961
+ * Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur
3962
+ * during parsing. When using JSONSchema, input and output types are the same.
3963
+ *
3964
+ * The input type for a given schema should match the structure of the arguments that the LLM
3965
+ * generates as part of its {@link ToolCall}. The output type will be the type that results from
3966
+ * applying any transforms defined in your schema. If there are no transforms, the input and output
3967
+ * types will be the same.
3968
+ */
3969
+ type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JSONSchema ? unknown : never;
3970
+ /**
3971
+ * Defines the type that will be passed into a tool handler function as a result of a tool call.
3972
+ *
3973
+ * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
3974
+ * @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
3975
+ */
3976
+ type StructuredToolCallInput<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>> = (ToolInputSchemaOutputType<SchemaT> extends string ? string : never) | SchemaInputT | ToolCall;
3977
+ /**
3978
+ * An input schema type for tools that accept a single string input.
3979
+ *
3980
+ * This schema defines a tool that takes an optional string parameter named "input".
3981
+ * It uses Zod's effects to transform the input and strip any extra properties.
3982
+ *
3983
+ * This is primarily used for creating simple string-based tools where the LLM
3984
+ * only needs to provide a single text value as input to the tool.
3985
+ */
3986
+ type StringInputToolSchema = z.ZodType<string | undefined, z.ZodTypeDef, any>;
3987
+ /**
3988
+ * Interface that defines the shape of a LangChain structured tool.
3989
+ *
3990
+ * A structured tool is a tool that uses a schema to define the structure of the arguments that the
3991
+ * LLM generates as part of its {@link ToolCall}.
3992
+ *
3993
+ * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
3994
+ * @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
3995
+ */
3996
+ interface StructuredToolInterface<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends RunnableInterface<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> {
3997
+ lc_namespace: string[];
3998
+ /**
3999
+ * A Zod schema representing the parameters of the tool.
4000
+ */
4001
+ schema: SchemaT;
4002
+ /**
4003
+ * Invokes the tool with the provided argument and configuration.
4004
+ * @param arg The input argument for the tool.
4005
+ * @param configArg Optional configuration for the tool call.
4006
+ * @returns A Promise that resolves with the tool's output.
4007
+ */
4008
+ invoke<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;
4009
+ /**
4010
+ * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
4011
+ *
4012
+ * Calls the tool with the provided argument, configuration, and tags. It
4013
+ * parses the input according to the schema, handles any errors, and
4014
+ * manages callbacks.
4015
+ * @param arg The input argument for the tool.
4016
+ * @param configArg Optional configuration or callbacks for the tool.
4017
+ * @param tags Optional tags for the tool.
4018
+ * @returns A Promise that resolves with a string.
4019
+ */
4020
+ call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig,
4021
+ /** @deprecated */
4022
+ tags?: string[]): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;
4023
+ /**
4024
+ * The name of the tool.
4025
+ */
4026
+ name: string;
4027
+ /**
4028
+ * A description of the tool.
4029
+ */
4030
+ description: string;
4031
+ /**
4032
+ * Whether to return the tool's output directly.
4033
+ *
4034
+ * Setting this to true means that after the tool is called,
4035
+ * an agent should stop looping.
4036
+ */
4037
+ returnDirect: boolean;
4038
+ }
4039
+ /**
4040
+ * A special interface for tools that accept a string input, usually defined with the {@link Tool} class.
4041
+ *
4042
+ * @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
4043
+ * @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
4044
+ */
4045
+ interface ToolInterface<SchemaT = StringInputToolSchema, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
4046
+ /**
4047
+ * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
4048
+ *
4049
+ * Calls the tool with the provided argument and callbacks. It handles
4050
+ * string inputs specifically.
4051
+ * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.
4052
+ * @param callbacks Optional callbacks for the tool.
4053
+ * @returns A Promise that resolves with a string.
4054
+ */
4055
+ call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;
4056
+ }
4057
+ /**
4058
+ * Base interface for the input parameters of the {@link DynamicTool} and
4059
+ * {@link DynamicStructuredTool} classes.
4060
+ */
4061
+ interface BaseDynamicToolInput extends ToolParams {
4062
+ name: string;
4063
+ description: string;
4064
+ /**
4065
+ * Whether to return the tool's output directly.
4066
+ *
4067
+ * Setting this to true means that after the tool is called,
4068
+ * an agent should stop looping.
4069
+ */
4070
+ returnDirect?: boolean;
4071
+ }
4072
+ /**
4073
+ * Interface for the input parameters of the DynamicTool class.
4074
+ */
4075
+ interface DynamicToolInput<ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {
4076
+ func: (input: string, runManager?: CallbackManagerForToolRun, config?: ToolRunnableConfig) => Promise<ToolOutputT>;
4077
+ }
4078
+
2065
4079
  /**
2066
4080
  * Base class for Tools that accept input of any shape defined by a Zod schema.
2067
4081
  */
2068
- declare abstract class StructuredTool<T extends ZodObjectAny = ZodObjectAny> extends BaseLangChain<(z.output<T> extends string ? string : never) | z.input<T> | ToolCall, ToolReturnType> {
4082
+ declare abstract class StructuredTool<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseLangChain<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> implements StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
2069
4083
  abstract name: string;
2070
4084
  abstract description: string;
2071
- abstract schema: T | z.ZodEffects<T>;
4085
+ abstract schema: SchemaT;
2072
4086
  /**
2073
4087
  * Whether to return the tool's output directly.
2074
4088
  *
@@ -2088,15 +4102,19 @@ declare abstract class StructuredTool<T extends ZodObjectAny = ZodObjectAny> ext
2088
4102
  * @default "content"
2089
4103
  */
2090
4104
  responseFormat?: ResponseFormat;
4105
+ /**
4106
+ * Default config object for the tool runnable.
4107
+ */
4108
+ defaultConfig?: ToolRunnableConfig;
2091
4109
  constructor(fields?: ToolParams);
2092
- protected abstract _call(arg: z.output<T>, runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise<ToolReturnType>;
4110
+ protected abstract _call(arg: SchemaOutputT, runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise<ToolOutputT>;
2093
4111
  /**
2094
4112
  * Invokes the tool with the provided input and configuration.
2095
4113
  * @param input The input for the tool.
2096
4114
  * @param config Optional configuration for the tool.
2097
- * @returns A Promise that resolves with a string.
4115
+ * @returns A Promise that resolves with the tool's output.
2098
4116
  */
2099
- invoke(input: (z.output<T> extends string ? string : never) | z.input<T> | ToolCall, config?: RunnableConfig): Promise<ToolReturnType>;
4117
+ invoke<TInput extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(input: TInput, config?: TConfig): Promise<ToolReturnType<TInput, TConfig, ToolOutputT>>;
2100
4118
  /**
2101
4119
  * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
2102
4120
  *
@@ -2108,55 +4126,55 @@ declare abstract class StructuredTool<T extends ZodObjectAny = ZodObjectAny> ext
2108
4126
  * @param tags Optional tags for the tool.
2109
4127
  * @returns A Promise that resolves with a string.
2110
4128
  */
2111
- call(arg: (z.output<T> extends string ? string : never) | z.input<T>, configArg?: Callbacks | ToolRunnableConfig,
4129
+ call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig,
2112
4130
  /** @deprecated */
2113
- tags?: string[]): Promise<ToolReturnType>;
4131
+ tags?: string[]): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;
2114
4132
  }
2115
- interface BaseDynamicToolInput extends ToolParams {
2116
- name: string;
2117
- description: string;
4133
+ /**
4134
+ * Base class for Tools that accept input as a string.
4135
+ */
4136
+ declare abstract class Tool<ToolOutputT = ToolOutputType> extends StructuredTool<StringInputToolSchema, ToolInputSchemaOutputType<StringInputToolSchema>, ToolInputSchemaInputType<StringInputToolSchema>, ToolOutputT> implements ToolInterface<StringInputToolSchema, ToolInputSchemaInputType<StringInputToolSchema>, ToolOutputT> {
4137
+ schema: z.ZodEffects<z.ZodObject<{
4138
+ input: z.ZodOptional<z.ZodString>;
4139
+ }, "strip", z.ZodTypeAny, {
4140
+ input?: string | undefined;
4141
+ }, {
4142
+ input?: string | undefined;
4143
+ }>, string | undefined, {
4144
+ input?: string | undefined;
4145
+ }>;
4146
+ constructor(fields?: ToolParams);
2118
4147
  /**
2119
- * Whether to return the tool's output directly.
4148
+ * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
2120
4149
  *
2121
- * Setting this to true means that after the tool is called,
2122
- * an agent should stop looping.
4150
+ * Calls the tool with the provided argument and callbacks. It handles
4151
+ * string inputs specifically.
4152
+ * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.
4153
+ * @param callbacks Optional callbacks for the tool.
4154
+ * @returns A Promise that resolves with a string.
2123
4155
  */
2124
- returnDirect?: boolean;
2125
- }
2126
- /**
2127
- * Interface for the input parameters of the DynamicStructuredTool class.
2128
- */
2129
- interface DynamicStructuredToolInput<T extends ZodObjectAny | Record<string, any> = ZodObjectAny> extends BaseDynamicToolInput {
2130
- func: (input: BaseDynamicToolInput["responseFormat"] extends "content_and_artifact" ? ToolCall : T extends ZodObjectAny ? z.infer<T> : T, runManager?: CallbackManagerForToolRun, config?: RunnableConfig) => Promise<ToolReturnType>;
2131
- schema: T extends ZodObjectAny ? T : T;
4156
+ call<TArg extends string | undefined | z.input<this["schema"]> | ToolCall, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;
2132
4157
  }
2133
4158
  /**
2134
- * A tool that can be created dynamically from a function, name, and
2135
- * description, designed to work with structured data. It extends the
2136
- * StructuredTool class and overrides the _call method to execute the
2137
- * provided function when the tool is called.
2138
- *
2139
- * Schema can be passed as Zod or JSON schema. The tool will not validate
2140
- * input if JSON schema is passed.
4159
+ * A tool that can be created dynamically from a function, name, and description.
2141
4160
  */
2142
- declare class DynamicStructuredTool<T extends ZodObjectAny | Record<string, any> = ZodObjectAny> extends StructuredTool<T extends ZodObjectAny ? T : ZodObjectAny> {
4161
+ declare class DynamicTool<ToolOutputT = ToolOutputType> extends Tool<ToolOutputT> {
2143
4162
  static lc_name(): string;
2144
4163
  name: string;
2145
4164
  description: string;
2146
- func: DynamicStructuredToolInput<T>["func"];
2147
- schema: T extends ZodObjectAny ? T : ZodObjectAny;
2148
- constructor(fields: DynamicStructuredToolInput<T>);
4165
+ func: DynamicToolInput<ToolOutputT>["func"];
4166
+ constructor(fields: DynamicToolInput<ToolOutputT>);
2149
4167
  /**
2150
4168
  * @deprecated Use .invoke() instead. Will be removed in 0.3.0.
2151
4169
  */
2152
- call(arg: (T extends ZodObjectAny ? z.output<T> : T) | ToolCall, configArg?: RunnableConfig | Callbacks,
2153
- /** @deprecated */
2154
- tags?: string[]): Promise<ToolReturnType>;
2155
- protected _call(arg: (T extends ZodObjectAny ? z.output<T> : T) | ToolCall, runManager?: CallbackManagerForToolRun, parentConfig?: RunnableConfig): Promise<ToolReturnType>;
4170
+ call<TArg extends string | undefined | z.input<this["schema"]> | ToolCall, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;
4171
+ /** @ignore */
4172
+ _call(input: string, // DynamicTool's _call specifically expects a string after schema transformation
4173
+ runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise<ToolOutputT>;
2156
4174
  }
2157
4175
 
2158
4176
  declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration & {
2159
4177
  apiKey: string;
2160
- }) => DynamicStructuredTool;
4178
+ }) => DynamicTool;
2161
4179
 
2162
4180
  export { executeTool };