@mutagent/sdk 0.2.123 → 0.2.127
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 +4 -56
- package/README.npm.md +1040 -0
- package/dist/commonjs/lib/config.d.ts +3 -3
- package/dist/commonjs/lib/config.js +3 -3
- package/dist/esm/lib/config.d.ts +3 -3
- package/dist/esm/lib/config.js +3 -3
- package/package.json +1 -1
- package/src/lib/config.ts +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# MutagenT SDK
|
|
2
2
|
|
|
3
|
+
<!-- NOTE: README.npm.md is the public-facing README for npm publish.
|
|
4
|
+
See publish workflow for copy step. -->
|
|
5
|
+
|
|
3
6
|
```bash
|
|
4
7
|
╔════════════════════════════════════════════════════════════════════════════════════════════╗
|
|
5
8
|
║ ║
|
|
@@ -545,61 +548,7 @@ This software is proprietary and confidential. Unauthorized copying, distributio
|
|
|
545
548
|
|
|
546
549
|
---
|
|
547
550
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
This section provides an overview of which API endpoints are included in the SDK and which are excluded.
|
|
551
|
-
|
|
552
|
-
### Included in SDK (Public API)
|
|
553
|
-
|
|
554
|
-
The following namespaces and methods are available in the SDK:
|
|
555
|
-
|
|
556
|
-
| Namespace | Key Methods | Description |
|
|
557
|
-
|-----------|-------------|-------------|
|
|
558
|
-
| `prompt` | `createPrompt`, `listPrompts`, `getPrompt`, `updatePrompt`, `deletePrompt`, `createPromptVersion` | Prompt management and versioning |
|
|
559
|
-
| `promptDatasets` | `listPromptDatasets`, `getPromptDataset`, `updatePromptDataset`, `deletePromptDataset`, `clonePromptDataset`, `exportPromptDataset`, `listDatasetsForPrompt`, `createPromptDataset` | Dataset operations for prompts |
|
|
560
|
-
| `promptDatasetItems` | `listPromptDatasetItems`, `createPromptDatasetItem`, `bulkCreatePromptDatasetItems`, `getPromptDatasetItem`, `updatePromptDatasetItem`, `deletePromptDatasetItem` | Dataset item CRUD operations |
|
|
561
|
-
| `promptEvaluations` | `listEvaluations`, `createEvaluation`, `getEvaluation`, `runEvaluation`, `getEvaluationResult` | Evaluation engine for prompts |
|
|
562
|
-
| `playground` | `playgroundCall`, `playgroundEval` | Interactive testing and experimentation |
|
|
563
|
-
| `optimization` | `optimizePrompt`, `getOptimization`, `listOptimizations`, `getOptimizationProgress`, `pauseOptimization`, `resumeOptimization`, `cancelOptimization` | Auto-optimization with MetaTuner |
|
|
564
|
-
| `agents` | `listAgents`, `createAgent`, `getAgent`, `getAgentBySlug`, `updateAgent`, `deleteAgent` | Agent CRUD operations |
|
|
565
|
-
| `agentConversations` | `listAgentConversations`, `createAgentConversation` | Agent conversation management |
|
|
566
|
-
| `conversations` | `getConversation`, `updateConversation`, `deleteConversation`, `listConversationMessages`, `sendConversationMessage`, `forkConversation` | Conversation operations |
|
|
567
|
-
| `agentChatStreaming` | `sendStreamMessage`, `getStreamEvents` | Real-time streaming chat |
|
|
568
|
-
| `agentDatasets` | `listAgentDatasets`, `createAgentDataset`, `getAgentDataset`, `updateAgentDataset`, `deleteAgentDataset`, `cloneAgentDataset`, `exportAgentDataset`, `getAgentDatasetStatistics` | Agent evaluation datasets |
|
|
569
|
-
| `agentDatasetItems` | `listAgentDatasetItems`, `createAgentDatasetItem`, `bulkCreateAgentDatasetItems`, `getAgentDatasetItem`, `updateAgentDatasetItem`, `deleteAgentDatasetItem` | Agent dataset item operations |
|
|
570
|
-
| `agentMCPServers` | `listAgentMcpServers`, `addAgentMcpServer` | MCP server configuration |
|
|
571
|
-
| `organizations` | `createOrganization`, `listOrganizations`, `getOrganization`, `updateOrganization`, `deleteOrganization`, `getOrganizationBySlug`, `checkOrganizationSlug`, `getOrganizationMemberCount` | Organization management |
|
|
572
|
-
| `organizationMembers` | `listOrganizationMembers`, `addOrganizationMember`, `updateOrganizationMember`, `removeOrganizationMember` | Organization membership |
|
|
573
|
-
| `workspaces` | `listWorkspaces`, `createWorkspace`, `getWorkspace`, `updateWorkspace`, `deleteWorkspace`, `setDefaultWorkspace` | Workspace management |
|
|
574
|
-
| `workspaceMembers` | `listWorkspaceMembers`, `addWorkspaceMember`, `updateWorkspaceMember`, `removeWorkspaceMember` | Workspace membership |
|
|
575
|
-
| `providerConfigs` | `listProviders`, `createProvider`, `getProvider`, `updateProvider`, `deleteProvider`, `testProvider` | LLM provider configurations |
|
|
576
|
-
| `traces` | `ingestTrace`, `listTraces`, `ingestTraceBatch`, `ingestOtlp`, `getTraceStats`, `getTrace`, `deleteTrace` | Trace observability and ingestion |
|
|
577
|
-
| `userProfile` | `getProfile`, `updateProfile`, `changePassword`, `deleteAccount`, `listSessions`, `deleteSession` | User profile management |
|
|
578
|
-
| `invitations` | `createInvitation`, `listInvitations`, `getInvitation`, `deleteInvitation`, `resendInvitation` | Invitation management |
|
|
579
|
-
|
|
580
|
-
### Excluded from SDK (Internal/Admin Only)
|
|
581
|
-
|
|
582
|
-
The following endpoints are intentionally excluded from the SDK:
|
|
583
|
-
|
|
584
|
-
| Module | Reason for Exclusion |
|
|
585
|
-
|--------|---------------------|
|
|
586
|
-
| Health checks (`/health`) | Infrastructure monitoring endpoints - not needed in application code |
|
|
587
|
-
| Hello/Debug (`/hello`) | Development testing endpoints only |
|
|
588
|
-
| Auth validation (`/api/auth`) | Internal server-side authentication validation |
|
|
589
|
-
| Session management (`/api/sessions`) | Use `userProfile.listSessions()` instead |
|
|
590
|
-
| API key management (`/api/api-keys`) | Managed through Admin Panel only for security |
|
|
591
|
-
| MCP servers (`/api/mcp-servers`) | Managed through `agentMCPServers` namespace instead |
|
|
592
|
-
| Internal stats (`/api/stats`) | Admin Panel analytics only |
|
|
593
|
-
|
|
594
|
-
### Manual Modules (Not Generated by Speakeasy)
|
|
595
|
-
|
|
596
|
-
The following modules are manually maintained and not auto-generated:
|
|
597
|
-
|
|
598
|
-
| Module | Import Path | Key Exports |
|
|
599
|
-
|--------|-------------|-------------|
|
|
600
|
-
| **Tracing** | `@mutagent/sdk/tracing` or `@mutagent/sdk` | `initTracing()`, `shutdownTracing()`, `@trace`, `withTrace()`, `startSpan()`, `endSpan()`, `getCurrentSpan()`, `getCurrentTraceId()`, `runInSpanContext()` |
|
|
601
|
-
|
|
602
|
-
**Note**: The tracing module provides full OpenTelemetry-compatible instrumentation for LLM calls, chains, agents, and custom operations. See the [Tracing & Observability](#-tracing--observability) section above for usage examples.
|
|
551
|
+
For full API reference, see [docs.mutagent.io](https://docs.mutagent.io)
|
|
603
552
|
|
|
604
553
|
---
|
|
605
554
|
|
|
@@ -638,7 +587,6 @@ MutagenT Server API Documentation: Comprehensive API documentation for MutagenT
|
|
|
638
587
|
* [📖 API Reference](#api-reference)
|
|
639
588
|
* [🤝 Contributing](#contributing)
|
|
640
589
|
* [📄 License](#license)
|
|
641
|
-
* [📋 SDK Coverage Report](#sdk-coverage-report)
|
|
642
590
|
* [SDK Installation](#sdk-installation)
|
|
643
591
|
* [Requirements](#requirements)
|
|
644
592
|
* [SDK Example Usage](#sdk-example-usage)
|
package/README.npm.md
ADDED
|
@@ -0,0 +1,1040 @@
|
|
|
1
|
+
# @mutagent/sdk
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
███╗ ███╗██╗ ██╗████████╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗
|
|
5
|
+
████╗ ████║██║ ██║╚══██╔══╝██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝
|
|
6
|
+
██╔████╔██║██║ ██║ ██║ ███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║
|
|
7
|
+
██║╚██╔╝██║██║ ██║ ██║ ██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║
|
|
8
|
+
██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║
|
|
9
|
+
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝
|
|
10
|
+
███████╗██████╗ ██╗ ██╗
|
|
11
|
+
██╔════╝██╔══██╗██║ ██╔╝
|
|
12
|
+
███████╗██║ ██║█████╔╝
|
|
13
|
+
╚════██║██║ ██║██╔═██╗
|
|
14
|
+
███████║██████╔╝██║ ██╗
|
|
15
|
+
╚══════╝╚═════╝ ╚═╝ ╚═╝
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://www.npmjs.com/package/@mutagent/sdk"><img src="https://img.shields.io/npm/v/@mutagent/sdk?style=for-the-badge&color=cb3837&logo=npm&logoColor=white" alt="npm"></a>
|
|
20
|
+
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node-18+-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js"></a>
|
|
21
|
+
<a href="https://bun.sh"><img src="https://img.shields.io/badge/Bun-1.1+-f472b6?style=for-the-badge&logo=bun&logoColor=white" alt="Bun"></a>
|
|
22
|
+
<a href="https://www.typescriptlang.org"><img src="https://img.shields.io/badge/TypeScript-5.0+-3178C6?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript"></a>
|
|
23
|
+
<a href="#license"><img src="https://img.shields.io/badge/License-Proprietary-ff6b6b?style=for-the-badge" alt="License: Proprietary"></a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<p align="center">
|
|
27
|
+
<strong>Type-safe. Framework-agnostic. Production-ready.</strong><br>
|
|
28
|
+
<em>The official TypeScript SDK for the MutagenT AI Engineering Platform.</em>
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Table of Contents
|
|
34
|
+
|
|
35
|
+
- [What is MutagenT SDK?](#what-is-mutagent-sdk)
|
|
36
|
+
- [Features](#features)
|
|
37
|
+
- [Installation](#installation)
|
|
38
|
+
- [Quick Start](#quick-start)
|
|
39
|
+
- [Authentication](#authentication)
|
|
40
|
+
- [Prompts](#prompts)
|
|
41
|
+
- [Datasets](#datasets)
|
|
42
|
+
- [Evaluations](#evaluations)
|
|
43
|
+
- [Optimization](#optimization)
|
|
44
|
+
- [Tracing & Observability](#tracing--observability)
|
|
45
|
+
- [Agents](#agents)
|
|
46
|
+
- [Playground](#playground)
|
|
47
|
+
- [Pagination](#pagination)
|
|
48
|
+
- [Retries](#retries)
|
|
49
|
+
- [Error Handling](#error-handling)
|
|
50
|
+
- [Custom HTTP Client](#custom-http-client)
|
|
51
|
+
- [Tree-shakeable Imports](#tree-shakeable-imports)
|
|
52
|
+
- [TypeScript Support](#typescript-support)
|
|
53
|
+
- [Framework Integrations](#framework-integrations)
|
|
54
|
+
- [API Reference](#api-reference)
|
|
55
|
+
- [See Also](#see-also)
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## What is MutagenT SDK?
|
|
60
|
+
|
|
61
|
+
The **MutagenT SDK** is a developer-friendly, type-safe TypeScript client for the [MutagenT AI platform](https://mutagent.io). It gives you programmatic access to everything MutagenT offers: create and version prompts, upload evaluation datasets, run automated evaluations, trigger auto-optimization jobs, collect LLM traces, and manage AI agents — all from your own code.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Features
|
|
66
|
+
|
|
67
|
+
| Feature | Description |
|
|
68
|
+
|---------|-------------|
|
|
69
|
+
| **Prompt Management** | Create, version, update, and delete prompts programmatically |
|
|
70
|
+
| **Dataset Operations** | Upload, export, clone, and manage evaluation datasets |
|
|
71
|
+
| **Evaluation Engine** | Define criteria, run automated evaluations, and retrieve scored results |
|
|
72
|
+
| **Auto-Optimization** | Start optimization jobs that iteratively improve your prompts against metrics |
|
|
73
|
+
| **Tracing & Observability** | OpenTelemetry-compatible tracing for LLM calls, chains, agents, and custom spans |
|
|
74
|
+
| **Agents** | Create and manage AI agents with conversation history and streaming chat |
|
|
75
|
+
| **Playground** | Execute and evaluate prompts interactively without running a full pipeline |
|
|
76
|
+
| **Multi-tenant** | Organizations, workspaces, provider configs, and team membership |
|
|
77
|
+
| **Full Type Safety** | End-to-end TypeScript with Zod-validated responses |
|
|
78
|
+
| **Multiple Runtimes** | Works with Bun, Node.js, Deno, and Edge runtimes |
|
|
79
|
+
| **Tree-shakeable** | Import only what you need for smaller bundles |
|
|
80
|
+
| **Configurable Retries** | Per-call and global retry strategies with exponential backoff |
|
|
81
|
+
| **Pagination** | Async iterable responses for all paginated list endpoints |
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
### npm
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm install @mutagent/sdk
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### pnpm
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pnpm add @mutagent/sdk
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### yarn
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
yarn add @mutagent/sdk
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### bun
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
bun add @mutagent/sdk
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
> This package ships both CommonJS (`require`) and ES Modules (`import`) builds.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Quick Start
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { Mutagent } from '@mutagent/sdk';
|
|
119
|
+
|
|
120
|
+
const mutagent = new Mutagent({
|
|
121
|
+
security: {
|
|
122
|
+
apiKey: process.env.MUTAGENT_API_KEY,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Create a prompt
|
|
127
|
+
const prompt = await mutagent.prompt.createPrompt({
|
|
128
|
+
name: 'Customer Support Template',
|
|
129
|
+
content: 'You are a helpful support agent. User query: {{query}}',
|
|
130
|
+
variables: ['query'],
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Add a dataset
|
|
134
|
+
const dataset = await mutagent.promptDatasets.createPromptDataset({
|
|
135
|
+
id: prompt.id,
|
|
136
|
+
name: 'Support Tickets',
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await mutagent.promptDatasetItems.bulkCreatePromptDatasetItems({
|
|
140
|
+
id: dataset.id,
|
|
141
|
+
items: [
|
|
142
|
+
{ input: { query: 'How do I reset my password?' }, expected: '...' },
|
|
143
|
+
{ input: { query: 'What are your business hours?' }, expected: '...' },
|
|
144
|
+
],
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Start optimization
|
|
148
|
+
const job = await mutagent.optimization.optimizePrompt({
|
|
149
|
+
id: prompt.id,
|
|
150
|
+
datasetId: dataset.id,
|
|
151
|
+
metric: 'response_quality',
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
console.log(`Optimization started: ${job.id}`);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Authentication
|
|
160
|
+
|
|
161
|
+
### API Key
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { Mutagent } from '@mutagent/sdk';
|
|
165
|
+
|
|
166
|
+
const mutagent = new Mutagent({
|
|
167
|
+
security: {
|
|
168
|
+
apiKey: process.env.MUTAGENT_API_KEY,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Bearer Token
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const mutagent = new Mutagent({
|
|
177
|
+
security: {
|
|
178
|
+
bearerAuth: process.env.MUTAGENT_BEARER_AUTH,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Authentication Schemes
|
|
184
|
+
|
|
185
|
+
| Scheme | Type | Environment Variable |
|
|
186
|
+
|--------|------|----------------------|
|
|
187
|
+
| `apiKey` | API Key | `MUTAGENT_API_KEY` |
|
|
188
|
+
| `bearerAuth` | HTTP Bearer | `MUTAGENT_BEARER_AUTH` |
|
|
189
|
+
|
|
190
|
+
Both schemes are supported globally and apply to all operations.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Prompts
|
|
195
|
+
|
|
196
|
+
Prompts are the core resource in MutagenT. Every dataset, evaluation, and optimization job is scoped to a prompt.
|
|
197
|
+
|
|
198
|
+
### Create a Prompt
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const prompt = await mutagent.prompt.createPrompt({
|
|
202
|
+
name: 'Summarizer',
|
|
203
|
+
content: 'Summarize the following text concisely: {{text}}',
|
|
204
|
+
variables: ['text'],
|
|
205
|
+
outputSchema: {
|
|
206
|
+
type: 'object',
|
|
207
|
+
properties: {
|
|
208
|
+
summary: { type: 'string' },
|
|
209
|
+
keyPoints: { type: 'array', items: { type: 'string' } },
|
|
210
|
+
},
|
|
211
|
+
required: ['summary'],
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### List Prompts
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const prompts = await mutagent.prompt.listPrompts();
|
|
220
|
+
|
|
221
|
+
// With pagination
|
|
222
|
+
for await (const page of prompts) {
|
|
223
|
+
console.log(page);
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Get a Prompt
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
const prompt = await mutagent.prompt.getPrompt({ id: 'prompt-id' });
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Update a Prompt
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
await mutagent.prompt.updatePrompt({
|
|
237
|
+
id: 'prompt-id',
|
|
238
|
+
content: 'Updated template: {{input}}',
|
|
239
|
+
name: 'Updated Name',
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Delete a Prompt
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
await mutagent.prompt.deletePrompt({ id: 'prompt-id' });
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Prompt Versioning
|
|
250
|
+
|
|
251
|
+
Every update creates a new version. You can also create versions explicitly:
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
// Create a new version
|
|
255
|
+
const version = await mutagent.prompt.createPromptVersion({
|
|
256
|
+
id: 'prompt-id',
|
|
257
|
+
content: 'Revised version of the prompt: {{input}}',
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// List all versions
|
|
261
|
+
const versions = await mutagent.prompt.listPromptVersions({ id: 'prompt-id' });
|
|
262
|
+
|
|
263
|
+
// Get analytics across versions
|
|
264
|
+
const analytics = await mutagent.prompt.getPromptAnalytics({ id: 'prompt-id' });
|
|
265
|
+
|
|
266
|
+
// Compare model performance across versions
|
|
267
|
+
const comparisons = await mutagent.prompt.getPromptModelComparisons({ id: 'prompt-id' });
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Datasets
|
|
273
|
+
|
|
274
|
+
Datasets hold the input/expected-output pairs used for evaluations and optimization.
|
|
275
|
+
|
|
276
|
+
### Create a Dataset
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
const dataset = await mutagent.promptDatasets.createPromptDataset({
|
|
280
|
+
id: 'prompt-id',
|
|
281
|
+
name: 'Production Queries',
|
|
282
|
+
description: 'Real queries sampled from production traffic',
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Add Items
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
// Single item
|
|
290
|
+
await mutagent.promptDatasetItems.createPromptDatasetItem({
|
|
291
|
+
id: dataset.id,
|
|
292
|
+
input: { query: 'What is the return policy?' },
|
|
293
|
+
expected: { summary: 'Returns accepted within 30 days with receipt.' },
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// Bulk add (recommended for large datasets)
|
|
297
|
+
await mutagent.promptDatasetItems.bulkCreatePromptDatasetItems({
|
|
298
|
+
id: dataset.id,
|
|
299
|
+
items: [
|
|
300
|
+
{ input: { query: 'How do I cancel?' }, expected: { summary: '...' } },
|
|
301
|
+
{ input: { query: 'Where is my order?' }, expected: { summary: '...' } },
|
|
302
|
+
],
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### List, Get, Update, Delete Items
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
// List items
|
|
310
|
+
const items = await mutagent.promptDatasetItems.listPromptDatasetItems({ id: dataset.id });
|
|
311
|
+
|
|
312
|
+
// Get a specific item
|
|
313
|
+
const item = await mutagent.promptDatasetItems.getPromptDatasetItem({
|
|
314
|
+
id: dataset.id,
|
|
315
|
+
itemId: 'item-id',
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// Update an item
|
|
319
|
+
await mutagent.promptDatasetItems.updatePromptDatasetItem({
|
|
320
|
+
id: dataset.id,
|
|
321
|
+
itemId: 'item-id',
|
|
322
|
+
expected: { summary: 'Corrected expected output.' },
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// Delete an item
|
|
326
|
+
await mutagent.promptDatasetItems.deletePromptDatasetItem({
|
|
327
|
+
id: dataset.id,
|
|
328
|
+
itemId: 'item-id',
|
|
329
|
+
});
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Clone and Export
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
// Clone a dataset
|
|
336
|
+
const clone = await mutagent.promptDatasets.clonePromptDataset({ id: dataset.id });
|
|
337
|
+
|
|
338
|
+
// Export a dataset
|
|
339
|
+
const exported = await mutagent.promptDatasets.exportPromptDataset({ id: dataset.id });
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## Evaluations
|
|
345
|
+
|
|
346
|
+
Evaluations score your prompt's outputs against defined criteria using a dataset.
|
|
347
|
+
|
|
348
|
+
### Create an Evaluation
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
const evaluation = await mutagent.promptEvaluations.createEvaluation({
|
|
352
|
+
promptId: 'prompt-id',
|
|
353
|
+
datasetId: 'dataset-id',
|
|
354
|
+
name: 'Quality Check',
|
|
355
|
+
evalConfig: {
|
|
356
|
+
criteria: [
|
|
357
|
+
{ name: 'Accuracy', description: 'Is the output factually accurate?' },
|
|
358
|
+
{ name: 'Conciseness', description: 'Is the output appropriately brief?' },
|
|
359
|
+
],
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Run an Evaluation
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
await mutagent.promptEvaluations.runEvaluation({ id: evaluation.id });
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Get Evaluation Results
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
const results = await mutagent.promptEvaluations.getEvaluationResult({
|
|
374
|
+
id: evaluation.id,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
console.log(`Score: ${results.overallScore}`);
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### Evaluation Version History
|
|
381
|
+
|
|
382
|
+
```typescript
|
|
383
|
+
// Get evaluation version history
|
|
384
|
+
const history = await mutagent.promptEvaluations.getEvaluationHistory({
|
|
385
|
+
id: evaluation.id,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// Get results aggregated by prompt version
|
|
389
|
+
const aggregated = await mutagent.promptEvaluations.getEvaluationResultsAggregated({
|
|
390
|
+
id: evaluation.id,
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
## Optimization
|
|
397
|
+
|
|
398
|
+
The optimization engine automatically improves your prompts based on evaluation metrics.
|
|
399
|
+
|
|
400
|
+
### Start an Optimization Job
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const job = await mutagent.optimization.optimizePrompt({
|
|
404
|
+
id: 'prompt-id',
|
|
405
|
+
datasetId: 'dataset-id',
|
|
406
|
+
metric: 'response_quality',
|
|
407
|
+
maxIterations: 5,
|
|
408
|
+
targetScore: 0.95,
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
console.log(`Job started: ${job.id}`);
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Poll Job Status
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
const status = await mutagent.optimization.getOptimization({ id: job.id });
|
|
418
|
+
|
|
419
|
+
console.log(`Status: ${status.status}`); // 'running' | 'paused' | 'completed' | 'failed'
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Track Score Progression
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
const progress = await mutagent.optimization.getOptimizationProgress({ id: job.id });
|
|
426
|
+
|
|
427
|
+
// Returns an array of (iteration, score) pairs
|
|
428
|
+
for (const point of progress.scores) {
|
|
429
|
+
console.log(`Iteration ${point.iteration}: ${point.score}`);
|
|
430
|
+
}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### Get Final Results
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
const results = await mutagent.optimization.getOptimizationResults({ id: job.id });
|
|
437
|
+
|
|
438
|
+
console.log(`Best version: ${results.bestVersionId}`);
|
|
439
|
+
console.log(`Score improvement: ${results.baselineScore} → ${results.bestScore}`);
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Pause, Resume, and Cancel
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
await mutagent.optimization.pauseOptimization({ id: job.id });
|
|
446
|
+
await mutagent.optimization.resumeOptimization({ id: job.id });
|
|
447
|
+
await mutagent.optimization.cancelOptimization({ id: job.id });
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
## Tracing & Observability
|
|
453
|
+
|
|
454
|
+
The SDK ships a built-in OpenTelemetry-compatible tracing module. It captures LLM calls, chains, agents, and custom operations and sends them to MutagenT for analysis.
|
|
455
|
+
|
|
456
|
+
### Initialize Tracing
|
|
457
|
+
|
|
458
|
+
Call `initTracing` once at application startup:
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
import { initTracing, shutdownTracing } from '@mutagent/sdk';
|
|
462
|
+
|
|
463
|
+
initTracing({
|
|
464
|
+
apiKey: process.env.MUTAGENT_API_KEY!,
|
|
465
|
+
endpoint: 'https://api.mutagent.io',
|
|
466
|
+
environment: 'production',
|
|
467
|
+
batchSize: 10, // spans per flush batch (default: 10)
|
|
468
|
+
flushInterval: 5000, // flush interval in ms (default: 5000)
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// Flush and close on app exit
|
|
472
|
+
process.on('SIGTERM', async () => {
|
|
473
|
+
await shutdownTracing();
|
|
474
|
+
process.exit(0);
|
|
475
|
+
});
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### @trace Decorator
|
|
479
|
+
|
|
480
|
+
The easiest way to instrument class methods:
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
import { trace } from '@mutagent/sdk';
|
|
484
|
+
|
|
485
|
+
class SupportAgent {
|
|
486
|
+
@trace({ kind: 'agent', name: 'support-agent' })
|
|
487
|
+
async handleQuery(query: string) {
|
|
488
|
+
const response = await this.generate(query);
|
|
489
|
+
return response;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
@trace({ kind: 'llm.chat', name: 'gpt-4o' })
|
|
493
|
+
private async generate(query: string) {
|
|
494
|
+
// LLM call — traced automatically with input/output/duration
|
|
495
|
+
return callOpenAI(query);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### withTrace Wrapper
|
|
501
|
+
|
|
502
|
+
For functional-style code or when you need fine-grained control:
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
import { withTrace } from '@mutagent/sdk';
|
|
506
|
+
|
|
507
|
+
async function ragPipeline(query: string) {
|
|
508
|
+
return await withTrace(
|
|
509
|
+
{ kind: 'chain', name: 'rag-pipeline' },
|
|
510
|
+
async (span) => {
|
|
511
|
+
span.setAttributes({ 'gen_ai.model': 'gpt-4o', 'user.query': query });
|
|
512
|
+
|
|
513
|
+
const docs = await retrieveDocuments(query);
|
|
514
|
+
span.addEvent('documents_retrieved', { count: docs.length });
|
|
515
|
+
|
|
516
|
+
const answer = await generateAnswer(query, docs);
|
|
517
|
+
span.setOutput({ text: answer, sources: docs.map(d => d.id) });
|
|
518
|
+
|
|
519
|
+
return answer;
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### Manual Spans
|
|
526
|
+
|
|
527
|
+
```typescript
|
|
528
|
+
import { startSpan, endSpan, getCurrentSpan, getCurrentTraceId } from '@mutagent/sdk';
|
|
529
|
+
|
|
530
|
+
const span = startSpan({ kind: 'tool', name: 'web-search' });
|
|
531
|
+
span.setAttributes({ query: 'latest AI news' });
|
|
532
|
+
|
|
533
|
+
try {
|
|
534
|
+
const results = await webSearch('latest AI news');
|
|
535
|
+
span.setOutput(results);
|
|
536
|
+
endSpan(span);
|
|
537
|
+
} catch (err) {
|
|
538
|
+
span.setStatus('error', String(err));
|
|
539
|
+
endSpan(span);
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### Span Kinds
|
|
544
|
+
|
|
545
|
+
| SpanKind | Description | Example Use Case |
|
|
546
|
+
|----------|-------------|------------------|
|
|
547
|
+
| `llm.chat` | Chat completion calls | OpenAI ChatGPT, Anthropic Claude |
|
|
548
|
+
| `llm.completion` | Text completion calls | Legacy completions |
|
|
549
|
+
| `llm.embedding` | Embedding generation | OpenAI Embeddings, Cohere Embed |
|
|
550
|
+
| `chain` | Sequential processing pipeline | LangChain chains, RAG pipelines |
|
|
551
|
+
| `agent` | Autonomous agent execution | ReAct agents |
|
|
552
|
+
| `graph` | State graph execution | LangGraph workflows |
|
|
553
|
+
| `node` | Individual graph node | State transitions |
|
|
554
|
+
| `edge` | Graph transition | Conditional routing |
|
|
555
|
+
| `workflow` | Multi-step workflows | Business process automation |
|
|
556
|
+
| `tool` | External tool calls | API calls, calculators |
|
|
557
|
+
| `retrieval` | Document retrieval | Vector search, keyword search |
|
|
558
|
+
| `rerank` | Result reranking | Cohere Rerank, cross-encoders |
|
|
559
|
+
| `guardrail` | Safety/validation checks | PII detection, content filtering |
|
|
560
|
+
| `custom` | Custom operations | Your domain-specific ops |
|
|
561
|
+
|
|
562
|
+
### Ingest Traces via API
|
|
563
|
+
|
|
564
|
+
You can also send traces programmatically via the SDK:
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
// Ingest a single trace
|
|
568
|
+
await mutagent.traces.ingestTrace({
|
|
569
|
+
traceId: 'trace-id',
|
|
570
|
+
spans: [ /* ... */ ],
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
// Batch ingest
|
|
574
|
+
await mutagent.traces.ingestTraceBatch({
|
|
575
|
+
traces: [ /* ... */ ],
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// OTLP ingestion (standard OpenTelemetry format)
|
|
579
|
+
await mutagent.traces.ingestOtlp({ /* OTLP payload */ });
|
|
580
|
+
|
|
581
|
+
// Query traces
|
|
582
|
+
const traces = await mutagent.traces.listTraces();
|
|
583
|
+
const stats = await mutagent.traces.getTraceStats();
|
|
584
|
+
const summary = await mutagent.traces.getAnalyticsSummary();
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
---
|
|
588
|
+
|
|
589
|
+
## Agents
|
|
590
|
+
|
|
591
|
+
Agents are persistent AI entities backed by a prompt. They maintain conversation history and support streaming.
|
|
592
|
+
|
|
593
|
+
### Create an Agent
|
|
594
|
+
|
|
595
|
+
```typescript
|
|
596
|
+
const agent = await mutagent.agents.createAgent({
|
|
597
|
+
name: 'Support Agent',
|
|
598
|
+
description: 'Handles customer support queries',
|
|
599
|
+
promptId: 'prompt-id',
|
|
600
|
+
});
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
### List and Get Agents
|
|
604
|
+
|
|
605
|
+
```typescript
|
|
606
|
+
const agents = await mutagent.agents.listAgents();
|
|
607
|
+
const agent = await mutagent.agents.getAgent({ id: 'agent-id' });
|
|
608
|
+
const agentBySlug = await mutagent.agents.getAgentBySlug({ slug: 'support-agent' });
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
### Update and Delete
|
|
612
|
+
|
|
613
|
+
```typescript
|
|
614
|
+
await mutagent.agents.updateAgent({ id: 'agent-id', name: 'Updated Name' });
|
|
615
|
+
await mutagent.agents.deleteAgent({ id: 'agent-id' });
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
### Conversations
|
|
619
|
+
|
|
620
|
+
```typescript
|
|
621
|
+
// Start a conversation
|
|
622
|
+
const conversation = await mutagent.agentConversations.createAgentConversation({
|
|
623
|
+
id: agent.id,
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
// Send a message
|
|
627
|
+
await mutagent.conversations.sendConversationMessage({
|
|
628
|
+
id: conversation.id,
|
|
629
|
+
content: 'How do I reset my password?',
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// List messages
|
|
633
|
+
const messages = await mutagent.conversations.listConversationMessages({
|
|
634
|
+
id: conversation.id,
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
// Fork a conversation (branch off from a specific point)
|
|
638
|
+
const forked = await mutagent.conversations.forkConversation({
|
|
639
|
+
id: conversation.id,
|
|
640
|
+
messageId: 'message-id',
|
|
641
|
+
});
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
### Streaming Chat
|
|
645
|
+
|
|
646
|
+
```typescript
|
|
647
|
+
// Send a streaming message
|
|
648
|
+
await mutagent.agentChatStreaming.sendStreamMessage({
|
|
649
|
+
id: conversation.id,
|
|
650
|
+
content: 'Tell me about your return policy.',
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
// Poll stream events
|
|
654
|
+
const events = await mutagent.agentChatStreaming.getStreamEvents({
|
|
655
|
+
id: conversation.id,
|
|
656
|
+
});
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
---
|
|
660
|
+
|
|
661
|
+
## Playground
|
|
662
|
+
|
|
663
|
+
The Playground lets you execute and evaluate a prompt without running a full optimization pipeline.
|
|
664
|
+
|
|
665
|
+
### Execute a Prompt
|
|
666
|
+
|
|
667
|
+
```typescript
|
|
668
|
+
const result = await mutagent.playground.playgroundCall({
|
|
669
|
+
promptId: 'prompt-id',
|
|
670
|
+
input: { query: 'What are your hours?' },
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
console.log(result.output);
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
### Evaluate in the Playground
|
|
677
|
+
|
|
678
|
+
```typescript
|
|
679
|
+
const evalResult = await mutagent.playground.playgroundEval({
|
|
680
|
+
promptId: 'prompt-id',
|
|
681
|
+
input: { query: 'What are your hours?' },
|
|
682
|
+
expected: { summary: 'Open 9 AM to 5 PM, Monday to Friday.' },
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
console.log(`Score: ${evalResult.score}`);
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
---
|
|
689
|
+
|
|
690
|
+
## Pagination
|
|
691
|
+
|
|
692
|
+
All list endpoints return async iterables. Iterate with `for await...of`:
|
|
693
|
+
|
|
694
|
+
```typescript
|
|
695
|
+
const result = await mutagent.promptDatasets.listPromptDatasets({
|
|
696
|
+
promptId: 42,
|
|
697
|
+
limit: 20,
|
|
698
|
+
offset: 0,
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
for await (const page of result) {
|
|
702
|
+
console.log(page);
|
|
703
|
+
}
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
---
|
|
707
|
+
|
|
708
|
+
## Retries
|
|
709
|
+
|
|
710
|
+
### Per-call Retry Config
|
|
711
|
+
|
|
712
|
+
```typescript
|
|
713
|
+
const result = await mutagent.userProfile.getProfile({
|
|
714
|
+
retries: {
|
|
715
|
+
strategy: 'backoff',
|
|
716
|
+
backoff: {
|
|
717
|
+
initialInterval: 500, // ms
|
|
718
|
+
maxInterval: 30000, // ms
|
|
719
|
+
exponent: 1.5,
|
|
720
|
+
maxElapsedTime: 120000, // ms
|
|
721
|
+
},
|
|
722
|
+
retryConnectionErrors: true,
|
|
723
|
+
},
|
|
724
|
+
});
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
### Global Retry Config
|
|
728
|
+
|
|
729
|
+
Set a default retry policy for all calls:
|
|
730
|
+
|
|
731
|
+
```typescript
|
|
732
|
+
const mutagent = new Mutagent({
|
|
733
|
+
retryConfig: {
|
|
734
|
+
strategy: 'backoff',
|
|
735
|
+
backoff: {
|
|
736
|
+
initialInterval: 500,
|
|
737
|
+
maxInterval: 30000,
|
|
738
|
+
exponent: 1.5,
|
|
739
|
+
maxElapsedTime: 120000,
|
|
740
|
+
},
|
|
741
|
+
retryConnectionErrors: true,
|
|
742
|
+
},
|
|
743
|
+
security: {
|
|
744
|
+
apiKey: process.env.MUTAGENT_API_KEY,
|
|
745
|
+
},
|
|
746
|
+
});
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
---
|
|
750
|
+
|
|
751
|
+
## Error Handling
|
|
752
|
+
|
|
753
|
+
All HTTP errors extend `MutagentError`:
|
|
754
|
+
|
|
755
|
+
```typescript
|
|
756
|
+
import { Mutagent } from '@mutagent/sdk';
|
|
757
|
+
import * as errors from '@mutagent/sdk/models/errors';
|
|
758
|
+
|
|
759
|
+
try {
|
|
760
|
+
const prompt = await mutagent.prompt.getPrompt({ id: 'does-not-exist' });
|
|
761
|
+
} catch (error) {
|
|
762
|
+
if (error instanceof errors.MutagentError) {
|
|
763
|
+
console.error(`HTTP ${error.statusCode}: ${error.message}`);
|
|
764
|
+
|
|
765
|
+
if (error instanceof errors.ErrorMessage) {
|
|
766
|
+
console.error('API error:', error.data$.error);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
### Error Properties
|
|
773
|
+
|
|
774
|
+
| Property | Type | Description |
|
|
775
|
+
|----------|------|-------------|
|
|
776
|
+
| `error.message` | `string` | Human-readable error message |
|
|
777
|
+
| `error.statusCode` | `number` | HTTP status code (e.g. `404`, `401`) |
|
|
778
|
+
| `error.headers` | `Headers` | HTTP response headers |
|
|
779
|
+
| `error.body` | `string` | Raw HTTP response body |
|
|
780
|
+
| `error.rawResponse` | `Response` | Raw HTTP response object |
|
|
781
|
+
| `error.data$` | varies | Structured error data (where available) |
|
|
782
|
+
|
|
783
|
+
### Error Classes
|
|
784
|
+
|
|
785
|
+
**Base class:**
|
|
786
|
+
- `MutagentError` — all HTTP error responses extend this
|
|
787
|
+
|
|
788
|
+
**Domain errors (extend `MutagentError`):**
|
|
789
|
+
- `ErrorMessage` — general API error message
|
|
790
|
+
- `ErrorMessageStatusCode` — error with explicit status code
|
|
791
|
+
- `ErrorResponse` — standard error response
|
|
792
|
+
- `OptimizationError` — optimization-specific errors
|
|
793
|
+
- `TraceError` — tracing ingestion errors
|
|
794
|
+
- `ProviderError` — provider config errors
|
|
795
|
+
- `WsError` — WebSocket/streaming errors
|
|
796
|
+
- `TestConnectionResultError` — provider connection test failures
|
|
797
|
+
- `ResponseValidationError` — server returned unexpected shape
|
|
798
|
+
|
|
799
|
+
**Network errors (client-side):**
|
|
800
|
+
- `ConnectionError` — could not reach the server
|
|
801
|
+
- `RequestTimeoutError` — request exceeded the timeout
|
|
802
|
+
- `RequestAbortedError` — request was aborted
|
|
803
|
+
- `InvalidRequestError` — invalid input before the request was sent
|
|
804
|
+
- `UnexpectedClientError` — unrecognised client-side error
|
|
805
|
+
|
|
806
|
+
---
|
|
807
|
+
|
|
808
|
+
## Custom HTTP Client
|
|
809
|
+
|
|
810
|
+
The SDK uses the native Fetch API internally. You can swap in any fetcher — useful for proxying, testing, or custom timeouts:
|
|
811
|
+
|
|
812
|
+
```typescript
|
|
813
|
+
import { Mutagent } from '@mutagent/sdk';
|
|
814
|
+
import { HTTPClient } from '@mutagent/sdk/lib/http';
|
|
815
|
+
import { ProxyAgent } from 'undici';
|
|
816
|
+
|
|
817
|
+
const dispatcher = new ProxyAgent('http://proxy.example.com:8080');
|
|
818
|
+
|
|
819
|
+
const httpClient = new HTTPClient({
|
|
820
|
+
fetcher: (input, init) =>
|
|
821
|
+
fetch(input, { ...init, dispatcher } as RequestInit),
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
// Add a request timeout and custom header
|
|
825
|
+
httpClient.addHook('beforeRequest', (request) => {
|
|
826
|
+
const next = new Request(request, {
|
|
827
|
+
signal: request.signal ?? AbortSignal.timeout(10_000),
|
|
828
|
+
});
|
|
829
|
+
next.headers.set('x-app-version', '1.0.0');
|
|
830
|
+
return next;
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// Log errors
|
|
834
|
+
httpClient.addHook('requestError', (error, request) => {
|
|
835
|
+
console.error(`Request failed: ${request.method} ${request.url}`, error);
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
const mutagent = new Mutagent({ httpClient, security: { apiKey: process.env.MUTAGENT_API_KEY } });
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
---
|
|
842
|
+
|
|
843
|
+
## Tree-shakeable Imports
|
|
844
|
+
|
|
845
|
+
All SDK methods are also available as standalone functions. This is ideal for serverless environments or browser bundles where tree-shaking matters:
|
|
846
|
+
|
|
847
|
+
```typescript
|
|
848
|
+
import {
|
|
849
|
+
promptCreatePrompt,
|
|
850
|
+
promptListPrompts,
|
|
851
|
+
promptDatasetsCreatePromptDataset,
|
|
852
|
+
promptDatasetItemsBulkCreatePromptDatasetItems,
|
|
853
|
+
optimizationOptimizePrompt,
|
|
854
|
+
optimizationGetOptimizationResults,
|
|
855
|
+
} from '@mutagent/sdk/functions';
|
|
856
|
+
|
|
857
|
+
import { Mutagent } from '@mutagent/sdk';
|
|
858
|
+
|
|
859
|
+
const client = new Mutagent({ security: { apiKey: process.env.MUTAGENT_API_KEY } });
|
|
860
|
+
|
|
861
|
+
const prompt = await promptCreatePrompt(client, {
|
|
862
|
+
name: 'My Prompt',
|
|
863
|
+
content: 'Template: {{input}}',
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
const dataset = await promptDatasetsCreatePromptDataset(client, {
|
|
867
|
+
id: prompt.id,
|
|
868
|
+
name: 'My Dataset',
|
|
869
|
+
});
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
Full list of standalone functions is available in [FUNCTIONS.md](./FUNCTIONS.md).
|
|
873
|
+
|
|
874
|
+
---
|
|
875
|
+
|
|
876
|
+
## TypeScript Support
|
|
877
|
+
|
|
878
|
+
The SDK is written in TypeScript and ships full type declarations.
|
|
879
|
+
|
|
880
|
+
### Client Constructor Types
|
|
881
|
+
|
|
882
|
+
```typescript
|
|
883
|
+
import type { MutagentOptions } from '@mutagent/sdk';
|
|
884
|
+
|
|
885
|
+
const options: MutagentOptions = {
|
|
886
|
+
security: { apiKey: process.env.MUTAGENT_API_KEY },
|
|
887
|
+
serverURL: 'https://api.mutagent.io/v1',
|
|
888
|
+
retryConfig: { strategy: 'backoff', backoff: { /* ... */ } },
|
|
889
|
+
};
|
|
890
|
+
```
|
|
891
|
+
|
|
892
|
+
### Response Types
|
|
893
|
+
|
|
894
|
+
All responses are fully typed. IDE autocomplete works out of the box:
|
|
895
|
+
|
|
896
|
+
```typescript
|
|
897
|
+
import type { Prompt, Dataset, EvaluationResult, OptimizationJob } from '@mutagent/sdk/models/components';
|
|
898
|
+
|
|
899
|
+
const prompt: Prompt = await mutagent.prompt.getPrompt({ id: 'prompt-id' });
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
### Debugging
|
|
903
|
+
|
|
904
|
+
Enable debug logging to inspect every request and response. Use only in local development — debug logs contain API keys and secrets:
|
|
905
|
+
|
|
906
|
+
```typescript
|
|
907
|
+
const mutagent = new Mutagent({ debugLogger: console, security: { apiKey: '...' } });
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
Or set `MUTAGENT_DEBUG=true` in your environment.
|
|
911
|
+
|
|
912
|
+
---
|
|
913
|
+
|
|
914
|
+
## Framework Integrations
|
|
915
|
+
|
|
916
|
+
Use MutagenT with your favourite AI framework. The CLI can generate integration boilerplate automatically:
|
|
917
|
+
|
|
918
|
+
```bash
|
|
919
|
+
npx @mutagent/cli integrate mastra
|
|
920
|
+
npx @mutagent/cli integrate langchain
|
|
921
|
+
npx @mutagent/cli integrate langgraph
|
|
922
|
+
npx @mutagent/cli integrate vercel-ai
|
|
923
|
+
npx @mutagent/cli integrate openai
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
### Mastra
|
|
927
|
+
|
|
928
|
+
```typescript
|
|
929
|
+
import { MutagentObserver } from '@mutagent/sdk/mastra';
|
|
930
|
+
|
|
931
|
+
const observer = new MutagentObserver({
|
|
932
|
+
apiKey: process.env.MUTAGENT_API_KEY,
|
|
933
|
+
});
|
|
934
|
+
```
|
|
935
|
+
|
|
936
|
+
### LangChain
|
|
937
|
+
|
|
938
|
+
```typescript
|
|
939
|
+
import { MutagentCallbackHandler } from '@mutagent/sdk/langchain';
|
|
940
|
+
import { ChatOpenAI } from '@langchain/openai';
|
|
941
|
+
|
|
942
|
+
const handler = new MutagentCallbackHandler({
|
|
943
|
+
apiKey: process.env.MUTAGENT_API_KEY,
|
|
944
|
+
promptId: 'my-prompt-id',
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
const llm = new ChatOpenAI({ callbacks: [handler] });
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
### Vercel AI SDK
|
|
951
|
+
|
|
952
|
+
```typescript
|
|
953
|
+
import { withMutagent } from '@mutagent/sdk/vercel-ai';
|
|
954
|
+
import { streamText } from 'ai';
|
|
955
|
+
import { openai } from '@ai-sdk/openai';
|
|
956
|
+
|
|
957
|
+
const result = await withMutagent(
|
|
958
|
+
streamText({ model: openai('gpt-4o'), messages }),
|
|
959
|
+
{ apiKey: process.env.MUTAGENT_API_KEY }
|
|
960
|
+
);
|
|
961
|
+
```
|
|
962
|
+
|
|
963
|
+
### Migration from Langfuse
|
|
964
|
+
|
|
965
|
+
```typescript
|
|
966
|
+
// Before (Langfuse)
|
|
967
|
+
import { Langfuse } from 'langfuse';
|
|
968
|
+
const langfuse = new Langfuse({
|
|
969
|
+
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
|
970
|
+
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
// After (MutagenT)
|
|
974
|
+
import { initTracing } from '@mutagent/sdk/tracing';
|
|
975
|
+
initTracing({ apiKey: process.env.MUTAGENT_API_KEY! });
|
|
976
|
+
```
|
|
977
|
+
|
|
978
|
+
---
|
|
979
|
+
|
|
980
|
+
## API Reference
|
|
981
|
+
|
|
982
|
+
### Available Namespaces
|
|
983
|
+
|
|
984
|
+
| Namespace | Key Methods | Description |
|
|
985
|
+
|-----------|-------------|-------------|
|
|
986
|
+
| `prompt` | `createPrompt`, `listPrompts`, `getPrompt`, `updatePrompt`, `deletePrompt`, `createPromptVersion`, `listPromptVersions`, `getPromptAnalytics` | Prompt management and versioning |
|
|
987
|
+
| `promptDatasets` | `createPromptDataset`, `listDatasetsForPrompt`, `getPromptDataset`, `updatePromptDataset`, `deletePromptDataset`, `clonePromptDataset`, `exportPromptDataset` | Dataset operations |
|
|
988
|
+
| `promptDatasetItems` | `createPromptDatasetItem`, `bulkCreatePromptDatasetItems`, `listPromptDatasetItems`, `getPromptDatasetItem`, `updatePromptDatasetItem`, `deletePromptDatasetItem` | Dataset item CRUD |
|
|
989
|
+
| `promptEvaluations` | `createEvaluation`, `listEvaluations`, `getEvaluation`, `runEvaluation`, `getEvaluationResult`, `getEvaluationHistory`, `getEvaluationResultsAggregated` | Evaluation engine |
|
|
990
|
+
| `optimization` | `optimizePrompt`, `getOptimization`, `listOptimizations`, `getOptimizationProgress`, `getOptimizationResults`, `getOptimizationStates`, `pauseOptimization`, `resumeOptimization`, `cancelOptimization` | Auto-optimization jobs |
|
|
991
|
+
| `playground` | `playgroundCall`, `playgroundEval` | Interactive prompt execution |
|
|
992
|
+
| `agents` | `createAgent`, `listAgents`, `getAgent`, `getAgentBySlug`, `updateAgent`, `deleteAgent` | Agent CRUD |
|
|
993
|
+
| `agentConversations` | `createAgentConversation`, `listAgentConversations` | Agent conversation management |
|
|
994
|
+
| `conversations` | `getConversation`, `sendConversationMessage`, `listConversationMessages`, `updateConversation`, `deleteConversation`, `forkConversation` | Conversation operations |
|
|
995
|
+
| `agentChatStreaming` | `sendStreamMessage`, `getStreamEvents` | Real-time streaming chat |
|
|
996
|
+
| `agentDatasets` | `createAgentDataset`, `listAgentDatasets`, `getAgentDataset`, `updateAgentDataset`, `deleteAgentDataset`, `cloneAgentDataset`, `exportAgentDataset` | Agent evaluation datasets |
|
|
997
|
+
| `agentDatasetItems` | `createAgentDatasetItem`, `bulkCreateAgentDatasetItems`, `listAgentDatasetItems`, `getAgentDatasetItem`, `updateAgentDatasetItem`, `deleteAgentDatasetItem` | Agent dataset item operations |
|
|
998
|
+
| `traces` | `ingestTrace`, `ingestTraceBatch`, `ingestOtlp`, `listTraces`, `getTrace`, `getTraceStats`, `getAnalyticsSummary`, `deleteTrace` | Trace observability and ingestion |
|
|
999
|
+
| `providerConfigs` | `createProvider`, `listProviders`, `getProvider`, `updateProvider`, `deleteProvider`, `testProvider`, `listAvailableModels`, `getModelsCatalog` | LLM provider configurations |
|
|
1000
|
+
| `workspaces` | `createWorkspace`, `listWorkspaces`, `getWorkspace`, `updateWorkspace`, `deleteWorkspace`, `setDefaultWorkspace` | Workspace management |
|
|
1001
|
+
| `workspaceMembers` | `addWorkspaceMember`, `listWorkspaceMembers`, `updateWorkspaceMember`, `removeWorkspaceMember` | Workspace membership |
|
|
1002
|
+
| `organizations` | `createOrganization`, `listOrganizations`, `getOrganization`, `updateOrganization`, `deleteOrganization`, `getOrganizationBySlug` | Organization management |
|
|
1003
|
+
| `organizationMembers` | `addOrganizationMember`, `listOrganizationMembers`, `updateOrganizationMember`, `removeOrganizationMember` | Organization membership |
|
|
1004
|
+
| `userProfile` | `getProfile`, `updateProfile`, `changePassword`, `deleteAccount`, `listSessions`, `deleteSession` | User profile management |
|
|
1005
|
+
| `invitations` | `createInvitation`, `listInvitations`, `getInvitation`, `resendInvitation`, `deleteInvitation` | Team invitations |
|
|
1006
|
+
| `experiments` | `createExperiment`, `listExperiments`, `getExperiment`, `executeExperiment`, `completeExperiment`, `addExperimentResult`, `deleteExperiment` | Experiments |
|
|
1007
|
+
|
|
1008
|
+
For complete per-method docs, see [docs/sdks/](./docs/sdks/).
|
|
1009
|
+
|
|
1010
|
+
---
|
|
1011
|
+
|
|
1012
|
+
## See Also
|
|
1013
|
+
|
|
1014
|
+
- **[@mutagent/cli](https://www.npmjs.com/package/@mutagent/cli)** — Command-line interface for MutagenT
|
|
1015
|
+
- **[docs.mutagent.io](https://docs.mutagent.io)** — Full platform documentation
|
|
1016
|
+
- **[Integration Guides](https://docs.mutagent.io/integrations/overview)** — Mastra, LangChain, LangGraph, Vercel AI, OpenAI
|
|
1017
|
+
- **[Tracing Setup](https://docs.mutagent.io/tracing/setup)** — OTel integration walkthrough
|
|
1018
|
+
- **[API Reference](https://docs.mutagent.io/api)** — Complete REST API reference
|
|
1019
|
+
- **[mutagent.io](https://mutagent.io)** — Homepage
|
|
1020
|
+
|
|
1021
|
+
---
|
|
1022
|
+
|
|
1023
|
+
## License
|
|
1024
|
+
|
|
1025
|
+
This software is proprietary and confidential. Unauthorized copying, distribution, or use is strictly prohibited.
|
|
1026
|
+
|
|
1027
|
+
(c) 2026 MutagenT. All rights reserved.
|
|
1028
|
+
|
|
1029
|
+
---
|
|
1030
|
+
|
|
1031
|
+
<p align="center">
|
|
1032
|
+
<sub>Built with care by the MutagenT Team</sub>
|
|
1033
|
+
</p>
|
|
1034
|
+
|
|
1035
|
+
<p align="center">
|
|
1036
|
+
<a href="https://twitter.com/mutagent">Twitter</a> •
|
|
1037
|
+
<a href="https://discord.gg/mutagent">Discord</a> •
|
|
1038
|
+
<a href="https://mutagent.io">Website</a> •
|
|
1039
|
+
<a href="https://docs.mutagent.io">Documentation</a>
|
|
1040
|
+
</p>
|
|
@@ -35,8 +35,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
35
35
|
export declare const SDK_METADATA: {
|
|
36
36
|
readonly language: "typescript";
|
|
37
37
|
readonly openapiDocVersion: "2.0.0";
|
|
38
|
-
readonly sdkVersion: "0.2.
|
|
39
|
-
readonly genVersion: "2.881.
|
|
40
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.2.
|
|
38
|
+
readonly sdkVersion: "0.2.127";
|
|
39
|
+
readonly genVersion: "2.881.4";
|
|
40
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.2.127 2.881.4 2.0.0 @mutagent/sdk";
|
|
41
41
|
};
|
|
42
42
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -31,8 +31,8 @@ function serverURLFromOptions(options) {
|
|
|
31
31
|
exports.SDK_METADATA = {
|
|
32
32
|
language: "typescript",
|
|
33
33
|
openapiDocVersion: "2.0.0",
|
|
34
|
-
sdkVersion: "0.2.
|
|
35
|
-
genVersion: "2.881.
|
|
36
|
-
userAgent: "speakeasy-sdk/typescript 0.2.
|
|
34
|
+
sdkVersion: "0.2.127",
|
|
35
|
+
genVersion: "2.881.4",
|
|
36
|
+
userAgent: "speakeasy-sdk/typescript 0.2.127 2.881.4 2.0.0 @mutagent/sdk",
|
|
37
37
|
};
|
|
38
38
|
//# sourceMappingURL=config.js.map
|
package/dist/esm/lib/config.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
35
35
|
export declare const SDK_METADATA: {
|
|
36
36
|
readonly language: "typescript";
|
|
37
37
|
readonly openapiDocVersion: "2.0.0";
|
|
38
|
-
readonly sdkVersion: "0.2.
|
|
39
|
-
readonly genVersion: "2.881.
|
|
40
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.2.
|
|
38
|
+
readonly sdkVersion: "0.2.127";
|
|
39
|
+
readonly genVersion: "2.881.4";
|
|
40
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.2.127 2.881.4 2.0.0 @mutagent/sdk";
|
|
41
41
|
};
|
|
42
42
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/esm/lib/config.js
CHANGED
|
@@ -27,8 +27,8 @@ export function serverURLFromOptions(options) {
|
|
|
27
27
|
export const SDK_METADATA = {
|
|
28
28
|
language: "typescript",
|
|
29
29
|
openapiDocVersion: "2.0.0",
|
|
30
|
-
sdkVersion: "0.2.
|
|
31
|
-
genVersion: "2.881.
|
|
32
|
-
userAgent: "speakeasy-sdk/typescript 0.2.
|
|
30
|
+
sdkVersion: "0.2.127",
|
|
31
|
+
genVersion: "2.881.4",
|
|
32
|
+
userAgent: "speakeasy-sdk/typescript 0.2.127 2.881.4 2.0.0 @mutagent/sdk",
|
|
33
33
|
};
|
|
34
34
|
//# sourceMappingURL=config.js.map
|
package/package.json
CHANGED
package/src/lib/config.ts
CHANGED
|
@@ -65,7 +65,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
65
65
|
export const SDK_METADATA = {
|
|
66
66
|
language: "typescript",
|
|
67
67
|
openapiDocVersion: "2.0.0",
|
|
68
|
-
sdkVersion: "0.2.
|
|
69
|
-
genVersion: "2.881.
|
|
70
|
-
userAgent: "speakeasy-sdk/typescript 0.2.
|
|
68
|
+
sdkVersion: "0.2.127",
|
|
69
|
+
genVersion: "2.881.4",
|
|
70
|
+
userAgent: "speakeasy-sdk/typescript 0.2.127 2.881.4 2.0.0 @mutagent/sdk",
|
|
71
71
|
} as const;
|