@mindstudio-ai/agent 0.1.99 → 0.1.100

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
@@ -374,6 +374,60 @@ mindstudio batch --no-meta '[...]'
374
374
 
375
375
  Run `mindstudio batch` with no arguments for full usage help.
376
376
 
377
+ ## Task agents
378
+
379
+ `runTask()` runs a multi-step tool-use loop: the model receives your prompt and a set of tools
380
+ (SDK actions and/or your own app's methods), calls them as needed, and produces structured
381
+ output. Use it when the task needs judgment between steps — research, enrichment, content
382
+ pipelines — rather than a fixed sequence of calls.
383
+
384
+ Define the output contract with `outputSchema` — plain JSON Schema in the same dialect as a
385
+ tool definition (`type`, `properties`, `required`, `enum`, `items`; nullability via type
386
+ arrays like `['string', 'null']`). The output is validated every turn with automatic repair,
387
+ and `result.output` is typed by inference from the schema — no generic argument, no manual
388
+ validation:
389
+
390
+ ```typescript
391
+ const result = await agent.runTask({
392
+ prompt: 'Find canonical info for this restaurant, then save it.',
393
+ input: { restaurantName: 'Tartine Bakery SF' },
394
+ tools: [
395
+ 'searchGoogle',
396
+ 'fetchUrl',
397
+ { appMethod: 'saveRestaurant', description: 'Persist the researched restaurant.' },
398
+ ],
399
+ outputSchema: {
400
+ type: 'object',
401
+ properties: {
402
+ name: { type: 'string' },
403
+ url: { type: ['string', 'null'] },
404
+ kind: { enum: ['bakery', 'cafe', 'restaurant'] },
405
+ },
406
+ required: ['name', 'kind'],
407
+ },
408
+ model: 'claude-5-sonnet', // any current tool-use model id
409
+ });
410
+
411
+ result.output.kind; // typed as 'bakery' | 'cafe' | 'restaurant'
412
+ ```
413
+
414
+ With `outputSchema`, `runTask()` either returns conforming output or throws a
415
+ `MindStudioError` with `code === 'task_output_schema_mismatch'` (raw text and validation
416
+ errors in `err.details`) — it never resolves with garbage. Schemas outside the supported
417
+ dialect subset (`oneOf`, `$ref`, `nullable: true`, …) are rejected up front with
418
+ `task_output_schema_unsupported`. When building a schema in a variable rather than inline,
419
+ write it `as const satisfies JsonObjectSchema` to keep the literal inference.
420
+
421
+ The legacy alternative, `structuredOutputExample`, shapes output by example only: `output` is
422
+ typed by your generic argument and unvalidated — always check `result.parsedSuccessfully`
423
+ before using it.
424
+
425
+ App-method tools run as the user who invoked the method that started the task, with their
426
+ roles. Pass `onEvent` to stream progress (text chunks, tool calls, the final `done` event).
427
+
428
+ > `outputSchema` typing uses a `const` type parameter — consuming projects need
429
+ > TypeScript 5.0+.
430
+
377
431
  ## Thread persistence
378
432
 
379
433
  Steps execute within threads. Pass `$threadId` and `$appId` from a previous call to maintain state:
@@ -526,6 +580,11 @@ import type {
526
580
  BatchStepResult,
527
581
  ExecuteStepBatchOptions,
528
582
  ExecuteStepBatchResult,
583
+ RunTaskOptions,
584
+ RunTaskResult,
585
+ JsonSchema,
586
+ JsonObjectSchema,
587
+ FromSchema,
529
588
  } from '@mindstudio-ai/agent';
530
589
  ```
531
590