@marshmallo/marlo 0.1.0 → 0.1.2
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 +95 -204
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @marshmallo/marlo
|
|
2
2
|
|
|
3
|
-
The official TypeScript SDK for [Marlo](https://marshmallo.ai) - agent
|
|
3
|
+
The official TypeScript SDK for [Marlo](https://marshmallo.ai) - the agent learning platform.
|
|
4
|
+
|
|
5
|
+
Marlo enables AI agents to learn and improve autonomously in production. It captures agent behavior, evaluates outcomes, and turns failures into actionable learnings.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@marshmallo/marlo)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
9
|
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
@@ -13,269 +18,155 @@ npm install @marshmallo/marlo
|
|
|
13
18
|
```typescript
|
|
14
19
|
import * as marlo from '@marshmallo/marlo';
|
|
15
20
|
|
|
16
|
-
// Initialize
|
|
17
|
-
await marlo.init(process.env.MARLO_API_KEY
|
|
21
|
+
// Initialize
|
|
22
|
+
await marlo.init(process.env.MARLO_API_KEY);
|
|
18
23
|
|
|
19
24
|
// Register your agent
|
|
20
|
-
marlo.agent(
|
|
21
|
-
'
|
|
22
|
-
|
|
23
|
-
[{ name: 'search', description: 'Search the web' }],
|
|
24
|
-
null,
|
|
25
|
-
{ model: 'gpt-4' }
|
|
26
|
-
);
|
|
25
|
+
marlo.agent('support-bot', 'You are a customer support agent.', [
|
|
26
|
+
{ name: 'lookup_order', description: 'Find order by ID' }
|
|
27
|
+
]);
|
|
27
28
|
|
|
28
29
|
// Track a task
|
|
29
|
-
const task = marlo.task('thread-123', '
|
|
30
|
-
task.input('
|
|
30
|
+
const task = marlo.task('thread-123', 'support-bot').start();
|
|
31
|
+
task.input('Where is my order?');
|
|
31
32
|
|
|
32
33
|
// Your agent logic here...
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
usage: { input_tokens: 50, output_tokens: 100 },
|
|
36
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
37
|
-
response: 'I can help with many things!',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
task.output('I can help with many things!');
|
|
34
|
+
|
|
35
|
+
task.output('Your order ships tomorrow.');
|
|
41
36
|
task.end();
|
|
42
37
|
|
|
43
38
|
// Shutdown before exit
|
|
44
39
|
await marlo.shutdown();
|
|
45
40
|
```
|
|
46
41
|
|
|
47
|
-
##
|
|
42
|
+
## Why Marlo?
|
|
43
|
+
|
|
44
|
+
Agents fail silently in production. The same mistakes repeat because failures aren't captured in a reusable form. Marlo solves this with a learning loop:
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- **Learnings Integration**: Fetch and apply learnings from past interactions
|
|
54
|
-
- **Buffered Sending**: Automatic batching and retry for reliability
|
|
46
|
+
1. **Capture** - Record LLM calls, tool calls, and outcomes
|
|
47
|
+
2. **Evaluate** - Score task outcomes automatically
|
|
48
|
+
3. **Learn** - Generate guidance from failures
|
|
49
|
+
4. **Apply** - Inject learnings into future tasks
|
|
55
50
|
|
|
56
|
-
## API
|
|
51
|
+
## API
|
|
57
52
|
|
|
58
|
-
###
|
|
53
|
+
### Initialize
|
|
59
54
|
|
|
60
55
|
```typescript
|
|
61
|
-
// Initialize the SDK
|
|
62
56
|
await marlo.init(apiKey);
|
|
63
|
-
|
|
64
|
-
// Check if SDK is enabled
|
|
65
|
-
marlo.isEnabled(): boolean;
|
|
66
|
-
|
|
67
|
-
// Get the client instance
|
|
68
|
-
marlo.getClient(): MarloClient | null;
|
|
69
|
-
|
|
70
|
-
// Shutdown and flush pending events
|
|
71
|
-
await marlo.shutdown();
|
|
72
57
|
```
|
|
73
58
|
|
|
74
|
-
### Agent
|
|
59
|
+
### Register Agent
|
|
75
60
|
|
|
76
61
|
```typescript
|
|
77
|
-
marlo.agent(
|
|
78
|
-
name: string,
|
|
79
|
-
systemPrompt: string,
|
|
80
|
-
tools: ToolDefinition[],
|
|
81
|
-
mcp?: McpDefinition[] | null,
|
|
82
|
-
modelConfig?: ModelConfig | null
|
|
83
|
-
): string;
|
|
62
|
+
marlo.agent(name, systemPrompt, tools, mcp?, modelConfig?);
|
|
84
63
|
```
|
|
85
64
|
|
|
86
|
-
| Parameter | Description |
|
|
87
|
-
|
|
88
|
-
| `name` |
|
|
89
|
-
| `systemPrompt` |
|
|
90
|
-
| `tools` |
|
|
91
|
-
| `mcp` |
|
|
92
|
-
| `modelConfig` |
|
|
65
|
+
| Parameter | Type | Description |
|
|
66
|
+
|-----------|------|-------------|
|
|
67
|
+
| `name` | `string` | Unique agent identifier |
|
|
68
|
+
| `systemPrompt` | `string` | Agent's system prompt |
|
|
69
|
+
| `tools` | `ToolDefinition[]` | Available tools |
|
|
70
|
+
| `mcp` | `McpDefinition[]` | MCP servers (optional) |
|
|
71
|
+
| `modelConfig` | `ModelConfig` | Model settings (optional) |
|
|
93
72
|
|
|
94
|
-
###
|
|
73
|
+
### Track Tasks
|
|
95
74
|
|
|
96
75
|
```typescript
|
|
97
|
-
|
|
98
|
-
const task = marlo.task(threadId: string, agentName: string, threadName?: string).start();
|
|
99
|
-
|
|
100
|
-
// Record events
|
|
101
|
-
task.input(text); // User input
|
|
102
|
-
task.output(text); // Agent response
|
|
103
|
-
task.llm({ model, usage, messages?, response? }); // LLM call
|
|
104
|
-
task.tool(name, input, output, error?); // Tool call
|
|
105
|
-
task.reasoning(text); // Chain-of-thought
|
|
106
|
-
task.error(message); // Mark task as failed
|
|
107
|
-
|
|
108
|
-
// Fetch learnings
|
|
109
|
-
const learnings = await task.getLearnings();
|
|
76
|
+
const task = marlo.task(threadId, agentName, threadName?).start();
|
|
110
77
|
|
|
111
|
-
//
|
|
112
|
-
|
|
78
|
+
task.input(text); // User input
|
|
79
|
+
task.output(text); // Agent response
|
|
80
|
+
task.llm({ model, usage, messages?, response? });
|
|
81
|
+
task.tool(name, input, output, error?);
|
|
82
|
+
task.reasoning(text); // Chain-of-thought
|
|
83
|
+
task.error(message); // Mark as failed
|
|
113
84
|
|
|
114
|
-
|
|
115
|
-
task.end(hasError?: boolean);
|
|
85
|
+
task.end();
|
|
116
86
|
```
|
|
117
87
|
|
|
118
|
-
###
|
|
119
|
-
|
|
120
|
-
#### `task.input(text: string)`
|
|
121
|
-
Record the user's input message.
|
|
122
|
-
|
|
123
|
-
#### `task.output(text: string)`
|
|
124
|
-
Record the agent's final response.
|
|
125
|
-
|
|
126
|
-
#### `task.llm(params)`
|
|
127
|
-
Track an LLM call.
|
|
88
|
+
### Fetch Learnings
|
|
128
89
|
|
|
129
90
|
```typescript
|
|
130
|
-
task.
|
|
131
|
-
model: 'gpt-4',
|
|
132
|
-
usage: { input_tokens: 100, output_tokens: 50 },
|
|
133
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
134
|
-
response: 'Hi there!',
|
|
135
|
-
});
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
#### `task.tool(name, input, output, error?)`
|
|
139
|
-
Track a tool call.
|
|
91
|
+
const learnings = await task.getLearnings();
|
|
140
92
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
{ result: 'sunny' },
|
|
146
|
-
undefined // Optional error message
|
|
147
|
-
);
|
|
93
|
+
if (learnings?.learnings_text) {
|
|
94
|
+
// Inject into your agent's context
|
|
95
|
+
systemPrompt += `\n\nLearnings:\n${learnings.learnings_text}`;
|
|
96
|
+
}
|
|
148
97
|
```
|
|
149
98
|
|
|
150
|
-
|
|
151
|
-
Record chain-of-thought or reasoning steps.
|
|
99
|
+
### Multi-Agent
|
|
152
100
|
|
|
153
|
-
|
|
154
|
-
|
|
101
|
+
```typescript
|
|
102
|
+
const parent = marlo.task('thread-1', 'orchestrator').start();
|
|
103
|
+
parent.input('Research AI trends');
|
|
155
104
|
|
|
156
|
-
|
|
157
|
-
|
|
105
|
+
const child = parent.child('researcher').start();
|
|
106
|
+
child.input('Search for AI trends');
|
|
107
|
+
child.output('Found 3 sources...');
|
|
108
|
+
child.end();
|
|
158
109
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (learnings) {
|
|
162
|
-
// Apply learnings to your agent
|
|
163
|
-
}
|
|
110
|
+
parent.output('Report complete');
|
|
111
|
+
parent.end();
|
|
164
112
|
```
|
|
165
113
|
|
|
166
|
-
|
|
167
|
-
Create a child task for multi-agent workflows.
|
|
168
|
-
|
|
169
|
-
## Complete Example
|
|
114
|
+
### Shutdown
|
|
170
115
|
|
|
171
116
|
```typescript
|
|
172
|
-
import * as marlo from '@marshmallo/marlo';
|
|
173
|
-
|
|
174
|
-
// Initialize
|
|
175
|
-
await marlo.init('mk_abc123');
|
|
176
|
-
|
|
177
|
-
// Register agent with tools
|
|
178
|
-
marlo.agent(
|
|
179
|
-
'support-bot',
|
|
180
|
-
'You are a customer support agent.',
|
|
181
|
-
[
|
|
182
|
-
{ name: 'lookup_order', description: 'Find order by ID' },
|
|
183
|
-
{ name: 'check_inventory', description: 'Check product stock' },
|
|
184
|
-
],
|
|
185
|
-
null,
|
|
186
|
-
{ model: 'gpt-4', temperature: 0.7 }
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
async function handleMessage(threadId: string, userMessage: string): Promise<string> {
|
|
190
|
-
const task = marlo.task(threadId, 'support-bot').start();
|
|
191
|
-
task.input(userMessage);
|
|
192
|
-
|
|
193
|
-
try {
|
|
194
|
-
// Get learnings to improve responses
|
|
195
|
-
const learnings = await task.getLearnings();
|
|
196
|
-
|
|
197
|
-
// Build messages
|
|
198
|
-
const messages = [
|
|
199
|
-
{ role: 'system', content: 'You are a customer support agent.' },
|
|
200
|
-
{ role: 'user', content: userMessage },
|
|
201
|
-
];
|
|
202
|
-
|
|
203
|
-
// Call LLM
|
|
204
|
-
const response = await llm.chat(messages);
|
|
205
|
-
const answer = response.content;
|
|
206
|
-
|
|
207
|
-
// Track the LLM call
|
|
208
|
-
task.llm({
|
|
209
|
-
model: 'gpt-4',
|
|
210
|
-
usage: {
|
|
211
|
-
input_tokens: response.usage.promptTokens,
|
|
212
|
-
output_tokens: response.usage.completionTokens,
|
|
213
|
-
},
|
|
214
|
-
messages,
|
|
215
|
-
response: answer,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
// Track any tool calls
|
|
219
|
-
if (response.toolCalls) {
|
|
220
|
-
for (const toolCall of response.toolCalls) {
|
|
221
|
-
const result = await executeTool(toolCall);
|
|
222
|
-
task.tool(toolCall.name, toolCall.arguments, result);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
task.output(answer);
|
|
227
|
-
return answer;
|
|
228
|
-
} catch (error) {
|
|
229
|
-
task.error(error instanceof Error ? error.message : 'Unknown error');
|
|
230
|
-
throw error;
|
|
231
|
-
} finally {
|
|
232
|
-
task.end();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Cleanup on shutdown
|
|
237
117
|
await marlo.shutdown();
|
|
238
118
|
```
|
|
239
119
|
|
|
240
|
-
##
|
|
120
|
+
## Full Example
|
|
241
121
|
|
|
242
122
|
```typescript
|
|
243
123
|
import * as marlo from '@marshmallo/marlo';
|
|
244
124
|
|
|
245
|
-
await marlo.init(
|
|
125
|
+
await marlo.init(process.env.MARLO_API_KEY);
|
|
246
126
|
|
|
247
|
-
marlo.agent('
|
|
248
|
-
|
|
249
|
-
|
|
127
|
+
marlo.agent('support-bot', 'You are a customer support agent.', [
|
|
128
|
+
{ name: 'lookup_order', description: 'Find order by ID' }
|
|
129
|
+
]);
|
|
250
130
|
|
|
251
|
-
|
|
252
|
-
|
|
131
|
+
async function handleMessage(input: string, threadId: string) {
|
|
132
|
+
const task = marlo.task(threadId, 'support-bot').start();
|
|
133
|
+
task.input(input);
|
|
253
134
|
|
|
254
|
-
//
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
135
|
+
// Apply learnings from past interactions
|
|
136
|
+
const learnings = await task.getLearnings();
|
|
137
|
+
let systemPrompt = 'You are a customer support agent.';
|
|
138
|
+
if (learnings?.learnings_text) {
|
|
139
|
+
systemPrompt += `\n\nLearnings:\n${learnings.learnings_text}`;
|
|
140
|
+
}
|
|
259
141
|
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
writer.input('Write report based on research');
|
|
263
|
-
writer.output('# AI Report\n...');
|
|
264
|
-
writer.end();
|
|
142
|
+
// Track tool call
|
|
143
|
+
task.tool('lookup_order', { id: '123' }, { status: 'shipped' });
|
|
265
144
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
145
|
+
// Track LLM call
|
|
146
|
+
const response = 'Your order ships tomorrow.';
|
|
147
|
+
task.llm({
|
|
148
|
+
model: 'gpt-4',
|
|
149
|
+
usage: { input_tokens: 100, output_tokens: 25 },
|
|
150
|
+
messages: [{ role: 'user', content: input }],
|
|
151
|
+
response
|
|
152
|
+
});
|
|
269
153
|
|
|
270
|
-
|
|
154
|
+
task.output(response);
|
|
155
|
+
task.end();
|
|
271
156
|
|
|
272
|
-
|
|
273
|
-
|
|
157
|
+
return response;
|
|
158
|
+
}
|
|
274
159
|
```
|
|
275
160
|
|
|
276
161
|
## Requirements
|
|
277
162
|
|
|
278
|
-
- Node.js 18
|
|
163
|
+
- Node.js 18+
|
|
164
|
+
|
|
165
|
+
## Links
|
|
166
|
+
|
|
167
|
+
- [Documentation](https://docs.marshmallo.ai)
|
|
168
|
+
- [Dashboard](https://marshmallo.ai)
|
|
169
|
+
- [Python SDK](https://pypi.org/project/marlo-sdk)
|
|
279
170
|
|
|
280
171
|
## License
|
|
281
172
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marshmallo/marlo",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "The official TypeScript SDK for Marlo - the agent learning platform",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|