@langwatch/scenario 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.mts +268 -32
- package/dist/index.d.ts +268 -32
- package/dist/index.js +2940 -1935
- package/dist/index.mjs +2910 -1907
- package/dist/integrations/vitest/setup.js +5 -2
- package/dist/integrations/vitest/setup.mjs +5 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ describe("Weather Agent", () => {
|
|
|
97
97
|
role: AgentRole.AGENT,
|
|
98
98
|
call: async (input) => {
|
|
99
99
|
const response = await generateText({
|
|
100
|
-
model: openai("gpt-4.1"),
|
|
100
|
+
model: openai("gpt-4.1-mini"),
|
|
101
101
|
system: `You are a helpful assistant that may help the user with weather information.`,
|
|
102
102
|
messages: input.messages,
|
|
103
103
|
tools: { get_current_weather: getCurrentWeather },
|
|
@@ -150,7 +150,7 @@ describe("Weather Agent", () => {
|
|
|
150
150
|
"The user asks for the weather in a specific city, and the agent should use the weather tool to find it.",
|
|
151
151
|
agents: [
|
|
152
152
|
weatherAgent,
|
|
153
|
-
scenario.userSimulatorAgent({ model: openai("gpt-4.1") }),
|
|
153
|
+
scenario.userSimulatorAgent({ model: openai("gpt-4.1-mini") }),
|
|
154
154
|
],
|
|
155
155
|
script: [
|
|
156
156
|
scenario.user("What's the weather like in Barcelona?"),
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { ModelMessage, UserModelMessage, AssistantModelMessage, ToolModelMessage
|
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
import { SpanProcessor, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
5
5
|
import { RealtimeSession } from '@openai/agents/realtime';
|
|
6
|
+
import { SetupObservabilityOptions } from 'langwatch/observability/node';
|
|
6
7
|
import { Observable } from 'rxjs';
|
|
7
8
|
import { z as z$1 } from 'zod';
|
|
8
9
|
|
|
@@ -178,6 +179,12 @@ interface ScenarioConfig {
|
|
|
178
179
|
* If not provided, the scenario will not be grouped into a set.
|
|
179
180
|
*/
|
|
180
181
|
setId?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Optional metadata to attach to the scenario run.
|
|
184
|
+
* Accepts arbitrary key-value pairs (e.g. prompt IDs, environments, versions).
|
|
185
|
+
* The `langwatch` key is reserved for platform-internal use.
|
|
186
|
+
*/
|
|
187
|
+
metadata?: Record<string, unknown>;
|
|
181
188
|
}
|
|
182
189
|
/**
|
|
183
190
|
* Final, normalized scenario configuration.
|
|
@@ -265,6 +272,10 @@ type ScriptStep = (state: ScenarioExecutionStateLike, executor: ScenarioExecutio
|
|
|
265
272
|
*
|
|
266
273
|
*/
|
|
267
274
|
interface ScenarioResult {
|
|
275
|
+
/**
|
|
276
|
+
* Unique identifier for this scenario run.
|
|
277
|
+
*/
|
|
278
|
+
runId: string;
|
|
268
279
|
/**
|
|
269
280
|
* Indicates whether the scenario was successful.
|
|
270
281
|
*/
|
|
@@ -357,6 +368,13 @@ interface ScenarioExecutionStateLike {
|
|
|
357
368
|
hasToolCall(toolName: string): boolean;
|
|
358
369
|
}
|
|
359
370
|
|
|
371
|
+
/**
|
|
372
|
+
* Schema for the scenario project configuration file (scenario.config.js).
|
|
373
|
+
*
|
|
374
|
+
* The `observability` field accepts a subset of `SetupObservabilityOptions`
|
|
375
|
+
* from the langwatch SDK. It uses `z.custom()` to avoid strict validation
|
|
376
|
+
* on the passthrough object while keeping the outer config strict.
|
|
377
|
+
*/
|
|
360
378
|
declare const scenarioProjectConfigSchema: z.ZodObject<{
|
|
361
379
|
defaultModel: z.ZodOptional<z.ZodObject<{
|
|
362
380
|
model: z.ZodCustom<ai.LanguageModel, ai.LanguageModel>;
|
|
@@ -364,6 +382,7 @@ declare const scenarioProjectConfigSchema: z.ZodObject<{
|
|
|
364
382
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
365
383
|
}, z.core.$strip>>;
|
|
366
384
|
headless: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
385
|
+
observability: z.ZodOptional<z.ZodCustom<Partial<SetupObservabilityOptions>, Partial<SetupObservabilityOptions>>>;
|
|
367
386
|
}, z.core.$strict>;
|
|
368
387
|
type ScenarioProjectConfig = z.infer<typeof scenarioProjectConfigSchema>;
|
|
369
388
|
declare function defineConfig(config: ScenarioProjectConfig): ScenarioProjectConfig;
|
|
@@ -467,6 +486,13 @@ declare class JudgeSpanCollector implements SpanProcessor {
|
|
|
467
486
|
onEnd(span: ReadableSpan): void;
|
|
468
487
|
forceFlush(): Promise<void>;
|
|
469
488
|
shutdown(): Promise<void>;
|
|
489
|
+
/**
|
|
490
|
+
* Removes all spans associated with a specific thread.
|
|
491
|
+
* Call this after a scenario run completes to prevent memory growth
|
|
492
|
+
* in long-lived processes.
|
|
493
|
+
* @param threadId - The thread identifier whose spans should be cleared
|
|
494
|
+
*/
|
|
495
|
+
clearSpansForThread(threadId: string): void;
|
|
470
496
|
/**
|
|
471
497
|
* Retrieves all spans associated with a specific thread.
|
|
472
498
|
* @param threadId - The thread identifier to filter spans by
|
|
@@ -495,6 +521,22 @@ interface JudgeAgentConfig extends TestingAgentConfig {
|
|
|
495
521
|
* Optional span collector for telemetry. Defaults to global singleton.
|
|
496
522
|
*/
|
|
497
523
|
spanCollector?: JudgeSpanCollector;
|
|
524
|
+
/**
|
|
525
|
+
* Token threshold for switching to structure-only trace rendering.
|
|
526
|
+
* When the full trace digest exceeds this estimated token count,
|
|
527
|
+
* the judge receives a structure-only view with expand_trace and
|
|
528
|
+
* grep_trace tools for progressive discovery.
|
|
529
|
+
*
|
|
530
|
+
* @default 8192
|
|
531
|
+
*/
|
|
532
|
+
tokenThreshold?: number;
|
|
533
|
+
/**
|
|
534
|
+
* Maximum number of tool-calling steps for progressive trace discovery.
|
|
535
|
+
* Only applies when the trace exceeds the token threshold.
|
|
536
|
+
*
|
|
537
|
+
* @default 10
|
|
538
|
+
*/
|
|
539
|
+
maxDiscoverySteps?: number;
|
|
498
540
|
}
|
|
499
541
|
/**
|
|
500
542
|
* Agent that evaluates conversations against success criteria.
|
|
@@ -509,6 +551,8 @@ declare class JudgeAgent extends JudgeAgentAdapter {
|
|
|
509
551
|
private readonly cfg;
|
|
510
552
|
private logger;
|
|
511
553
|
private readonly spanCollector;
|
|
554
|
+
private readonly tokenThreshold;
|
|
555
|
+
private readonly maxDiscoverySteps;
|
|
512
556
|
role: AgentRole;
|
|
513
557
|
criteria: string[];
|
|
514
558
|
/**
|
|
@@ -517,7 +561,19 @@ declare class JudgeAgent extends JudgeAgentAdapter {
|
|
|
517
561
|
invokeLLM: (params: InvokeLLMParams) => Promise<InvokeLLMResult>;
|
|
518
562
|
constructor(cfg: JudgeAgentConfig);
|
|
519
563
|
call(input: AgentInput): Promise<JudgeResult | null>;
|
|
520
|
-
|
|
564
|
+
/**
|
|
565
|
+
* Builds the trace digest, choosing between full inline rendering
|
|
566
|
+
* and structure-only mode based on estimated token count.
|
|
567
|
+
*/
|
|
568
|
+
private buildTraceDigest;
|
|
569
|
+
/**
|
|
570
|
+
* Invokes the LLM, enabling multi-step tool execution for large traces.
|
|
571
|
+
* In multi-step mode, the AI SDK loops automatically: the judge can call
|
|
572
|
+
* expand_trace/grep_trace tools multiple times before reaching a terminal
|
|
573
|
+
* tool (finish_test/continue_test) or hitting the step limit.
|
|
574
|
+
*/
|
|
575
|
+
private invokeLLMWithDiscovery;
|
|
576
|
+
private parseToolCalls;
|
|
521
577
|
}
|
|
522
578
|
/**
|
|
523
579
|
* Factory function for creating JudgeAgent instances.
|
|
@@ -578,6 +634,15 @@ declare const judgeAgent: (cfg?: JudgeAgentConfig) => JudgeAgent;
|
|
|
578
634
|
declare class JudgeSpanDigestFormatter {
|
|
579
635
|
private readonly logger;
|
|
580
636
|
private readonly deduplicator;
|
|
637
|
+
/**
|
|
638
|
+
* Formats spans into a structure-only digest showing span tree hierarchy
|
|
639
|
+
* without attributes, events, or content. Used for large traces that
|
|
640
|
+
* exceed the token threshold, paired with expand_trace/grep_trace tools.
|
|
641
|
+
*
|
|
642
|
+
* @param spans - All spans for a thread
|
|
643
|
+
* @returns Plain text digest with only structural information
|
|
644
|
+
*/
|
|
645
|
+
formatStructureOnly(spans: ReadableSpan[]): string;
|
|
581
646
|
/**
|
|
582
647
|
* Formats spans into a complete digest with full content and nesting.
|
|
583
648
|
* @param spans - All spans for a thread
|
|
@@ -586,20 +651,18 @@ declare class JudgeSpanDigestFormatter {
|
|
|
586
651
|
format(spans: ReadableSpan[]): string;
|
|
587
652
|
private sortByStartTime;
|
|
588
653
|
private buildHierarchy;
|
|
654
|
+
private renderStructureNode;
|
|
589
655
|
private renderNode;
|
|
590
656
|
private getTreePrefix;
|
|
591
657
|
private getAttrIndent;
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
private
|
|
597
|
-
private
|
|
598
|
-
private
|
|
658
|
+
/**
|
|
659
|
+
* Formats a value with deduplication applied. Used by the `format()` method
|
|
660
|
+
* to reduce token usage by replacing repeated strings with markers.
|
|
661
|
+
*/
|
|
662
|
+
private formatValueWithDedup;
|
|
663
|
+
private transformValueWithDedup;
|
|
664
|
+
private transformStringWithDedup;
|
|
599
665
|
private calculateTotalDuration;
|
|
600
|
-
private formatDuration;
|
|
601
|
-
private formatTimestamp;
|
|
602
|
-
private getStatusIndicator;
|
|
603
666
|
private collectErrors;
|
|
604
667
|
}
|
|
605
668
|
/**
|
|
@@ -607,6 +670,45 @@ declare class JudgeSpanDigestFormatter {
|
|
|
607
670
|
*/
|
|
608
671
|
declare const judgeSpanDigestFormatter: JudgeSpanDigestFormatter;
|
|
609
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Default token threshold for switching to structure-only trace rendering.
|
|
675
|
+
* Traces exceeding this estimated token count will be rendered in
|
|
676
|
+
* structure-only mode with expand/grep tools available to the judge.
|
|
677
|
+
*
|
|
678
|
+
*/
|
|
679
|
+
declare const DEFAULT_TOKEN_THRESHOLD = 8192;
|
|
680
|
+
/**
|
|
681
|
+
* Estimates the number of tokens in a text string using a byte-based heuristic.
|
|
682
|
+
* Uses UTF-8 byte length divided by 4, which accounts for multi-byte characters
|
|
683
|
+
* (emojis, CJK, etc.) that typically consume more tokens than ASCII text.
|
|
684
|
+
*
|
|
685
|
+
* @param text - The text to estimate token count for
|
|
686
|
+
* @returns Estimated token count
|
|
687
|
+
*/
|
|
688
|
+
declare function estimateTokens(text: string): number;
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Expands one or more spans from a trace, returning their full details
|
|
692
|
+
* (attributes, events, status) with tree position context.
|
|
693
|
+
*
|
|
694
|
+
* @param spans - The full array of ReadableSpan objects for the trace
|
|
695
|
+
* @param options - Either a single `index` or a `range` string like "10-15"
|
|
696
|
+
* @returns Formatted string with full span details, truncated to ~4000 tokens
|
|
697
|
+
*/
|
|
698
|
+
declare function expandTrace(spans: ReadableSpan[], { index, range }: {
|
|
699
|
+
index?: number;
|
|
700
|
+
range?: string;
|
|
701
|
+
}): string;
|
|
702
|
+
/**
|
|
703
|
+
* Searches across all span attributes, events, and content for a pattern.
|
|
704
|
+
* Returns matching spans with their tree position and matching content.
|
|
705
|
+
*
|
|
706
|
+
* @param spans - The full array of ReadableSpan objects for the trace
|
|
707
|
+
* @param pattern - Case-insensitive search pattern
|
|
708
|
+
* @returns Formatted string with matches, limited to 20 results and ~4000 tokens
|
|
709
|
+
*/
|
|
710
|
+
declare function grepTrace(spans: ReadableSpan[], pattern: string): string;
|
|
711
|
+
|
|
610
712
|
declare class UserSimulatorAgent extends UserSimulatorAgentAdapter {
|
|
611
713
|
private readonly cfg?;
|
|
612
714
|
private logger;
|
|
@@ -855,6 +957,7 @@ declare class RealtimeAgentAdapter extends AgentAdapter {
|
|
|
855
957
|
}
|
|
856
958
|
|
|
857
959
|
type agents_AudioResponseEvent = AudioResponseEvent;
|
|
960
|
+
declare const agents_DEFAULT_TOKEN_THRESHOLD: typeof DEFAULT_TOKEN_THRESHOLD;
|
|
858
961
|
type agents_FinishTestArgs = FinishTestArgs;
|
|
859
962
|
type agents_InvokeLLMParams = InvokeLLMParams;
|
|
860
963
|
type agents_InvokeLLMResult = InvokeLLMResult;
|
|
@@ -868,12 +971,15 @@ type agents_RealtimeAgentAdapter = RealtimeAgentAdapter;
|
|
|
868
971
|
declare const agents_RealtimeAgentAdapter: typeof RealtimeAgentAdapter;
|
|
869
972
|
type agents_RealtimeAgentAdapterConfig = RealtimeAgentAdapterConfig;
|
|
870
973
|
type agents_TestingAgentConfig = TestingAgentConfig;
|
|
974
|
+
declare const agents_estimateTokens: typeof estimateTokens;
|
|
975
|
+
declare const agents_expandTrace: typeof expandTrace;
|
|
976
|
+
declare const agents_grepTrace: typeof grepTrace;
|
|
871
977
|
declare const agents_judgeAgent: typeof judgeAgent;
|
|
872
978
|
declare const agents_judgeSpanCollector: typeof judgeSpanCollector;
|
|
873
979
|
declare const agents_judgeSpanDigestFormatter: typeof judgeSpanDigestFormatter;
|
|
874
980
|
declare const agents_userSimulatorAgent: typeof userSimulatorAgent;
|
|
875
981
|
declare namespace agents {
|
|
876
|
-
export { type agents_AudioResponseEvent as AudioResponseEvent, type agents_FinishTestArgs as FinishTestArgs, type agents_InvokeLLMParams as InvokeLLMParams, type agents_InvokeLLMResult as InvokeLLMResult, type agents_JudgeAgentConfig as JudgeAgentConfig, type agents_JudgeResult as JudgeResult, agents_JudgeSpanCollector as JudgeSpanCollector, agents_JudgeSpanDigestFormatter as JudgeSpanDigestFormatter, agents_RealtimeAgentAdapter as RealtimeAgentAdapter, type agents_RealtimeAgentAdapterConfig as RealtimeAgentAdapterConfig, type agents_TestingAgentConfig as TestingAgentConfig, agents_judgeAgent as judgeAgent, agents_judgeSpanCollector as judgeSpanCollector, agents_judgeSpanDigestFormatter as judgeSpanDigestFormatter, agents_userSimulatorAgent as userSimulatorAgent };
|
|
982
|
+
export { type agents_AudioResponseEvent as AudioResponseEvent, agents_DEFAULT_TOKEN_THRESHOLD as DEFAULT_TOKEN_THRESHOLD, type agents_FinishTestArgs as FinishTestArgs, type agents_InvokeLLMParams as InvokeLLMParams, type agents_InvokeLLMResult as InvokeLLMResult, type agents_JudgeAgentConfig as JudgeAgentConfig, type agents_JudgeResult as JudgeResult, agents_JudgeSpanCollector as JudgeSpanCollector, agents_JudgeSpanDigestFormatter as JudgeSpanDigestFormatter, agents_RealtimeAgentAdapter as RealtimeAgentAdapter, type agents_RealtimeAgentAdapterConfig as RealtimeAgentAdapterConfig, type agents_TestingAgentConfig as TestingAgentConfig, agents_estimateTokens as estimateTokens, agents_expandTrace as expandTrace, agents_grepTrace as grepTrace, agents_judgeAgent as judgeAgent, agents_judgeSpanCollector as judgeSpanCollector, agents_judgeSpanDigestFormatter as judgeSpanDigestFormatter, agents_userSimulatorAgent as userSimulatorAgent };
|
|
877
983
|
}
|
|
878
984
|
|
|
879
985
|
/**
|
|
@@ -914,35 +1020,39 @@ declare const scenarioEventSchema: z$1.ZodDiscriminatedUnion<"type", [z$1.ZodObj
|
|
|
914
1020
|
metadata: z$1.ZodObject<{
|
|
915
1021
|
name: z$1.ZodOptional<z$1.ZodString>;
|
|
916
1022
|
description: z$1.ZodOptional<z$1.ZodString>;
|
|
917
|
-
}, "strip", z$1.
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
}, {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
}
|
|
1023
|
+
}, "strip", z$1.ZodUnknown, z$1.objectOutputType<{
|
|
1024
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
1025
|
+
description: z$1.ZodOptional<z$1.ZodString>;
|
|
1026
|
+
}, z$1.ZodUnknown, "strip">, z$1.objectInputType<{
|
|
1027
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
1028
|
+
description: z$1.ZodOptional<z$1.ZodString>;
|
|
1029
|
+
}, z$1.ZodUnknown, "strip">>;
|
|
924
1030
|
}, "strip", z$1.ZodTypeAny, {
|
|
925
1031
|
type: ScenarioEventType.RUN_STARTED;
|
|
1032
|
+
metadata: {
|
|
1033
|
+
name?: string | undefined;
|
|
1034
|
+
description?: string | undefined;
|
|
1035
|
+
} & {
|
|
1036
|
+
[k: string]: unknown;
|
|
1037
|
+
};
|
|
926
1038
|
timestamp: number;
|
|
927
1039
|
batchRunId: string;
|
|
928
1040
|
scenarioId: string;
|
|
929
1041
|
scenarioRunId: string;
|
|
930
1042
|
scenarioSetId: string;
|
|
931
|
-
metadata: {
|
|
932
|
-
description?: string | undefined;
|
|
933
|
-
name?: string | undefined;
|
|
934
|
-
};
|
|
935
1043
|
rawEvent?: any;
|
|
936
1044
|
}, {
|
|
937
1045
|
type: ScenarioEventType.RUN_STARTED;
|
|
1046
|
+
metadata: {
|
|
1047
|
+
name?: string | undefined;
|
|
1048
|
+
description?: string | undefined;
|
|
1049
|
+
} & {
|
|
1050
|
+
[k: string]: unknown;
|
|
1051
|
+
};
|
|
938
1052
|
timestamp: number;
|
|
939
1053
|
batchRunId: string;
|
|
940
1054
|
scenarioId: string;
|
|
941
1055
|
scenarioRunId: string;
|
|
942
|
-
metadata: {
|
|
943
|
-
description?: string | undefined;
|
|
944
|
-
name?: string | undefined;
|
|
945
|
-
};
|
|
946
1056
|
rawEvent?: any;
|
|
947
1057
|
scenarioSetId?: string | undefined;
|
|
948
1058
|
}>, z$1.ZodObject<{
|
|
@@ -1363,13 +1473,18 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1363
1473
|
* - RUN_FINISHED: When scenario execution completes (success/failure/error)
|
|
1364
1474
|
*/
|
|
1365
1475
|
readonly events$: Observable<ScenarioEvent>;
|
|
1476
|
+
/** Batch run ID for grouping scenario runs */
|
|
1477
|
+
private batchRunId;
|
|
1478
|
+
/** The run ID for the current execution */
|
|
1479
|
+
private scenarioRunId?;
|
|
1366
1480
|
/**
|
|
1367
1481
|
* Creates a new ScenarioExecution instance.
|
|
1368
1482
|
*
|
|
1369
1483
|
* @param config - The scenario configuration containing agents, settings, and metadata
|
|
1370
1484
|
* @param script - The ordered sequence of script steps that define the test flow
|
|
1485
|
+
* @param batchRunId - Batch run ID for grouping scenario runs
|
|
1371
1486
|
*/
|
|
1372
|
-
constructor(config: ScenarioConfig, script: ScriptStep[]);
|
|
1487
|
+
constructor(config: ScenarioConfig, script: ScriptStep[], batchRunId: string);
|
|
1373
1488
|
/**
|
|
1374
1489
|
* Gets the complete conversation history as an array of messages.
|
|
1375
1490
|
*
|
|
@@ -1728,7 +1843,7 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1728
1843
|
* - Creates a new ScenarioExecutionState with the current config
|
|
1729
1844
|
* - Sets up the thread ID (generates new one if not provided)
|
|
1730
1845
|
* - Initializes all agents
|
|
1731
|
-
* -
|
|
1846
|
+
* - Initializes turn state (pending agents/roles) without creating a trace span
|
|
1732
1847
|
* - Records the start time for performance tracking
|
|
1733
1848
|
* - Clears any pending messages
|
|
1734
1849
|
* - Clears the result from any previous execution
|
|
@@ -1907,6 +2022,25 @@ declare namespace execution {
|
|
|
1907
2022
|
export { execution_ScenarioExecution as ScenarioExecution, execution_ScenarioExecutionState as ScenarioExecutionState, type execution_StateChangeEvent as StateChangeEvent, execution_StateChangeEventType as StateChangeEventType };
|
|
1908
2023
|
}
|
|
1909
2024
|
|
|
2025
|
+
/**
|
|
2026
|
+
* Configuration for LangWatch event reporting.
|
|
2027
|
+
* All fields are optional — any omitted fields fall back to environment variables.
|
|
2028
|
+
*/
|
|
2029
|
+
interface LangwatchConfig {
|
|
2030
|
+
/** The endpoint URL to send events to. Falls back to LANGWATCH_ENDPOINT env var. */
|
|
2031
|
+
endpoint?: string;
|
|
2032
|
+
/** The API key for authentication. Falls back to LANGWATCH_API_KEY env var. */
|
|
2033
|
+
apiKey?: string;
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Options for running a scenario.
|
|
2037
|
+
*/
|
|
2038
|
+
interface RunOptions {
|
|
2039
|
+
/** LangWatch configuration for event reporting. Overrides environment variables. */
|
|
2040
|
+
langwatch?: LangwatchConfig;
|
|
2041
|
+
/** Batch run ID for grouping scenario runs. Overrides SCENARIO_BATCH_RUN_ID env var. */
|
|
2042
|
+
batchRunId?: string;
|
|
2043
|
+
}
|
|
1910
2044
|
/**
|
|
1911
2045
|
* High-level interface for running a scenario test.
|
|
1912
2046
|
*
|
|
@@ -1956,11 +2090,13 @@ declare namespace execution {
|
|
|
1956
2090
|
* main();
|
|
1957
2091
|
* ```
|
|
1958
2092
|
*/
|
|
1959
|
-
declare function run(cfg: ScenarioConfig): Promise<ScenarioResult>;
|
|
2093
|
+
declare function run(cfg: ScenarioConfig, options?: RunOptions): Promise<ScenarioResult>;
|
|
1960
2094
|
|
|
2095
|
+
type runner_LangwatchConfig = LangwatchConfig;
|
|
2096
|
+
type runner_RunOptions = RunOptions;
|
|
1961
2097
|
declare const runner_run: typeof run;
|
|
1962
2098
|
declare namespace runner {
|
|
1963
|
-
export { runner_run as run };
|
|
2099
|
+
export { type runner_LangwatchConfig as LangwatchConfig, type runner_RunOptions as RunOptions, runner_run as run };
|
|
1964
2100
|
}
|
|
1965
2101
|
|
|
1966
2102
|
/**
|
|
@@ -2068,7 +2204,107 @@ declare namespace script {
|
|
|
2068
2204
|
export { script_agent as agent, script_fail as fail, script_judge as judge, script_message as message, script_proceed as proceed, script_succeed as succeed, script_user as user };
|
|
2069
2205
|
}
|
|
2070
2206
|
|
|
2207
|
+
/**
|
|
2208
|
+
* Explicitly set up tracing for @langwatch/scenario.
|
|
2209
|
+
*
|
|
2210
|
+
* Call this before any `run()` invocations when you want full control
|
|
2211
|
+
* over the observability configuration. If called, `run()` will skip
|
|
2212
|
+
* its own lazy initialization.
|
|
2213
|
+
*
|
|
2214
|
+
* The `judgeSpanCollector` is always added as a span processor regardless
|
|
2215
|
+
* of the user-provided options.
|
|
2216
|
+
*
|
|
2217
|
+
* @param options - Optional `SetupObservabilityOptions` forwarded to the
|
|
2218
|
+
* langwatch SDK `setupObservability()` function.
|
|
2219
|
+
*
|
|
2220
|
+
* @example
|
|
2221
|
+
* ```typescript
|
|
2222
|
+
* import { setupScenarioTracing } from "@langwatch/scenario";
|
|
2223
|
+
*
|
|
2224
|
+
* setupScenarioTracing({
|
|
2225
|
+
* instrumentations: [], // disable auto-instrumentation
|
|
2226
|
+
* spanProcessors: [myProcessor], // add custom processors
|
|
2227
|
+
* });
|
|
2228
|
+
* ```
|
|
2229
|
+
*/
|
|
2230
|
+
declare function setupScenarioTracing(options?: Partial<SetupObservabilityOptions>): void;
|
|
2231
|
+
|
|
2232
|
+
/**
|
|
2233
|
+
* Criteria for matching spans by instrumentation scope name or span name.
|
|
2234
|
+
* Within each field, matchers use OR semantics (any match succeeds).
|
|
2235
|
+
* Across fields, AND semantics apply (all specified fields must match).
|
|
2236
|
+
*/
|
|
2237
|
+
interface TraceFilterCriteria {
|
|
2238
|
+
instrumentationScopeName?: TraceFilterMatch[];
|
|
2239
|
+
name?: TraceFilterMatch[];
|
|
2240
|
+
}
|
|
2241
|
+
/**
|
|
2242
|
+
* A single match rule for string comparison.
|
|
2243
|
+
*/
|
|
2244
|
+
interface TraceFilterMatch {
|
|
2245
|
+
equals?: string;
|
|
2246
|
+
startsWith?: string;
|
|
2247
|
+
matches?: RegExp;
|
|
2248
|
+
ignoreCase?: boolean;
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* A filter rule for controlling which spans are exported.
|
|
2252
|
+
*
|
|
2253
|
+
* Compatible with the langwatch SDK's `TraceFilter` type used by
|
|
2254
|
+
* `LangWatchTraceExporter`.
|
|
2255
|
+
*/
|
|
2256
|
+
type TraceFilter = {
|
|
2257
|
+
preset: "vercelAIOnly" | "excludeHttpRequests";
|
|
2258
|
+
} | {
|
|
2259
|
+
include: TraceFilterCriteria;
|
|
2260
|
+
} | {
|
|
2261
|
+
exclude: TraceFilterCriteria;
|
|
2262
|
+
};
|
|
2263
|
+
/**
|
|
2264
|
+
* Preset filter that only keeps spans from the @langwatch/scenario instrumentation scope.
|
|
2265
|
+
* Use this to prevent unrelated server spans (HTTP, middleware, etc.) from being exported.
|
|
2266
|
+
*
|
|
2267
|
+
* @example
|
|
2268
|
+
* ```typescript
|
|
2269
|
+
* import { defineConfig, scenarioOnly } from "@langwatch/scenario";
|
|
2270
|
+
* import { LangWatchTraceExporter } from "langwatch/observability";
|
|
2271
|
+
*
|
|
2272
|
+
* export default defineConfig({
|
|
2273
|
+
* observability: {
|
|
2274
|
+
* traceExporter: new LangWatchTraceExporter({
|
|
2275
|
+
* filters: scenarioOnly,
|
|
2276
|
+
* }),
|
|
2277
|
+
* instrumentations: [], // disable auto-instrumentation
|
|
2278
|
+
* },
|
|
2279
|
+
* });
|
|
2280
|
+
* ```
|
|
2281
|
+
*/
|
|
2282
|
+
declare const scenarioOnly: TraceFilter[];
|
|
2283
|
+
/**
|
|
2284
|
+
* Creates a filter that keeps spans from the @langwatch/scenario scope
|
|
2285
|
+
* plus any additional custom instrumentation scopes.
|
|
2286
|
+
*
|
|
2287
|
+
* @param scopes - Additional instrumentation scope names to include
|
|
2288
|
+
* @returns Array of TraceFilter rules
|
|
2289
|
+
*
|
|
2290
|
+
* @example
|
|
2291
|
+
* ```typescript
|
|
2292
|
+
* import { defineConfig, withCustomScopes } from "@langwatch/scenario";
|
|
2293
|
+
* import { LangWatchTraceExporter } from "langwatch/observability";
|
|
2294
|
+
*
|
|
2295
|
+
* export default defineConfig({
|
|
2296
|
+
* observability: {
|
|
2297
|
+
* traceExporter: new LangWatchTraceExporter({
|
|
2298
|
+
* filters: withCustomScopes("my-app/database", "my-app/agent"),
|
|
2299
|
+
* }),
|
|
2300
|
+
* instrumentations: [], // disable auto-instrumentation
|
|
2301
|
+
* },
|
|
2302
|
+
* });
|
|
2303
|
+
* ```
|
|
2304
|
+
*/
|
|
2305
|
+
declare function withCustomScopes(...scopes: string[]): TraceFilter[];
|
|
2306
|
+
|
|
2071
2307
|
type ScenarioApi = typeof agents & typeof domain & typeof execution & typeof runner & typeof script;
|
|
2072
2308
|
declare const scenario: ScenarioApi;
|
|
2073
2309
|
|
|
2074
|
-
export { AgentAdapter, type AgentInput, type AgentReturnTypes, AgentRole, type AudioResponseEvent, DEFAULT_MAX_TURNS, DEFAULT_VERBOSE, type FinishTestArgs, type InvokeLLMParams, type InvokeLLMResult, JudgeAgentAdapter, type JudgeAgentConfig, type JudgeResult, JudgeSpanCollector, JudgeSpanDigestFormatter, type JudgmentRequest, RealtimeAgentAdapter, type RealtimeAgentAdapterConfig, type ScenarioConfig, type ScenarioConfigFinal, ScenarioExecution, type ScenarioExecutionLike, ScenarioExecutionState, type ScenarioExecutionStateLike, type ScenarioProjectConfig, type ScenarioResult, type ScriptStep, type StateChangeEvent, StateChangeEventType, type TestingAgentConfig, UserSimulatorAgentAdapter, agent, allAgentRoles, scenario as default, defineConfig, fail, judge, judgeAgent, judgeSpanCollector, judgeSpanDigestFormatter, message, proceed, run, scenario, scenarioProjectConfigSchema, succeed, user, userSimulatorAgent };
|
|
2310
|
+
export { AgentAdapter, type AgentInput, type AgentReturnTypes, AgentRole, type AudioResponseEvent, DEFAULT_MAX_TURNS, DEFAULT_TOKEN_THRESHOLD, DEFAULT_VERBOSE, type FinishTestArgs, type InvokeLLMParams, type InvokeLLMResult, JudgeAgentAdapter, type JudgeAgentConfig, type JudgeResult, JudgeSpanCollector, JudgeSpanDigestFormatter, type JudgmentRequest, type LangwatchConfig, RealtimeAgentAdapter, type RealtimeAgentAdapterConfig, type RunOptions, type ScenarioConfig, type ScenarioConfigFinal, ScenarioExecution, type ScenarioExecutionLike, ScenarioExecutionState, type ScenarioExecutionStateLike, type ScenarioProjectConfig, type ScenarioResult, type ScriptStep, type StateChangeEvent, StateChangeEventType, type TestingAgentConfig, UserSimulatorAgentAdapter, agent, allAgentRoles, scenario as default, defineConfig, estimateTokens, expandTrace, fail, grepTrace, judge, judgeAgent, judgeSpanCollector, judgeSpanDigestFormatter, message, proceed, run, scenario, scenarioOnly, scenarioProjectConfigSchema, setupScenarioTracing, succeed, user, userSimulatorAgent, withCustomScopes };
|