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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.0]

### Added

- `Conversations.uploadMemories` for `POST /conversations/{id}/memories`, which
bulk uploads a batch of memories scoped to a conversation for the agent to
search over on demand.

## [0.1.2]

### Added

- Initial release of the Gradient Labs Node.js / TypeScript client.
12 changes: 11 additions & 1 deletion examples/conversations/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Conversations example: starts a conversation, sends a customer message, reads
* it back, then finishes it.
* it back, uploads a batch of memories, then finishes it.
*
* In your own project, import from the published package:
* import { GradientLabs } from "@gradientlabs/client";
Expand Down Expand Up @@ -37,6 +37,16 @@ async function main(): Promise<void> {
const fetched = await client.conversations.get(id);
console.log("Read conversation, latest intent:", fetched.latest_intent || "(none yet)");

const upload = await client.conversations.uploadMemories(id, {
idempotency_key: `memories-${Date.now()}`,
memories: [
{ kind: "order", order_id: "A-1001", status: "shipped", occurred_at: "2026-01-01T00:00:00Z" },
{ kind: "preference", channel: "email" },
],
created_at_keys: ["occurred_at"],
});
console.log("Uploaded memories:", upload.upload_id, upload.memories_inserted);

await client.conversations.finish(id, {
reason: "example complete",
reason_code: "customer-ended-chat",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gradientlabs/client",
"version": "0.1.2",
"version": "0.2.0",
"description": "Official Node.js / TypeScript client for the Gradient Labs API",
"type": "module",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Kept in sync with the "version" field in package.json.
export const VERSION = "0.1.2";
export const VERSION = "0.2.0";
20 changes: 20 additions & 0 deletions src/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ export interface ReadConversationParams {
support_platform?: string;
}

export interface MemoriesBulkUploadParams {
/**
* De-duplicates retries of the same upload. Re-uploading with the same key
* returns the original upload instead of inserting again.
*/
idempotency_key: string;
/** The individual memories to store; each element is kept verbatim as the memory's raw payload. */
memories: Record<string, unknown>[];
/**
* JSON keys tried in order to read each memory's timestamp from its payload.
* When none match, the upload time is used.
*/
created_at_keys?: string[];
}

export interface MemoriesBulkUploadResult {
upload_id: string;
memories_inserted: number;
}

export interface StartOutboundConversationParams {
customer_id: string;
customer_source: CustomerSource;
Expand Down
14 changes: 14 additions & 0 deletions src/resources/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type {
Conversation,
ConversationEventParams,
FinishConversationParams,
MemoriesBulkUploadParams,
MemoriesBulkUploadResult,
Message,
ReadConversationParams,
RateConversationParams,
Expand Down Expand Up @@ -121,6 +123,18 @@ export class Conversations {
});
}

/** Bulk uploads a batch of memories scoped to a conversation for the agent to search over on demand. */
uploadMemories(
id: string,
params: MemoriesBulkUploadParams,
config: RequestConfig = {},
): Promise<MemoriesBulkUploadResult> {
return this.http.request("POST", `conversations/${encodeURIComponent(id)}/memories`, {
body: params,
signal: config.signal,
});
}

/** Returns the result of an async tool execution. */
returnAsyncToolResult(
id: string,
Expand Down
26 changes: 26 additions & 0 deletions test/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ describe("HttpClient", () => {
expect(record[0]!.body).toBeUndefined();
});

it("bulk uploads conversation memories and returns the upload result", async () => {
const record: RecordedRequest[] = [];
const client = new GradientLabs({
apiKey: "sk_test_123",
fetch: fakeFetch(
{ status: 200, body: JSON.stringify({ upload_id: "upl_1", memories_inserted: 2 }) },
record,
),
});

const result = await client.conversations.uploadMemories("conv_1", {
idempotency_key: "key-123",
memories: [{ note: "prefers email" }, { order_id: "A1", ts: "2026-01-01T00:00:00Z" }],
created_at_keys: ["ts", "created_at"],
});

expect(result).toEqual({ upload_id: "upl_1", memories_inserted: 2 });
expect(record).toHaveLength(1);
expect(record[0]!.method).toBe("POST");
expect(record[0]!.input).toBe("https://api.gradient-labs.ai/conversations/conv_1/memories");
const body = JSON.parse(record[0]!.body!);
expect(body.idempotency_key).toBe("key-123");
expect(body.memories).toHaveLength(2);
expect(body.created_at_keys).toEqual(["ts", "created_at"]);
});

it("respects a custom base URL", async () => {
const record: RecordedRequest[] = [];
const client = new GradientLabs({
Expand Down
Loading