mirror of
https://github.com/langchain-ai/deepagentsjs.git
synced 2026-07-20 19:40:28 -04:00
254895457f
### Summary - Rename `createQuickJSMiddleware` → `createREPLMiddleware` and `QuickJSMiddlewareOptions` → `REPLMiddlewareOptions` to match the Python `REPLMiddleware` naming - Rename middleware registration from `"QuickJSMiddleware"` → `"REPLMiddleware"` - Rename default tool name from `"js_eval"` → `"eval"`, now configurable via `toolName` option - Add `captureConsole` option (default `true`) to toggle console output capture - Align default memory limit to 64 MiB (was 50 MiB) and timeout to 5s (was 30s) to match Python ### Tests - All 156 existing unit tests pass with updated references - Updated `middleware.test.ts`, `middleware.int.test.ts`, and example files to use new names --------- Co-authored-by: Hunter Lovell <40191806+hntrl@users.noreply.github.com>
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
/**
|
|
* Data Analysis Agent Example
|
|
*
|
|
* Demonstrates the QuickJS REPL as a computational scratch pad.
|
|
* The agent reads data from the VFS, processes it in sandboxed JavaScript,
|
|
* and writes results back — all without network access or Node.js APIs.
|
|
*
|
|
* This is useful for tasks where LLMs typically hallucinate:
|
|
* - Arithmetic and statistical calculations
|
|
* - Sorting, filtering, grouping data
|
|
* - JSON transformation and restructuring
|
|
* - Multi-step logic with intermediate state
|
|
*/
|
|
import "dotenv/config";
|
|
import dedent from "dedent";
|
|
import { HumanMessage } from "@langchain/core/messages";
|
|
import { ChatAnthropic } from "@langchain/anthropic";
|
|
import { createDeepAgent } from "deepagents";
|
|
import { createREPLMiddleware } from "@langchain/quickjs";
|
|
|
|
const model = new ChatAnthropic({
|
|
model: "claude-sonnet-4-5",
|
|
temperature: 0,
|
|
});
|
|
|
|
const agent = createDeepAgent({
|
|
model,
|
|
systemPrompt: dedent`
|
|
You are a data analyst. Use the eval REPL to perform calculations
|
|
and data transformations. Always show your work in code — never guess
|
|
at arithmetic or statistics.
|
|
`,
|
|
middleware: [createREPLMiddleware()],
|
|
});
|
|
|
|
const result = await agent.invoke({
|
|
messages: [
|
|
new HumanMessage(dedent`
|
|
I have sales data in /data/sales.json. Parse it, calculate the total
|
|
revenue per region, find the top-performing region, and write a
|
|
summary report to /reports/sales-summary.md.
|
|
`),
|
|
],
|
|
});
|
|
|
|
const last = result.messages[result.messages.length - 1];
|
|
console.log(
|
|
typeof last.content === "string" ? last.content.slice(0, 500) : last.content,
|
|
);
|