@ariaflowagents/config 0.4.0 → 0.4.3

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,50 +1,517 @@
1
- # @ariaflowagents/config
1
+ # AriaFlow Config Guide
2
2
 
3
- Config loader for AriaFlow projects. This package parses `ariaflow.json(c)` and `.ariaflow/*` directories to produce ready-to-run agent configs.
3
+ A comprehensive guide to creating and managing AriaFlow agent configurations.
4
4
 
5
- ## Usage
5
+ ## Overview
6
6
 
7
- ```ts
8
- import 'dotenv/config';
9
- import { openai } from '@ai-sdk/openai';
10
- import { createRuntimeFromConfig, loadAriaflowConfig } from '@ariaflowagents/config';
7
+ The AriaFlow Config package (`@ariaflowagents/config`) provides:
8
+ - Configuration loading from `ari aflow.jsonc` files
9
+ - Agent and flow definition parsing
10
+ - Tool registration and loading
11
+ - Runtime creation from config
11
12
 
12
- const loaded = await loadAriaflowConfig({
13
- cwd: process.cwd(),
14
- modelRegistry: {
15
- default: openai('gpt-4o-mini') as any,
16
- 'openai:gpt-4o-mini': openai('gpt-4o-mini') as any,
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @ariaflowagents/config
17
+ ```
18
+
19
+ ## Configuration File
20
+
21
+ ### Basic Structure
22
+
23
+ ```jsonc
24
+ {
25
+ "$schema": "https://ariaflow.ai/config.json",
26
+ "name": "my-agent",
27
+ "version": "1.0.0",
28
+ "runtime": {
29
+ "defaultAgent": "chat",
30
+ "defaultModel": "default"
17
31
  },
18
- });
32
+ "models": {
33
+ "default": "openai:gpt-4o-mini"
34
+ },
35
+ "agents": { /* ... */ },
36
+ "tools": { /* ... */ },
37
+ "providers": { /* ... */ }
38
+ }
39
+ ```
40
+
41
+ ## Runtime Configuration
42
+
43
+ ### Default Agent & Model
44
+
45
+ ```jsonc
46
+ {
47
+ "runtime": {
48
+ "defaultAgent": "chat",
49
+ "defaultModel": "default"
50
+ }
51
+ }
52
+ ```
53
+
54
+ ### Model Registry
55
+
56
+ Define available models with providers:
57
+
58
+ ```jsonc
59
+ {
60
+ "models": {
61
+ "default": "openai:gpt-4o-mini",
62
+ "gpt-4": "openai:gpt-4",
63
+ "claude-3": "anthropic:claude-3-5-sonnet-20241022"
64
+ }
65
+ }
66
+ ```
67
+
68
+ ### Auto Retrieve (always-on)
69
+
70
+ Calls a retriever tool before every model run and injects the context.
71
+
72
+ ```jsonc
73
+ {
74
+ "runtime": {
75
+ "autoRetrieve": {
76
+ "type": "tool",
77
+ "toolName": "cag_retrieve"
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ ### Structured Triage
84
+
85
+ Force triage responses into a schema and route without leaking triage text.
86
+
87
+ ```jsonc
88
+ {
89
+ "runtime": {
90
+ "triageMode": "structured",
91
+ "triageAgent": "triage"
92
+ }
93
+ }
94
+ ```
95
+
96
+ ### Always Route Through Triage
97
+
98
+ Useful when every user turn should be re-routed.
99
+
100
+ ```jsonc
101
+ {
102
+ "runtime": {
103
+ "alwaysRouteThroughTriage": true
104
+ }
105
+ }
106
+ ```
107
+
108
+ ## Agents
109
+
110
+ Agents are the core components that handle user interactions.
111
+
112
+ ### LLM Agent
113
+
114
+ ```jsonc
115
+ {
116
+ "agents": {
117
+ "chat": {
118
+ "type": "llm",
119
+ "description": "A helpful assistant",
120
+ "prompt": {
121
+ "inline": "You are a helpful assistant. Be concise."
122
+ },
123
+ "tools": ["search", "calculator"]
124
+ }
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Triage Agent
130
+
131
+ Routes users to specialized agents:
132
+
133
+ ```jsonc
134
+ {
135
+ "agents": {
136
+ "triage": {
137
+ "type": "triage",
138
+ "description": "Routes customers to the right department",
139
+ "prompt": { "file": "./prompts/triage.md" },
140
+ "routes": [
141
+ {
142
+ "agentId": "sales",
143
+ "description": "Handles sales inquiries"
144
+ },
145
+ {
146
+ "agentId": "support",
147
+ "description": "Handles support issues"
148
+ }
149
+ ],
150
+ "defaultAgent": "sales"
151
+ }
152
+ }
153
+ }
154
+ ```
155
+
156
+ ### Flow Agent
157
+
158
+ Guided workflow agents:
159
+
160
+ ```jsonc
161
+ {
162
+ "agents": {
163
+ "booking": {
164
+ "type": "flow",
165
+ "description": "Hotel booking flow",
166
+ "prompt": { "file": "./prompts/booking.md" },
167
+ "flowRef": "booking-flow",
168
+ "mode": "hybrid"
169
+ }
170
+ }
171
+ }
172
+ ```
173
+
174
+ ### Inline Prompt
175
+
176
+ For simple agents, use inline prompts:
177
+
178
+ ```jsonc
179
+ {
180
+ "agents": {
181
+ "chat": {
182
+ "type": "llm",
183
+ "description": "A helpful assistant",
184
+ "prompt": {
185
+ "inline": "You are a helpful assistant. Be concise and friendly."
186
+ }
187
+ }
188
+ }
189
+ }
190
+ ```
191
+
192
+ ### File-based Prompt
193
+
194
+ For complex prompts, use external files:
195
+
196
+ ```jsonc
197
+ {
198
+ "agents": {
199
+ "support": {
200
+ "type": "llm",
201
+ "description": "Customer support",
202
+ "prompt": { "file": "./prompts/support.md" }
203
+ }
204
+ }
205
+ }
206
+ ```
207
+
208
+ Create the prompt file:
209
+
210
+ ```markdown
211
+ # System Prompt
212
+
213
+ You are a customer support agent for our company.
214
+
215
+ ## Guidelines
216
+ - Be empathetic and patient
217
+ - Always verify customer identity before sharing sensitive info
218
+ - Escalate complex issues to human agents
219
+
220
+ ## Tools Available
221
+ - create_ticket: Create support tickets
222
+ ```
223
+
224
+ ## Tools
225
+
226
+ ### External Tools
227
+
228
+ Define tools that agents can use:
229
+
230
+ ```jsonc
231
+ {
232
+ "tools": {
233
+ "search": {
234
+ "type": "module",
235
+ "entry": "./tools/search/index.ts"
236
+ },
237
+ "calculator": {
238
+ "type": "module",
239
+ "entry": "./tools/calculator/index.ts"
240
+ }
241
+ }
242
+ }
243
+ ```
244
+
245
+ Tool implementation (`tools/search/index.ts`):
246
+
247
+ ```typescript
248
+ import type { ToolDefinition } from '@ariaflowagents/core';
249
+
250
+ export const tool: ToolDefinition = {
251
+ description: 'Search for information',
252
+ inputSchema: {
253
+ type: 'object',
254
+ properties: {
255
+ query: { type: 'string', description: 'Search query' }
256
+ },
257
+ required: ['query']
258
+ },
259
+ execute: async (input: unknown) => {
260
+ const { query } = input as { query: string };
261
+ // Implementation
262
+ return { results: [...] };
263
+ }
264
+ };
265
+
266
+ export default tool;
267
+ ```
268
+
269
+ ### Skill Loader
270
+
271
+ Load skills from a directory:
272
+
273
+ ```jsonc
274
+ {
275
+ "tools": {
276
+ "skill": {
277
+ "type": "skill-loader",
278
+ "paths": ["./skill"]
279
+ }
280
+ }
281
+ }
282
+ ```
283
+
284
+ ## Flows
19
285
 
20
- const runtime = createRuntimeFromConfig(loaded);
286
+ Define reusable workflow patterns:
21
287
 
22
- for await (const part of runtime.stream({ input: 'Hello!' })) {
23
- if (part.type === 'text-delta') process.stdout.write(part.text);
288
+ ```jsonc
289
+ {
290
+ "flows": {
291
+ "booking-flow": {
292
+ "steps": [
293
+ {
294
+ "id": "collect-info",
295
+ "tool": "collect_info"
296
+ },
297
+ {
298
+ "id": "confirm",
299
+ "tool": "confirm_booking"
300
+ }
301
+ ]
302
+ }
303
+ }
24
304
  }
25
305
  ```
26
306
 
27
- ## Config Locations (Precedence)
307
+ ## Providers
308
+
309
+ Configure API providers:
28
310
 
29
- 1. Global: `~/.config/ariaflow/ariaflow.json(c)`
30
- 2. Custom: `ARIAFLOW_CONFIG`
31
- 3. Project: `ariaflow.json(c)` at git root
32
- 4. `.ariaflow/` directories (agents/flows/tools/skills)
33
- 5. Inline: `ARIAFLOW_CONFIG_CONTENT`
311
+ ```jsonc
312
+ {
313
+ "providers": {
314
+ "openai": {
315
+ "apiKey": "OPENAI_API_KEY",
316
+ "baseUrl": "https://api.openai.com/v1"
317
+ },
318
+ "anthropic": {
319
+ "apiKey": "ANTHROPIC_API_KEY"
320
+ }
321
+ }
322
+ }
323
+ ```
34
324
 
35
- ## Folder Layout
325
+ ## Loading Configuration
36
326
 
327
+ ### Basic Loading
328
+
329
+ ```typescript
330
+ import { loadAriaflowConfig } from '@ariaflowagents/config';
331
+
332
+ const config = await loadAriaflowConfig({
333
+ configPath: './ari aflow.jsonc'
334
+ });
37
335
  ```
38
- .ariaflow/
39
- agent/
40
- flow/
41
- tools/
42
- skill/
43
- prompts/
336
+
337
+ ### With Model Registry
338
+
339
+ ```typescript
340
+ import { loadAriaflowConfigWithResult } from '@ariaflowagents/config';
341
+ import { openai } from '@ai-sdk/openai';
342
+
343
+ const model = openai('gpt-4o-mini') as any;
344
+
345
+ const { config, summary, warnings } = await loadAriaflowConfigWithResult({
346
+ configPath: './ari aflow.jsonc',
347
+ modelRegistry: {
348
+ default: model,
349
+ 'openai:gpt-4o-mini': model
350
+ }
351
+ });
352
+
353
+ console.log(`Loaded ${summary.agents} agents`);
44
354
  ```
45
355
 
46
- ## Notes
47
- - Models are resolved via `modelRegistry`.
48
- - Tools can be loaded from `.ariaflow/tools/*/tool.json` and config entries.
49
- - Skill loading is opt-in via a `skill-loader` tool config.
356
+ ### Create Runtime
357
+
358
+ ```typescript
359
+ import { createRuntimeFromConfig } from '@ariaflowagents/config';
360
+
361
+ const { config } = await loadAriaflowConfigWithResult({
362
+ configPath: './ari aflow.jsonc'
363
+ });
364
+
365
+ const runtime = createRuntimeFromConfig(config);
366
+ ```
367
+
368
+ ## Directory Structure
369
+
370
+ ```
371
+ my-agent/
372
+ ├── ariaflow.jsonc # Main configuration
373
+ ├── .ariaflow/
374
+ │ ├── prompts/
375
+ │ │ ├── system.md # System prompts
376
+ │ │ ├── chat.md # Agent prompts
377
+ │ │ └── triage.md # Triage prompts
378
+ │ ├── tools/
379
+ │ │ ├── search/
380
+ │ │ │ ├── index.ts # Tool implementation
381
+ │ │ │ └── tool.json # Tool metadata
382
+ │ │ └── calculator/
383
+ │ │ ├── index.ts
384
+ │ │ └── tool.json
385
+ │ ├── skill/
386
+ │ │ └── my-skill/
387
+ │ │ └── SKILL.md
388
+ │ └── flow/
389
+ │ └── booking-flow.json # Flow definitions
390
+ └── package.json # Optional: Tool dependencies
391
+ ```
392
+
393
+ ## Example: Complete Configuration
394
+
395
+ ```jsonc
396
+ {
397
+ "$schema": "https://ariaflow.ai/config.json",
398
+ "name": "support-agent",
399
+ "version": "1.0.0",
400
+ "runtime": {
401
+ "defaultAgent": "triage",
402
+ "defaultModel": "gpt-4o-mini"
403
+ },
404
+ "models": {
405
+ "default": "openai:gpt-4o-mini",
406
+ "gpt-4": "openai:gpt-4"
407
+ },
408
+ "agents": {
409
+ "triage": {
410
+ "type": "triage",
411
+ "description": "Routes support requests",
412
+ "prompt": { "file": "./prompts/triage.md" },
413
+ "routes": [
414
+ { "agentId": "billing", "description": "Billing inquiries" },
415
+ { "agentId": "technical", "description": "Technical support" }
416
+ ],
417
+ "defaultAgent": "billing"
418
+ },
419
+ "billing": {
420
+ "type": "llm",
421
+ "description": "Handles billing questions",
422
+ "prompt": { "file": "./prompts/billing.md" },
423
+ "tools": ["create_ticket"]
424
+ },
425
+ "technical": {
426
+ "type": "llm",
427
+ "description": "Technical support",
428
+ "prompt": { "file": "./prompts/technical.md" },
429
+ "tools": ["diagnose", "create_ticket"]
430
+ }
431
+ },
432
+ "tools": {
433
+ "create_ticket": {
434
+ "type": "module",
435
+ "entry": "./tools/create_ticket/index.ts"
436
+ },
437
+ "diagnose": {
438
+ "type": "module",
439
+ "entry": "./tools/diagnose/index.ts"
440
+ }
441
+ },
442
+ "providers": {
443
+ "openai": {
444
+ "apiKey": "OPENAI_API_KEY"
445
+ }
446
+ }
447
+ }
448
+ ```
449
+
450
+ ## Configuration Reference
451
+
452
+ ### Root Properties
453
+
454
+ | Property | Type | Required | Description |
455
+ |----------|------|----------|-------------|
456
+ | `$schema` | string | No | JSON schema URI |
457
+ | `name` | string | Yes | Agent name |
458
+ | `version` | string | No | Version number |
459
+ | `runtime` | object | Yes | Runtime configuration |
460
+ | `models` | object | Yes | Model registry |
461
+ | `agents` | object | Yes | Agent definitions |
462
+ | `tools` | object | No | Tool definitions |
463
+ | `providers` | object | No | Provider configurations |
464
+ | `permissions` | object | No | Permission settings |
465
+
466
+ ### Runtime Properties
467
+
468
+ | Property | Type | Description |
469
+ |----------|------|-------------|
470
+ | `defaultAgent` | string | Default agent ID |
471
+ | `defaultModel` | string | Default model key |
472
+
473
+ ### Agent Properties
474
+
475
+ | Property | Type | Description |
476
+ |----------|------|-------------|
477
+ | `type` | string | Agent type: `llm`, `triage`, `flow` |
478
+ | `description` | string | Agent description |
479
+ | `prompt` | object | Prompt configuration |
480
+ | `tools` | array | List of tool names |
481
+ | `routes` | array | Triage routes (triage only) |
482
+ | `defaultAgent` | string | Default route (triage only) |
483
+ | `flowRef` | string | Flow reference (flow only) |
484
+ | `mode` | string | Flow mode: `guided`, `hybrid` (flow only) |
485
+
486
+ ### Prompt Properties
487
+
488
+ | Property | Type | Description |
489
+ |----------|------|-------------|
490
+ | `inline` | string | Inline prompt text |
491
+ | `file` | string | Path to prompt file |
492
+
493
+ ## Best Practices
494
+
495
+ 1. **Use file-based prompts** for complex prompts (>100 lines)
496
+ 2. **Organize tools** in separate directories with `tool.json` metadata
497
+ 3. **Use triage agents** for multi-agent routing
498
+ 4. **Version your config** using semantic versioning
499
+ 5. **Test locally** using the Hono server before deployment
500
+ 6. **Use environment variables** for API keys
501
+
502
+ ## Integration with Hono Server
503
+
504
+ ```typescript
505
+ import { loadAriaflowConfigWithResult, createRuntimeFromConfig } from '@ariaflowagents/config';
506
+ import { createAriaChatRouter } from '@ariaflowagents/hono-server';
507
+
508
+ const { config, summary } = await loadAriaflowConfigWithResult({
509
+ configPath: './ari aflow.jsonc',
510
+ modelRegistry: { default: model }
511
+ });
512
+
513
+ const runtime = createRuntimeFromConfig(config);
514
+
515
+ const app = new Hono();
516
+ app.route('/', createAriaChatRouter({ runtime }));
50
517
  ```
package/dist/loader.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type HarnessConfig, type Runtime } from '@ariaflowagents/core';
2
2
  import type { LoadedConfig, LoadOptions } from './types.js';
3
- type WarningType = 'invalid_frontmatter' | 'missing_prompt' | 'name_mismatch' | 'missing_ref' | 'invalid_tool_entry' | 'duplicate_agent' | 'duplicate_flow' | 'unresolved_flow_ref' | 'tool_not_found';
3
+ type WarningType = 'invalid_frontmatter' | 'missing_prompt' | 'missing_template' | 'name_mismatch' | 'missing_ref' | 'invalid_tool_entry' | 'duplicate_agent' | 'duplicate_flow' | 'unresolved_flow_ref' | 'tool_not_found';
4
4
  interface ConfigWarning {
5
5
  type: WarningType;
6
6
  file: string;
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAWA,OAAO,EAKL,KAAK,aAAa,EAElB,KAAK,OAAO,EAEb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAIV,YAAY,EACZ,WAAW,EAMZ,MAAM,YAAY,CAAC;AA0CpB,KAAK,WAAW,GACZ,qBAAqB,GACrB,gBAAgB,GAChB,eAAe,GACf,aAAa,GACb,oBAAoB,GACpB,iBAAiB,GACjB,gBAAgB,GAChB,qBAAqB,GACrB,gBAAgB,CAAC;AAErB,UAAU,aAAa;IACrB,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AAorBD,wBAAsB,kBAAkB,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CA4PzF;AAED,wBAAsB,4BAA4B,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC;IACrF,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAA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