@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.
Files changed (2) hide show
  1. package/README.md +95 -204
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,11 @@
1
- # Marlo TypeScript SDK
1
+ # @marshmallo/marlo
2
2
 
3
- The official TypeScript SDK for [Marlo](https://marshmallo.ai) - agent observability and learning platform.
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
+ [![npm version](https://img.shields.io/npm/v/@marshmallo/marlo.svg)](https://www.npmjs.com/package/@marshmallo/marlo)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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 with your API key
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
- 'my-agent',
22
- 'You are a helpful assistant.',
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', 'my-agent').start();
30
- task.input('Hello, how can you help?');
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
- task.llm({
34
- model: 'gpt-4',
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
- ## Features
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
- - **Task Tracking**: Capture agent inputs, outputs, and interactions
50
- - **LLM Call Recording**: Track model usage, tokens, and responses
51
- - **Tool Call Logging**: Record tool invocations and results
52
- - **Multi-Agent Support**: Track parent-child agent relationships
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 Reference
51
+ ## API
57
52
 
58
- ### Initialization
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 Registration
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` | Unique identifier for your agent |
89
- | `systemPrompt` | System prompt used by your agent |
90
- | `tools` | List of tool definitions `[{ name: "...", description: "..." }]` |
91
- | `mcp` | Optional list of MCP server definitions |
92
- | `modelConfig` | Optional model configuration `{ model: "gpt-4", ... }` |
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
- ### Task Tracking
73
+ ### Track Tasks
95
74
 
96
75
  ```typescript
97
- // Create and start a task
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
- // Create child task for multi-agent
112
- const child = task.child(agentName).start();
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
- // End the task
115
- task.end(hasError?: boolean);
85
+ task.end();
116
86
  ```
117
87
 
118
- ### Task Methods
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.llm({
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
- ```typescript
142
- task.tool(
143
- 'search',
144
- { query: 'weather' },
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
- #### `task.reasoning(text: string)`
151
- Record chain-of-thought or reasoning steps.
99
+ ### Multi-Agent
152
100
 
153
- #### `task.error(message: string)`
154
- Mark the task as failed with an error message.
101
+ ```typescript
102
+ const parent = marlo.task('thread-1', 'orchestrator').start();
103
+ parent.input('Research AI trends');
155
104
 
156
- #### `task.getLearnings()`
157
- Fetch learnings from past interactions.
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
- ```typescript
160
- const learnings = await task.getLearnings();
161
- if (learnings) {
162
- // Apply learnings to your agent
163
- }
110
+ parent.output('Report complete');
111
+ parent.end();
164
112
  ```
165
113
 
166
- #### `task.child(agentName: string)`
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
- ## Multi-Agent Example
120
+ ## Full Example
241
121
 
242
122
  ```typescript
243
123
  import * as marlo from '@marshmallo/marlo';
244
124
 
245
- await marlo.init('mk_abc123');
125
+ await marlo.init(process.env.MARLO_API_KEY);
246
126
 
247
- marlo.agent('orchestrator', 'You coordinate tasks.', []);
248
- marlo.agent('researcher', 'You research topics.', []);
249
- marlo.agent('writer', 'You write content.', []);
127
+ marlo.agent('support-bot', 'You are a customer support agent.', [
128
+ { name: 'lookup_order', description: 'Find order by ID' }
129
+ ]);
250
130
 
251
- const mainTask = marlo.task('doc-123', 'orchestrator').start();
252
- mainTask.input('Write a report about AI');
131
+ async function handleMessage(input: string, threadId: string) {
132
+ const task = marlo.task(threadId, 'support-bot').start();
133
+ task.input(input);
253
134
 
254
- // Delegate to researcher
255
- const research = mainTask.child('researcher').start();
256
- research.input('Research AI trends');
257
- research.output('AI trends: ...');
258
- research.end();
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
- // Delegate to writer
261
- const writer = mainTask.child('writer').start();
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
- mainTask.output('Report completed');
267
- mainTask.end();
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
- ## Environment Variables
154
+ task.output(response);
155
+ task.end();
271
156
 
272
- ```bash
273
- MARLO_API_KEY=your-api-key
157
+ return response;
158
+ }
274
159
  ```
275
160
 
276
161
  ## Requirements
277
162
 
278
- - Node.js 18.0.0 or later
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.0",
4
- "description": "Marlo SDK for agent observability and learning",
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",