agi 0.4.0 → 0.5.1

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 CHANGED
@@ -1,554 +1,98 @@
1
- <div align="center">
1
+ # @agi_inc/cli
2
2
 
3
- <img src="https://cdn.prod.website-files.com/67be56277f6d514dcad939e2/67e48dd1cdab04c17a311669_logo-agi-white.png" alt="AGI" width="120"/>
3
+ Terminal-based AI agent for desktop automation. Give it a task in plain English and watch it take control of your computer to get it done.
4
4
 
5
- <h1>AGI Node.js SDK</h1>
6
-
7
- <p>
8
- <a href="https://www.npmjs.com/package/agi"><img src="https://img.shields.io/npm/v/agi?style=flat-square" alt="npm version"></a>
9
- <a href="https://github.com/agi-inc/agi-node/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/agi-inc/agi-node/ci.yml?branch=main&style=flat-square" alt="Build Status"></a>
10
- <a href="https://codecov.io/gh/agi-inc/agi-node"><img src="https://img.shields.io/codecov/c/github/agi-inc/agi-node?style=flat-square" alt="Coverage"></a>
11
- <a href="https://github.com/agi-inc/agi-node/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/agi?style=flat-square" alt="License"></a>
12
- <a href="https://www.npmjs.com/package/agi"><img src="https://img.shields.io/npm/dm/agi?style=flat-square" alt="Downloads"></a>
13
- </p>
14
-
15
- <p>
16
- <a href="https://www.theagi.company/">Website</a> •
17
- <a href="https://docs.agi.tech">Documentation</a> •
18
- <a href="https://platform.agi.tech">Platform</a> •
19
- <a href="https://theagi.company/blog">Blog</a>
20
- </p>
21
-
22
- ---
23
-
24
- **Universal Computer-Use AI**
25
-
26
- <br />
27
-
28
- </div>
29
-
30
- ```typescript
31
- import { AGIClient } from 'agi';
32
-
33
- const client = new AGIClient({ apiKey: process.env.AGI_API_KEY });
34
-
35
- // Context manager with automatic cleanup
36
- await using session = client.session('agi-0');
37
-
38
- const result = await session.runTask(
39
- 'Find three nonstop flights from SFO to JFK next month under $450. ' +
40
- 'Return flight times, airlines, and booking links.'
41
- );
42
-
43
- console.log(result.data);
44
- console.log(`Duration: ${result.metadata.duration}s, Steps: ${result.metadata.steps}`);
45
- // Session automatically deleted
5
+ ```bash
6
+ npx @agi_inc/cli "open calculator and compute 2+2"
46
7
  ```
47
8
 
48
- <br />
49
-
50
- > Powered by [AGI.tech](https://agi.tech) - the world's most capable computer agent. Trusted by [Visa](https://www.theagi.company/blog/agi-inc-visa) for agentic commerce. Evaluated with [REAL Bench](https://www.theagi.company/blog/introducing-real-bench).
51
-
52
- <br />
53
-
54
9
  ## Installation
55
10
 
56
- ```bash
57
- npm install agi
58
- ```
59
-
60
- Get your API key at [platform.agi.tech](https://platform.agi.tech/api-keys)
11
+ **Zero-install** (recommended):
61
12
 
62
13
  ```bash
63
- export AGI_API_KEY="your-api-key"
64
- ```
65
-
66
- ## Quick Start
67
-
68
- ### Simple Task (Recommended)
69
-
70
- ```typescript
71
- import { AGIClient } from 'agi';
72
-
73
- const client = new AGIClient({ apiKey: process.env.AGI_API_KEY });
74
-
75
- // Context manager with automatic cleanup
76
- await using session = client.session('agi-0');
77
-
78
- const result = await session.runTask('Find the cheapest iPhone 15 on Amazon');
79
-
80
- console.log(result.data); // Task output
81
- console.log(result.metadata.duration); // Execution time in seconds
82
- console.log(result.metadata.steps); // Number of steps taken
83
- // Session automatically deleted when scope exits
84
- ```
85
-
86
- ### Real-Time Event Streaming
87
-
88
- ```typescript
89
- await using session = client.session('agi-0');
90
-
91
- await session.sendMessage('Research the top 5 AI companies in 2025');
92
-
93
- for await (const event of session.streamEvents()) {
94
- if (event.event === 'thought') {
95
- console.log('💭 Agent:', event.data);
96
- }
97
- if (event.event === 'done') {
98
- console.log('✅ Result:', event.data);
99
- break;
100
- }
101
- }
102
- // Session automatically deleted
103
- ```
104
-
105
- ### Polling Configuration
106
-
107
- Configure timeouts and polling intervals for different task types:
108
-
109
- ```typescript
110
- await using session = client.session('agi-0');
111
-
112
- // Quick task (1 min timeout, 2s polling)
113
- const result1 = await session.runTask('What is 2+2?', {
114
- timeout: 60000,
115
- pollInterval: 2000,
116
- });
117
-
118
- // Complex task (15 min timeout, 5s polling)
119
- const result2 = await session.runTask('Research AI companies...', {
120
- timeout: 900000,
121
- pollInterval: 5000,
122
- });
123
- ```
124
-
125
- ### Manual Session Management
126
-
127
- For advanced use cases requiring fine-grained control:
128
-
129
- ```typescript
130
- // Create session manually
131
- const response = await client.sessions.create('agi-0', {
132
- webhookUrl: 'https://yourapp.com/webhook',
133
- maxSteps: 200,
134
- });
135
-
136
- // Send message
137
- await client.sessions.sendMessage(response.sessionId, 'Find flights from SFO to JFK under $450');
138
-
139
- // Check status
140
- const status = await client.sessions.getStatus(response.sessionId);
141
-
142
- // Delete when done
143
- await client.sessions.delete(response.sessionId);
144
- ```
145
-
146
- ### Session Control
147
-
148
- ```typescript
149
- await using session = client.session('agi-0');
150
-
151
- await session.sendMessage('Long research task...');
152
-
153
- // Control execution
154
- await session.pause(); // Pause the agent
155
- await session.resume(); // Resume later
156
- await session.cancel(); // Or cancel
157
- ```
158
-
159
- ---
160
-
161
- ## Core Concepts
162
-
163
- _Understanding the building blocks of agi_
164
-
165
- ### Sessions: The Container for Tasks
166
-
167
- Every task runs inside a **session** - an isolated browser environment:
168
-
169
- ```typescript
170
- // Recommended: Context manager (automatic cleanup)
171
- await using session = client.session('agi-0');
172
- await session.runTask('Find flights...');
173
- // Session automatically deleted
174
-
175
- // Alternative: Manual management
176
- const response = await client.sessions.create('agi-0');
177
- await client.sessions.delete(response.sessionId);
178
- ```
179
-
180
- ▸ Use context managers (`await using`) for automatic cleanup. Sessions consume resources and should be deleted when done.
181
-
182
- ### Available Agents
183
-
184
- - **agi-0** - General purpose agent (recommended)
185
- - **agi-0-fast** - Faster agent for simple tasks
186
- - **agi-1** - Advanced agent with enhanced capabilities
187
-
188
- See [docs.agi.tech](https://docs.agi.tech) for the full list.
189
-
190
- ---
191
-
192
- ## Features
193
-
194
- - **Natural Language** - Describe tasks in plain English, no selectors or scraping code
195
- - **Real-Time Streaming** - Watch agent execution live with Server-Sent Events
196
- - **Session Control** - Pause, resume, or cancel long-running tasks
197
- - **Browser Control** - Navigate and screenshot for visual debugging
198
- - **Type-Safe** - Full TypeScript support with comprehensive type definitions
199
- - **Production-Ready** - Built-in retries, automatic cleanup, comprehensive error handling
200
-
201
- ---
202
-
203
- ## Common Use Cases
204
-
205
- ### Price Monitoring
206
-
207
- Monitor product prices and availability across retailers.
208
-
209
- ```typescript
210
- const session = await client.createSession('agi-0');
211
-
212
- try {
213
- const result = await session.runTask(
214
- 'Go to amazon.com and search for "Sony WH-1000XM5". ' +
215
- "Get the current price, check if it's in stock, and return the product rating. " +
216
- 'Return as JSON with fields: price, in_stock, rating, url.'
217
- );
218
- console.log(result);
219
- } finally {
220
- await session.delete();
221
- }
222
- ```
223
-
224
- ### Lead Generation
225
-
226
- Extract structured data from public sources.
227
-
228
- ```typescript
229
- const session = await client.createSession('agi-0');
230
-
231
- try {
232
- const result = await session.runTask(
233
- 'Go to ycombinator.com/companies, find companies in the "AI" category ' +
234
- 'from the latest batch. For the first 10 companies, get their name, ' +
235
- 'description, and website. Return as a JSON array.'
236
- );
237
- console.log(result);
238
- } finally {
239
- await session.delete();
240
- }
241
- ```
242
-
243
- ### Flight Booking Research
244
-
245
- ```typescript
246
- const session = await client.createSession('agi-0');
247
-
248
- try {
249
- const result = await session.runTask(
250
- 'Find three nonstop SFO→JFK flights next month under $450. ' +
251
- 'Compare prices on Google Flights, Kayak, and Expedia. ' +
252
- 'Return flight details and booking links.'
253
- );
254
- console.log(result);
255
- } finally {
256
- await session.delete();
257
- }
258
- ```
259
-
260
- <details>
261
- <summary><b>Browser Control</b> – Navigate and take screenshots for visual debugging</summary>
262
-
263
- <br />
264
-
265
- ```typescript
266
- const session = await client.createSession('agi-0');
267
-
268
- try {
269
- // Navigate to specific URL
270
- await session.navigate('https://amazon.com');
271
-
272
- // Get screenshot for debugging
273
- const screenshot = await session.screenshot();
274
- console.log(screenshot.url); // Current page URL
275
- console.log(screenshot.title); // Page title
276
- // screenshot.screenshot contains base64 JPEG data
277
- } finally {
278
- await session.delete();
279
- }
280
- ```
281
-
282
- </details>
283
-
284
- <details>
285
- <summary><b>Session Snapshots</b> – Preserve authentication and browser state</summary>
286
-
287
- <br />
288
-
289
- ```typescript
290
- // Create session and save environment
291
- const session1 = await client.createSession('agi-0');
292
- // ... do some authentication work ...
293
- await session1.delete('filesystem');
294
-
295
- // Later, restore from saved environment
296
- const session2 = await client.createSession('agi-0', {
297
- restoreFromEnvironmentId: session1.environmentId,
298
- });
299
- // Authentication state and cookies preserved!
300
-
301
- await session2.delete();
302
- ```
303
-
304
- </details>
305
-
306
- <details>
307
- <summary><b>Advanced Session Management</b> – Full control over session lifecycle</summary>
308
-
309
- <br />
310
-
311
- ```typescript
312
- // Create session with options
313
- const session = await client.createSession('agi-0-fast', {
314
- webhookUrl: 'https://yourapp.com/webhook',
315
- maxSteps: 200,
316
- });
317
-
318
- // Send message
319
- await session.sendMessage('Find flights from SFO to JFK under $450');
320
-
321
- // Check status
322
- const status = await session.getStatus();
323
- console.log(status.status); // "running", "finished", etc.
324
-
325
- // List all sessions
326
- const sessions = await client.listSessions();
327
-
328
- // Delete when done
329
- await session.delete();
330
- ```
331
-
332
- </details>
333
-
334
- <details>
335
- <summary><b>Webhooks</b> – Get notified when tasks complete</summary>
336
-
337
- <br />
338
-
339
- ```typescript
340
- const session = await client.createSession('agi-0', {
341
- webhookUrl: 'https://yourapp.com/webhook',
342
- });
343
-
344
- // Your webhook will receive events:
345
- // POST https://yourapp.com/webhook
346
- // {
347
- // "event": "done",
348
- // "session_id": "sess_...",
349
- // "data": {...}
350
- // }
14
+ npx @agi_inc/cli "your task here"
351
15
  ```
352
16
 
353
- </details>
17
+ **Global install**:
354
18
 
355
- <details>
356
- <summary><b>Client-Driven Sessions</b> Run agents on desktop, mobile, or custom environments</summary>
357
-
358
- <br />
359
-
360
- > **Note:** Desktop mode is currently feature-gated. For enterprise access, contact [`partner@theagi.company`](mailto:partner@theagi.company).
361
-
362
- For scenarios where you control the execution environment (desktop automation, mobile apps, custom browsers), use client-driven sessions with `AgentLoop`:
363
-
364
- ```typescript
365
- import { AGIClient, AgentLoop } from 'agi';
366
-
367
- const client = new AGIClient({ apiKey: process.env.AGI_API_KEY });
368
-
369
- // Create a client-driven session
370
- const session = await client.sessions.create('agi-2-claude', {
371
- agentSessionType: 'desktop',
372
- goal: 'Open calculator and compute 2+2',
373
- });
374
-
375
- // Create and run the loop
376
- const loop = new AgentLoop({
377
- client,
378
- agentUrl: session.agentUrl!,
379
- captureScreenshot: async () => {
380
- // Return base64-encoded screenshot from your environment
381
- return '...';
382
- },
383
- executeActions: async (actions) => {
384
- for (const action of actions) {
385
- console.log(`Executing: ${action.type}`);
386
- // Execute action in your environment
387
- }
388
- },
389
- onThinking: (t) => console.log(`💭 ${t}`),
390
- });
391
-
392
- const result = await loop.start();
393
- console.log(`Finished: ${result.finished}`);
394
- ```
395
-
396
- **Loop Control:**
397
-
398
- ```typescript
399
- // Start without awaiting
400
- const promise = loop.start();
401
-
402
- // Pause/resume/stop
403
- loop.pause(); // Pause after current step
404
- loop.resume(); // Continue execution
405
- loop.stop(); // Stop the loop
406
-
407
- // Check state
408
- loop.state; // 'running', 'paused', 'stopped', 'finished'
409
- loop.currentStep; // Current step number
410
- loop.lastResult; // Last StepDesktopResponse
19
+ ```bash
20
+ npm install -g @agi_inc/cli
21
+ agi "your task here"
411
22
  ```
412
23
 
413
- **Manual Step Control:**
24
+ **Homebrew** (macOS/Linux):
414
25
 
415
- ```typescript
416
- // Or manage the loop yourself
417
- let finished = false;
418
- while (!finished) {
419
- const screenshot = await captureScreenshot();
420
- const result = await client.sessions.step(session.agentUrl!, screenshot);
421
- await executeActions(result.actions);
422
- finished = result.finished;
423
- }
26
+ ```bash
27
+ brew install agi-inc/tap/agi
28
+ agi "your task here"
424
29
  ```
425
30
 
426
- </details>
427
-
428
- ---
429
-
430
- ## Error Handling
431
-
432
- <details>
433
- <summary><b>Robust error handling with detailed debugging</b></summary>
31
+ ## Configuration
434
32
 
435
- <br />
33
+ Set your API key before running:
436
34
 
437
- ```typescript
438
- import {
439
- AGIClient,
440
- AuthenticationError,
441
- NotFoundError,
442
- RateLimitError,
443
- AgentExecutionError,
444
- AGIError,
445
- } from 'agi';
446
-
447
- const client = new AGIClient({ apiKey: process.env.AGI_API_KEY });
448
-
449
- try {
450
- const session = await client.createSession('agi-0');
451
- try {
452
- const result = await session.runTask('Find flights...');
453
- console.log(result);
454
- } finally {
455
- await session.delete();
456
- }
457
- } catch (error) {
458
- if (error instanceof AuthenticationError) {
459
- console.error('Invalid API key');
460
- } else if (error instanceof NotFoundError) {
461
- console.error('Session not found');
462
- } else if (error instanceof RateLimitError) {
463
- console.error('Rate limit exceeded - please retry');
464
- } else if (error instanceof AgentExecutionError) {
465
- console.error('Task failed:', error.message);
466
- // Debug at VNC URL if available
467
- } else if (error instanceof AGIError) {
468
- console.error('API error:', error.message);
469
- }
470
- }
35
+ ```bash
36
+ export AGI_API_KEY=your_api_key
37
+ # or
38
+ export ANTHROPIC_API_KEY=your_api_key
471
39
  ```
472
40
 
473
- </details>
474
-
475
- ---
476
-
477
- ## Examples
478
-
479
- **Real-world, production-ready examples** → See [examples/](./examples)
480
-
481
- ### Quick Start
41
+ ## Usage
482
42
 
483
43
  ```bash
484
- # 5-line hello world
485
- npx tsx examples/hello-world.ts
44
+ # Basic usage
45
+ agi "Open calculator and compute 2+2"
486
46
 
487
- # Price tracking
488
- npx tsx examples/ecommerce/price-tracker.ts \
489
- --product "Sony WH-1000XM5" --max-price 350
47
+ # Use a specific model
48
+ agi "Find flights from SFO to JFK" --model claude-opus
490
49
 
491
- # Flight search
492
- npx tsx examples/travel/flight-finder.ts \
493
- --from SFO --to JFK --date "2026-02-15" --max-price 450
50
+ # Verbose output (shows agent thinking)
51
+ agi "Install Node.js" --verbose
494
52
 
495
- # B2B lead generation
496
- npx tsx examples/sales-marketing/linkedin-scraper.ts \
497
- --industry "SaaS" --location "San Francisco" --count 10
498
-
499
- # Competitor analysis
500
- npx tsx examples/research/competitor-analysis.ts \
501
- --competitors "stripe.com,square.com,paypal.com"
53
+ # Auto-approve confirmations
54
+ agi "Delete old files" --no-confirm
502
55
  ```
503
56
 
504
- ### Example Categories
505
-
506
- - **[Basic](./examples#-basic-examples-basic)** (⭐ Beginner) - Quickstart, error handling, streaming
507
- - **[E-Commerce](./examples#-e-commerce-ecommerce)** (⭐⭐ Intermediate) - Price tracking, product comparison
508
- - **[Travel](./examples#️-travel-travel)** (⭐⭐ Intermediate) - Flight search, booking research
509
- - **[Sales & Marketing](./examples#-sales--marketing-sales-marketing)** (⭐⭐ Intermediate) - Lead generation, LinkedIn scraping
510
- - **[Research](./examples#-research-research)** (⭐⭐ Intermediate) - Competitive analysis, market research
511
- - **[Production](./examples#-production-patterns-production)** (⭐⭐⭐ Advanced) - Batch processing, webhook servers
57
+ ## Options
512
58
 
513
- **Learning Path**: [hello-world.ts](./examples/hello-world.ts) [basic/quickstart.ts](./examples/basic/quickstart.ts) [Choose your domain](./examples#-examples-by-category) → [Production patterns](./examples#-production-patterns-production)
59
+ | Option | Alias | Description | Default |
60
+ |--------|-------|-------------|---------|
61
+ | `--model` | `-m` | Model to use (`claude-sonnet`, `claude-opus`) | `claude-sonnet` |
62
+ | `--verbose` | `-v` | Show agent thinking | `false` |
63
+ | `--no-confirm` | | Auto-approve confirmations | `false` |
64
+ | `--help` | `-h` | Show help | |
65
+ | `--version` | `-V` | Show version | |
514
66
 
515
- ---
67
+ ## Keyboard Shortcuts
516
68
 
517
- ## Documentation & Resources
69
+ While the agent is running:
518
70
 
519
- **Learn More**
71
+ | Key | Action |
72
+ |-----|--------|
73
+ | `Space` | Pause/Resume |
74
+ | `Q` | Stop |
75
+ | `Ctrl+C` | Cancel |
520
76
 
521
- - [API Reference](https://docs.agi.tech) – Complete API documentation
522
- - [Code Examples](./examples) – 15+ production-ready examples
523
- - [GitHub Issues](https://github.com/agi-inc/agi-node/issues) – Report bugs or request features
77
+ ## How It Works
524
78
 
525
- **Get Help**
526
-
527
- - [Platform](https://platform.agi.tech) Manage API keys and monitor usage
528
- - [Documentation](https://docs.agi.tech) Guides and tutorials
529
-
530
- ---
531
-
532
- ## TypeScript Support
533
-
534
- This SDK is written in TypeScript and provides full type definitions:
535
-
536
- ```typescript
537
- import type { Session, SessionStatus, SSEEvent, NavigateResponse } from 'agi';
538
-
539
- const session: Session = await client.createSession('agi-0');
540
- const status: SessionStatus = (await session.getStatus()).status;
541
- ```
542
-
543
- ---
79
+ 1. Captures screenshots of your desktop
80
+ 2. Analyzes them using Claude
81
+ 3. Decides on and executes actions
82
+ 4. Repeats until the task is complete
544
83
 
545
84
  ## Requirements
546
85
 
547
- - Node.js 20.4 or higher (required for `await using` syntax)
548
- - TypeScript 5.0+ (for TypeScript users)
86
+ - Node.js 20.4.0 or later
87
+ - macOS, Linux, or Windows
88
+ - AGI API key or Anthropic API key
89
+
90
+ ## SDKs
549
91
 
550
- ---
92
+ - [agi-python](https://github.com/agi-inc/agi-python) — Python SDK
93
+ - [agi-node](https://github.com/agi-inc/agi-node) — Node.js SDK
94
+ - [agi-csharp](https://github.com/agi-inc/agi-csharp) — C# SDK
551
95
 
552
96
  ## License
553
97
 
554
- MIT License - see [LICENSE](LICENSE) for details.
98
+ MIT
package/bin/agi ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import('../dist/index.mjs');