@langwatch/scenario 0.2.13 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,7 +78,7 @@ import { describe, it, expect } from "vitest";
78
78
  import { openai } from "@ai-sdk/openai";
79
79
  import scenario, { type AgentAdapter, AgentRole } from "@langwatch/scenario";
80
80
  import { generateText, tool } from "ai";
81
- import { z } from "zod";
81
+ import { z } from "zod/v4";
82
82
 
83
83
  describe("Weather Agent", () => {
84
84
  it("should get the weather for a city", async () => {
@@ -103,13 +103,40 @@ describe("Weather Agent", () => {
103
103
  tools: { get_current_weather: getCurrentWeather },
104
104
  });
105
105
 
106
- if (response.toolCalls?.length) {
107
- // For simplicity, we'll just return the arguments of the first tool call
108
- const { toolName, args } = response.toolCalls[0];
109
- return {
110
- role: "tool",
111
- content: [{ type: "tool-result", toolName, result: args }],
112
- };
106
+ if (response.toolCalls && response.toolCalls.length > 0) {
107
+ const toolCall = response.toolCalls[0];
108
+ // Agent executes the tool directly and returns both messages
109
+ const toolResult = await getCurrentWeather.execute(
110
+ toolCall.input as { city: string },
111
+ {
112
+ toolCallId: toolCall.toolCallId,
113
+ messages: input.messages,
114
+ }
115
+ );
116
+ return [
117
+ {
118
+ role: "assistant",
119
+ content: [
120
+ {
121
+ type: "tool-call",
122
+ toolName: toolCall.toolName,
123
+ toolCallId: toolCall.toolCallId,
124
+ input: toolCall.input,
125
+ },
126
+ ],
127
+ },
128
+ {
129
+ role: "tool",
130
+ content: [
131
+ {
132
+ type: "tool-result",
133
+ toolName: toolCall.toolName,
134
+ toolCallId: toolCall.toolCallId,
135
+ output: { type: "text", value: toolResult as string },
136
+ },
137
+ ],
138
+ },
139
+ ];
113
140
  }
114
141
 
115
142
  return response.text;
@@ -138,7 +165,7 @@ describe("Weather Agent", () => {
138
165
 
139
166
  // 4. Assert the final result
140
167
  expect(result.success).toBe(true);
141
- });
168
+ }, 30_000); // 30s test timeout
142
169
  });
143
170
  ```
144
171