Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sdk-trace-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"deepagents": patch
---

feat(deepagents): Add SDK version metadata to agent traces
14 changes: 13 additions & 1 deletion libs/deepagents/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ import type {
import type * as _messages from "@langchain/core/messages";
import type * as _Command from "@langchain/langgraph";

/**
* SDK version injected at build time by tsdown's `define` option.
* Falls back to "unknown" during tests or when not built via tsdown.
*/
declare const __SDK_VERSION__: string;

const BASE_PROMPT = `In order to complete the objective that the user asks of you, you have access to a number of standard tools.`;

/**
Expand Down Expand Up @@ -304,7 +310,13 @@ export function createDeepAgent<
checkpointer,
store,
name,
}).withConfig({ recursionLimit: 10_000 });
}).withConfig({
recursionLimit: 10_000,
metadata: {
sdk: "deepagents-js",
sdk_version: __SDK_VERSION__,
},
});

/**
* Combine custom middleware with flattened subagent middleware for complete type inference
Expand Down
11 changes: 11 additions & 0 deletions libs/deepagents/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { defineConfig } from "tsdown";
import { version } from "./package.json" with { type: "json" };

// Mark all node_modules as external since this is a library
const external = [/^[^./]/];

const { version } = JSON.parse(
readFileSync(new URL("./package.json", import.meta.url), "utf-8"),
);

export default defineConfig([
{
entry: ["./src/index.ts"],
Expand All @@ -13,6 +18,9 @@ export default defineConfig([
outDir: "dist",
outExtensions: () => ({ js: ".js" }),
external,
define: {
__SDK_VERSION__: JSON.stringify(version),
},
},
{
entry: ["./src/index.ts"],
Expand All @@ -23,5 +31,8 @@ export default defineConfig([
outDir: "dist",
outExtensions: () => ({ js: ".cjs" }),
external,
define: {
__SDK_VERSION__: JSON.stringify(version),
},
},
]);
10 changes: 10 additions & 0 deletions libs/deepagents/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "node:path";
import { version } from "./package.json" with { type: "json" };
import {
configDefaults,
defineConfig,
Expand All @@ -9,8 +10,15 @@ import dotenv from "dotenv";
// Load .env from workspace root (two levels up from libs/deepagents)
dotenv.config({ path: path.resolve(__dirname, "../../.env") });

const { version } = JSON.parse(
readFileSync(path.resolve(__dirname, "package.json"), "utf-8"),
);

export default defineConfig((env) => {
const common: ViteUserConfigExport = {
define: {
__SDK_VERSION__: JSON.stringify(version),
},
test: {
environment: "node",
hideSkippedTests: true,
Expand All @@ -27,6 +35,7 @@ export default defineConfig((env) => {

if (env.mode === "int") {
return {
define: common.define,
test: {
...common.test,
globals: false,
Expand All @@ -39,6 +48,7 @@ export default defineConfig((env) => {
}

return {
define: common.define,
test: {
...common.test,
include: ["src/**/*.test.ts"],
Expand Down
Loading