@ariaflowagents/core 0.7.0 → 0.8.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 +90 -1
- package/dist/agents/Agent.d.ts +188 -9
- package/dist/agents/Agent.d.ts.map +1 -1
- package/dist/agents/Agent.js +246 -24
- package/dist/agents/Agent.js.map +1 -1
- package/dist/agents/CompositeAgent.d.ts +4 -3
- package/dist/agents/CompositeAgent.d.ts.map +1 -1
- package/dist/agents/CompositeAgent.js +19 -9
- package/dist/agents/CompositeAgent.js.map +1 -1
- package/dist/agents/FlowAgent.d.ts +3 -2
- package/dist/agents/FlowAgent.d.ts.map +1 -1
- package/dist/agents/FlowAgent.js +16 -6
- package/dist/agents/FlowAgent.js.map +1 -1
- package/dist/agents/TriageAgent.d.ts +8 -2
- package/dist/agents/TriageAgent.d.ts.map +1 -1
- package/dist/agents/TriageAgent.js +39 -6
- package/dist/agents/TriageAgent.js.map +1 -1
- package/dist/agents/index.d.ts +1 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +0 -1
- package/dist/agents/index.js.map +1 -1
- package/dist/flows/FlowManager.d.ts +8 -0
- package/dist/flows/FlowManager.d.ts.map +1 -1
- package/dist/flows/FlowManager.js +38 -4
- package/dist/flows/FlowManager.js.map +1 -1
- package/dist/flows/template.d.ts +2 -2
- package/dist/flows/template.d.ts.map +1 -1
- package/dist/flows/template.js +13 -0
- package/dist/flows/template.js.map +1 -1
- package/dist/foundation/AgentDefinition.d.ts +18 -0
- package/dist/foundation/AgentDefinition.d.ts.map +1 -0
- package/dist/foundation/AgentDefinition.js +2 -0
- package/dist/foundation/AgentDefinition.js.map +1 -0
- package/dist/foundation/AgentStateController.d.ts +26 -0
- package/dist/foundation/AgentStateController.d.ts.map +1 -0
- package/dist/foundation/AgentStateController.js +2 -0
- package/dist/foundation/AgentStateController.js.map +1 -0
- package/dist/foundation/ConversationEventLog.d.ts +72 -0
- package/dist/foundation/ConversationEventLog.d.ts.map +1 -0
- package/dist/foundation/ConversationEventLog.js +2 -0
- package/dist/foundation/ConversationEventLog.js.map +1 -0
- package/dist/foundation/ConversationState.d.ts +31 -0
- package/dist/foundation/ConversationState.d.ts.map +1 -0
- package/dist/foundation/ConversationState.js +2 -0
- package/dist/foundation/ConversationState.js.map +1 -0
- package/dist/foundation/DefaultAgentStateController.d.ts +24 -0
- package/dist/foundation/DefaultAgentStateController.d.ts.map +1 -0
- package/dist/foundation/DefaultAgentStateController.js +49 -0
- package/dist/foundation/DefaultAgentStateController.js.map +1 -0
- package/dist/foundation/DefaultConversationEventLog.d.ts +28 -0
- package/dist/foundation/DefaultConversationEventLog.d.ts.map +1 -0
- package/dist/foundation/DefaultConversationEventLog.js +195 -0
- package/dist/foundation/DefaultConversationEventLog.js.map +1 -0
- package/dist/foundation/DefaultConversationState.d.ts +34 -0
- package/dist/foundation/DefaultConversationState.d.ts.map +1 -0
- package/dist/foundation/DefaultConversationState.js +100 -0
- package/dist/foundation/DefaultConversationState.js.map +1 -0
- package/dist/foundation/DefaultToolExecutor.d.ts +58 -0
- package/dist/foundation/DefaultToolExecutor.d.ts.map +1 -0
- package/dist/foundation/DefaultToolExecutor.js +128 -0
- package/dist/foundation/DefaultToolExecutor.js.map +1 -0
- package/dist/foundation/ToolExecutor.d.ts +44 -0
- package/dist/foundation/ToolExecutor.d.ts.map +1 -0
- package/dist/foundation/ToolExecutor.js +2 -0
- package/dist/foundation/ToolExecutor.js.map +1 -0
- package/dist/foundation/createFoundation.d.ts +33 -0
- package/dist/foundation/createFoundation.d.ts.map +1 -0
- package/dist/foundation/createFoundation.js +34 -0
- package/dist/foundation/createFoundation.js.map +1 -0
- package/dist/foundation/index.d.ts +15 -0
- package/dist/foundation/index.d.ts.map +1 -0
- package/dist/foundation/index.js +8 -0
- package/dist/foundation/index.js.map +1 -0
- package/dist/hooks/HookRunner.d.ts +2 -0
- package/dist/hooks/HookRunner.d.ts.map +1 -1
- package/dist/hooks/HookRunner.js +4 -0
- package/dist/hooks/HookRunner.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/memory/MemoryService.d.ts +40 -0
- package/dist/memory/MemoryService.d.ts.map +1 -0
- package/dist/memory/MemoryService.js +2 -0
- package/dist/memory/MemoryService.js.map +1 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +3 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/preloadMemory.d.ts +17 -0
- package/dist/memory/preloadMemory.d.ts.map +1 -0
- package/dist/memory/preloadMemory.js +62 -0
- package/dist/memory/preloadMemory.js.map +1 -0
- package/dist/memory/stores/InMemoryMemoryService.d.ts +20 -0
- package/dist/memory/stores/InMemoryMemoryService.d.ts.map +1 -0
- package/dist/memory/stores/InMemoryMemoryService.js +92 -0
- package/dist/memory/stores/InMemoryMemoryService.js.map +1 -0
- package/dist/memory/types.d.ts +49 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +8 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/prompts/AgentPrompt.d.ts +110 -0
- package/dist/prompts/AgentPrompt.d.ts.map +1 -0
- package/dist/prompts/AgentPrompt.js +373 -0
- package/dist/prompts/AgentPrompt.js.map +1 -0
- package/dist/prompts/PromptAssembly.d.ts +119 -0
- package/dist/prompts/PromptAssembly.d.ts.map +1 -0
- package/dist/prompts/PromptAssembly.js +150 -0
- package/dist/prompts/PromptAssembly.js.map +1 -0
- package/dist/prompts/PromptBuilder.d.ts +22 -3
- package/dist/prompts/PromptBuilder.d.ts.map +1 -1
- package/dist/prompts/PromptBuilder.js +242 -13
- package/dist/prompts/PromptBuilder.js.map +1 -1
- package/dist/prompts/PromptRenderer.d.ts +43 -0
- package/dist/prompts/PromptRenderer.d.ts.map +1 -0
- package/dist/prompts/PromptRenderer.js +114 -0
- package/dist/prompts/PromptRenderer.js.map +1 -0
- package/dist/prompts/brandVoice.d.ts +10 -0
- package/dist/prompts/brandVoice.d.ts.map +1 -0
- package/dist/prompts/brandVoice.js +87 -0
- package/dist/prompts/brandVoice.js.map +1 -0
- package/dist/prompts/index.d.ts +11 -4
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +7 -2
- package/dist/prompts/index.js.map +1 -1
- package/dist/prompts/security.d.ts +5 -0
- package/dist/prompts/security.d.ts.map +1 -0
- package/dist/prompts/security.js +52 -0
- package/dist/prompts/security.js.map +1 -0
- package/dist/prompts/types.d.ts +65 -1
- package/dist/prompts/types.d.ts.map +1 -1
- package/dist/prompts/types.js +26 -0
- package/dist/prompts/types.js.map +1 -1
- package/dist/runtime/ContextBudget.d.ts +57 -0
- package/dist/runtime/ContextBudget.d.ts.map +1 -0
- package/dist/runtime/ContextBudget.js +103 -0
- package/dist/runtime/ContextBudget.js.map +1 -0
- package/dist/runtime/ContextManager.d.ts +8 -5
- package/dist/runtime/ContextManager.d.ts.map +1 -1
- package/dist/runtime/ContextManager.js +47 -14
- package/dist/runtime/ContextManager.js.map +1 -1
- package/dist/runtime/FlowExecutor.d.ts +16 -11
- package/dist/runtime/FlowExecutor.d.ts.map +1 -1
- package/dist/runtime/FlowExecutor.js +32 -138
- package/dist/runtime/FlowExecutor.js.map +1 -1
- package/dist/runtime/Runtime.d.ts +31 -78
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +225 -1406
- package/dist/runtime/Runtime.js.map +1 -1
- package/dist/runtime/SessionCache.d.ts +16 -0
- package/dist/runtime/SessionCache.d.ts.map +1 -0
- package/dist/runtime/SessionCache.js +49 -0
- package/dist/runtime/SessionCache.js.map +1 -0
- package/dist/runtime/SessionMutex.d.ts +37 -0
- package/dist/runtime/SessionMutex.d.ts.map +1 -0
- package/dist/runtime/SessionMutex.js +59 -0
- package/dist/runtime/SessionMutex.js.map +1 -0
- package/dist/runtime/StreamEmitter.d.ts +34 -0
- package/dist/runtime/StreamEmitter.d.ts.map +1 -0
- package/dist/runtime/StreamEmitter.js +91 -0
- package/dist/runtime/StreamEmitter.js.map +1 -0
- package/dist/runtime/handoffFilters.d.ts +60 -0
- package/dist/runtime/handoffFilters.d.ts.map +1 -0
- package/dist/runtime/handoffFilters.js +95 -0
- package/dist/runtime/handoffFilters.js.map +1 -0
- package/dist/runtime/pipeline/AgentExecuteStage.d.ts +22 -0
- package/dist/runtime/pipeline/AgentExecuteStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/AgentExecuteStage.js +889 -0
- package/dist/runtime/pipeline/AgentExecuteStage.js.map +1 -0
- package/dist/runtime/pipeline/ContextAssembleStage.d.ts +26 -0
- package/dist/runtime/pipeline/ContextAssembleStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/ContextAssembleStage.js +253 -0
- package/dist/runtime/pipeline/ContextAssembleStage.js.map +1 -0
- package/dist/runtime/pipeline/ContextGatherStage.d.ts +21 -0
- package/dist/runtime/pipeline/ContextGatherStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/ContextGatherStage.js +161 -0
- package/dist/runtime/pipeline/ContextGatherStage.js.map +1 -0
- package/dist/runtime/pipeline/IntakeStage.d.ts +25 -0
- package/dist/runtime/pipeline/IntakeStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/IntakeStage.js +126 -0
- package/dist/runtime/pipeline/IntakeStage.js.map +1 -0
- package/dist/runtime/pipeline/PostStreamStage.d.ts +26 -0
- package/dist/runtime/pipeline/PostStreamStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/PostStreamStage.js +129 -0
- package/dist/runtime/pipeline/PostStreamStage.js.map +1 -0
- package/dist/runtime/pipeline/TurnPipeline.d.ts +54 -0
- package/dist/runtime/pipeline/TurnPipeline.d.ts.map +1 -0
- package/dist/runtime/pipeline/TurnPipeline.js +15 -0
- package/dist/runtime/pipeline/TurnPipeline.js.map +1 -0
- package/dist/runtime/pipeline/TurnServices.d.ts +48 -0
- package/dist/runtime/pipeline/TurnServices.d.ts.map +1 -0
- package/dist/runtime/pipeline/TurnServices.js +2 -0
- package/dist/runtime/pipeline/TurnServices.js.map +1 -0
- package/dist/runtime/pipeline/agentTypeGuards.d.ts +4 -0
- package/dist/runtime/pipeline/agentTypeGuards.d.ts.map +1 -0
- package/dist/runtime/pipeline/agentTypeGuards.js +7 -0
- package/dist/runtime/pipeline/agentTypeGuards.js.map +1 -0
- package/dist/runtime/pipeline/index.d.ts +11 -0
- package/dist/runtime/pipeline/index.d.ts.map +1 -0
- package/dist/runtime/pipeline/index.js +13 -0
- package/dist/runtime/pipeline/index.js.map +1 -0
- package/dist/runtime/pipeline/outputProcessing.d.ts +23 -0
- package/dist/runtime/pipeline/outputProcessing.d.ts.map +1 -0
- package/dist/runtime/pipeline/outputProcessing.js +63 -0
- package/dist/runtime/pipeline/outputProcessing.js.map +1 -0
- package/dist/runtime/pipeline/sessionUtils.d.ts +12 -0
- package/dist/runtime/pipeline/sessionUtils.d.ts.map +1 -0
- package/dist/runtime/pipeline/sessionUtils.js +73 -0
- package/dist/runtime/pipeline/sessionUtils.js.map +1 -0
- package/dist/tools/Tool.d.ts +7 -0
- package/dist/tools/Tool.d.ts.map +1 -1
- package/dist/tools/Tool.js +12 -3
- package/dist/tools/Tool.js.map +1 -1
- package/dist/tools/memory.d.ts +26 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +51 -0
- package/dist/tools/memory.js.map +1 -0
- package/dist/types/index.d.ts +177 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/guides/AGENTS.md +173 -0
- package/guides/README.md +12 -0
- package/guides/TOOLS.md +93 -27
- package/package.json +12 -4
- package/dist/agents/LLMAgent.d.ts +0 -11
- package/dist/agents/LLMAgent.d.ts.map +0 -1
- package/dist/agents/LLMAgent.js +0 -31
- package/dist/agents/LLMAgent.js.map +0 -1
package/guides/AGENTS.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Agents Guide
|
|
2
|
+
|
|
3
|
+
Agent primitives in AriaFlow: LLMAgent, FlowAgent, TriageAgent, CompositeAgent.
|
|
4
|
+
|
|
5
|
+
## Agent Types
|
|
6
|
+
|
|
7
|
+
### LLMAgent
|
|
8
|
+
Standard LLM-based agent with tools and system prompt. Good for free-form conversation.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
const agent: LLMAgentConfig = {
|
|
12
|
+
id: 'my-agent',
|
|
13
|
+
type: 'llm',
|
|
14
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
15
|
+
model: openai('gpt-4o'),
|
|
16
|
+
tools: { myTool },
|
|
17
|
+
};
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### FlowAgent
|
|
21
|
+
Node-based agent with defined flow graph and state management. Good for structured, multi-step processes.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const agent: FlowAgentConfig = {
|
|
25
|
+
id: 'my-flow',
|
|
26
|
+
type: 'flow',
|
|
27
|
+
flow: {
|
|
28
|
+
nodes: [
|
|
29
|
+
{ id: 'start', prompt: '...' },
|
|
30
|
+
{ id: 'collect_info', prompt: '...' },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
initialNode: 'start',
|
|
34
|
+
model: openai('gpt-4o'),
|
|
35
|
+
tools: { myTool },
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### TriageAgent
|
|
40
|
+
Routes user input to appropriate agent based on conditions or LLM classification.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const agent: TriageAgentConfig = {
|
|
44
|
+
id: 'triage',
|
|
45
|
+
type: 'triage',
|
|
46
|
+
routes: [
|
|
47
|
+
{ agentId: 'sales', condition: 'sales-related' },
|
|
48
|
+
{ agentId: 'support', condition: 'support-related' },
|
|
49
|
+
],
|
|
50
|
+
model: openai('gpt-4o'),
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### CompositeAgent
|
|
55
|
+
Orchestrates multiple agents in sequence or parallel with coordination logic.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const agent: CompositeAgentConfig = {
|
|
59
|
+
id: 'composite',
|
|
60
|
+
type: 'composite',
|
|
61
|
+
agents: ['agent1', 'agent2', 'agent3'],
|
|
62
|
+
orchestration: 'sequential', // or 'parallel'
|
|
63
|
+
model: openai('gpt-4o'),
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Agent-to-Agent Consultation
|
|
68
|
+
|
|
69
|
+
Use `runtime.runAgent()` to have one agent consult another directly, enabling **team collaboration**.
|
|
70
|
+
|
|
71
|
+
### Pattern
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
// Specialist agents
|
|
75
|
+
const weatherAgent = {
|
|
76
|
+
id: 'weather',
|
|
77
|
+
type: 'llm',
|
|
78
|
+
systemPrompt: 'You are a weather expert.',
|
|
79
|
+
model,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const newsAgent = {
|
|
83
|
+
id: 'news',
|
|
84
|
+
type: 'llm',
|
|
85
|
+
systemPrompt: 'You are a news expert.',
|
|
86
|
+
model,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Lead agent with consultation tools
|
|
90
|
+
const leadAgent = {
|
|
91
|
+
id: 'lead',
|
|
92
|
+
type: 'llm',
|
|
93
|
+
systemPrompt: 'You have access to weather and news specialists.',
|
|
94
|
+
model,
|
|
95
|
+
tools: {
|
|
96
|
+
consult_weather: createTool({
|
|
97
|
+
description: 'Consult Weather Specialist',
|
|
98
|
+
inputSchema: z.object({ query: z.string() }),
|
|
99
|
+
execute: async (input, options?: ToolExecutionOptions) => {
|
|
100
|
+
const { runtime } = options.experimental_context;
|
|
101
|
+
if (!runtime) throw new Error('Runtime required in tool context');
|
|
102
|
+
|
|
103
|
+
let result = '';
|
|
104
|
+
for await (const part of runtime.runAgent('weather', input, options.sessionId)) {
|
|
105
|
+
if (part.type === 'text-delta') result += part.text;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return result;
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Runtime orchestrates everything
|
|
115
|
+
const runtime = new Runtime({
|
|
116
|
+
agents: [leadAgent, weatherAgent, newsAgent],
|
|
117
|
+
defaultModel: model,
|
|
118
|
+
ctaConfig: { enabled: false }, // Disable CTA for direct agent control
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### How It Works
|
|
123
|
+
|
|
124
|
+
1. **User talks to**: Lead agent
|
|
125
|
+
2. **Lead calls**: `consult_weather` tool
|
|
126
|
+
3. **Tool receives**: `runtime` via `experimental_context.runtime`
|
|
127
|
+
4. **Tool executes**: `runtime.runAgent('weather', query, sessionId)`
|
|
128
|
+
5. **Specialist responds**: Weather agent processes request
|
|
129
|
+
6. **Result returned**: Tool result passed back to lead agent
|
|
130
|
+
7. **Lead synthesizes**: Combines into ONE unified response
|
|
131
|
+
|
|
132
|
+
### Benefits
|
|
133
|
+
|
|
134
|
+
- ✅ **No wrappers** - Tools get runtime directly from context
|
|
135
|
+
- ✅ **Type-safe** - Uses proper types (no `as any`)
|
|
136
|
+
- ✅ **Session sharing** - Automatic sessionId injection
|
|
137
|
+
- ✅ **Team model** - Lead orchestrates specialists as one team
|
|
138
|
+
- ✅ **Single response** - Customer sees unified answer, not multiple agents
|
|
139
|
+
|
|
140
|
+
### When to Use
|
|
141
|
+
|
|
142
|
+
- **Team collaboration** (specialist pattern): One lead agent + multiple specialists
|
|
143
|
+
- **Direct agent control**: Use `runtime.runAgent()` to run specific agents
|
|
144
|
+
- **Bypass CTA**: Pass `agentId` to skip triage routing
|
|
145
|
+
|
|
146
|
+
### Example
|
|
147
|
+
|
|
148
|
+
See [Agent Consultation Example](../../examples/agents/agent-consultation.ts) for a full working demo.
|
|
149
|
+
|
|
150
|
+
## Key Types
|
|
151
|
+
|
|
152
|
+
- `ToolExecutionOptions` - Tool execution options including `experimental_context`
|
|
153
|
+
- `ToolExecutionContext` - Context passed to tools (includes `runtime`)
|
|
154
|
+
- `ToolExecutionContextWithRuntime` - Extended context with `runtime` field
|
|
155
|
+
- `Runtime.runAgent()` - Direct method to run specific agent
|
|
156
|
+
|
|
157
|
+
## Best Practices
|
|
158
|
+
|
|
159
|
+
1. **Always check runtime existence**: `if (!context?.runtime) throw new Error(...)`
|
|
160
|
+
2. **Use sessionId from options**: `options.sessionId` for consultation continuity
|
|
161
|
+
3. **Type-safe access**: Use helper functions like `getRuntimeFromContext()`
|
|
162
|
+
4. **Consultation tools should be lightweight**: Return string results, not complex objects
|
|
163
|
+
5. **Lead agent combines results**: The orchestrator agent synthesizes specialist responses
|
|
164
|
+
|
|
165
|
+
## Comparison to Other Patterns
|
|
166
|
+
|
|
167
|
+
| Pattern | Description | CTA | Handoffs | Wrapper Functions |
|
|
168
|
+
|---------|-------------|-----|-----------|------------------|
|
|
169
|
+
| Agent Consultation | Tool calls runtime.runAgent() directly | Skip CTA | No handoffs | Direct runtime access |
|
|
170
|
+
| Traditional Handoff | TriageAgent routes to agent | CTA | Handoffs | No runtime access to tools | N/A |
|
|
171
|
+
| Wrapper Function | Custom function wraps runtime.runAgent() | May not use CTA | N/A | N/A | Boilerplate code |
|
|
172
|
+
|
|
173
|
+
**Agent Consultation is the cleanest approach** - no wrappers, no handoffs, type-safe runtime access.
|
package/guides/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Practical guides for the AriaFlow core runtime and agent primitives.
|
|
|
9
9
|
- **[Flows](./FLOWS.md)** - Flow agents and structured conversations
|
|
10
10
|
- **[Tools](./TOOLS.md)** - Tool design, execution, and AI SDK integration
|
|
11
11
|
- **[Guardrails](./GUARDRAILS.md)** - Stop conditions, enforcement rules, processors, redaction
|
|
12
|
+
- **[Agents](./AGENTS.md)** - Agent types, consultation patterns, and team collaboration
|
|
12
13
|
- **[Example Verification](./EXAMPLE_VERIFICATION.md)** - Latest example sweep results and known prerequisites
|
|
13
14
|
|
|
14
15
|
## Examples
|
|
@@ -16,3 +17,14 @@ Practical guides for the AriaFlow core runtime and agent primitives.
|
|
|
16
17
|
- `examples/` for runnable demos
|
|
17
18
|
- `examples/flows/` for Pipecat flow parity examples
|
|
18
19
|
- `examples/agents/` for Line example parity agents and integrations
|
|
20
|
+
|
|
21
|
+
### New in This Version
|
|
22
|
+
|
|
23
|
+
**Agent-to-Agent Consultation** (see AGENTS.md): Enables team collaboration where a lead agent can consult specialist agents directly using `runtime.runAgent()`. This pattern supports:
|
|
24
|
+
|
|
25
|
+
- Lead agent orchestration
|
|
26
|
+
- Direct specialist consultation
|
|
27
|
+
- Type-safe runtime access
|
|
28
|
+
- Single unified customer response
|
|
29
|
+
|
|
30
|
+
See [agent-consultation](../examples/agents/agent-consultation.ts) for a complete example.
|
package/guides/TOOLS.md
CHANGED
|
@@ -32,41 +32,107 @@ const lookup = createToolWithFiller({
|
|
|
32
32
|
});
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## Agent-to-Agent Consultation
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
- `toolCallId`
|
|
39
|
-
- `messages`
|
|
40
|
-
- `abortSignal`
|
|
41
|
-
- `experimental_context`
|
|
37
|
+
Use `runtime.runAgent()` to have one agent consult another directly, without CTA routing or wrapper functions.
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
- `
|
|
39
|
+
### Why This Matters
|
|
40
|
+
|
|
41
|
+
- **Team Model**: Lead agent orchestrates, specialists provide domain expertise
|
|
42
|
+
- **Single Response**: Customer sees ONE unified answer from lead agent
|
|
43
|
+
- **Type-Safe**: No `as any` casts needed - uses proper types
|
|
44
|
+
- **Automatic Context**: Session ID injected via `experimental_context`
|
|
45
|
+
|
|
46
|
+
### Basic Example
|
|
48
47
|
|
|
49
48
|
```ts
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
// Define specialist agents
|
|
50
|
+
const weatherAgent = {
|
|
51
|
+
id: 'weather',
|
|
52
|
+
name: 'Weather Specialist',
|
|
53
|
+
type: 'llm' as const,
|
|
54
|
+
systemPrompt: 'You are a weather expert.',
|
|
55
|
+
model,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const newsAgent = {
|
|
59
|
+
id: 'news',
|
|
60
|
+
name: 'News Specialist',
|
|
61
|
+
type: 'llm' as const,
|
|
62
|
+
systemPrompt: 'You are a news expert.',
|
|
63
|
+
model,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Create lead agent with consultation tools
|
|
67
|
+
const leadAgent = {
|
|
68
|
+
id: 'lead',
|
|
69
|
+
name: 'Lead Agent',
|
|
70
|
+
type: 'llm' as const,
|
|
71
|
+
systemPrompt: 'You have access to weather and news specialists.',
|
|
72
|
+
model,
|
|
73
|
+
tools: {
|
|
74
|
+
consult_weather: createTool({
|
|
75
|
+
description: 'Consult Weather Specialist',
|
|
76
|
+
inputSchema: z.object({ query: z.string() }),
|
|
77
|
+
execute: async (input, options?: ToolExecutionOptions) => {
|
|
78
|
+
const { runtime } = options.experimental_context;
|
|
79
|
+
if (!runtime) throw new Error('Runtime required in tool context');
|
|
80
|
+
|
|
81
|
+
let result = '';
|
|
82
|
+
for await (const part of runtime.runAgent('weather', input, options.sessionId)) {
|
|
83
|
+
if (part.type === 'text-delta') result += part.text;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return result;
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Runtime handles orchestration
|
|
93
|
+
const runtime = new Runtime({
|
|
94
|
+
agents: [leadAgent, weatherAgent, newsAgent],
|
|
95
|
+
defaultModel: model,
|
|
96
|
+
ctaConfig: { enabled: false },
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Usage: Lead agent consults specialists
|
|
100
|
+
const response = await runtime.stream({ input: 'What is the weather today?' });
|
|
101
|
+
// Internally: consult_weather tool calls runtime.runAgent('weather', query)
|
|
102
|
+
// Weather agent responds, result returned to lead
|
|
103
|
+
// Lead combines into: "The weather is sunny, 72°F."
|
|
56
104
|
```
|
|
57
105
|
|
|
58
|
-
|
|
106
|
+
### How It Works
|
|
59
107
|
|
|
60
|
-
|
|
108
|
+
1. **User asks**: Lead agent
|
|
109
|
+
2. **Tool executes**: `consult_weather` tool
|
|
110
|
+
3. **Runtime available**: Tool receives `runtime` via `experimental_context.runtime`
|
|
111
|
+
4. **Direct consultation**: Tool calls `runtime.runAgent('weather', input, sessionId)`
|
|
112
|
+
5. **Session preserved**: Same session ID flows through consultation
|
|
113
|
+
6. **Specialist responds**: Weather agent processes request
|
|
114
|
+
7. **Result returned**: Tool result passed back to lead agent
|
|
115
|
+
8. **Unified answer**: Lead agent synthesizes and delivers ONE response
|
|
61
116
|
|
|
62
|
-
|
|
63
|
-
import { createFlowTransition } from '@ariaflowagents/core';
|
|
117
|
+
### Key Features
|
|
64
118
|
|
|
65
|
-
|
|
66
|
-
|
|
119
|
+
- ✅ **No wrapper functions** - Tools get runtime directly from context
|
|
120
|
+
- ✅ **Type-safe** - Uses `ToolExecutionOptions` and `ToolExecutionContext`
|
|
121
|
+
- ✅ **Session sharing** - Automatic sessionId injection
|
|
122
|
+
- ✅ **Clean consultation** - Direct agent-to-agent execution path
|
|
123
|
+
- ✅ **Team collaboration** - Multiple agents can work together
|
|
124
|
+
|
|
125
|
+
### When to Use
|
|
126
|
+
|
|
127
|
+
- When you need **one agent to consult another** (specialist pattern)
|
|
128
|
+
- When you want **team collaboration** (lead agent + specialists)
|
|
129
|
+
- When you need **direct agent control** (skip CTA entirely)
|
|
130
|
+
|
|
131
|
+
### When NOT to Use
|
|
132
|
+
|
|
133
|
+
- Simple tool-to-API calls (use `createTool()` directly)
|
|
134
|
+
- Handoffs/CTA (use handoffs for routing instead)
|
|
135
|
+
- Wrapper functions around tools
|
|
67
136
|
|
|
68
|
-
|
|
137
|
+
See [Agent Consultation Example](../../examples/agents/agent-consultation.ts) for a full working demo.
|
|
69
138
|
|
|
70
|
-
- Treat tool args/results as sensitive.
|
|
71
|
-
- Avoid returning secrets in tool results.
|
|
72
|
-
- If you forward tool events to a UI or webhook, filter them first.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ariaflowagents/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "A framework for structured conversational AI agents",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -53,6 +53,14 @@
|
|
|
53
53
|
"./types": {
|
|
54
54
|
"types": "./dist/types/index.d.ts",
|
|
55
55
|
"default": "./dist/types/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./memory": {
|
|
58
|
+
"types": "./dist/memory/index.d.ts",
|
|
59
|
+
"default": "./dist/memory/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./foundation": {
|
|
62
|
+
"types": "./dist/foundation/index.d.ts",
|
|
63
|
+
"default": "./dist/foundation/index.js"
|
|
56
64
|
}
|
|
57
65
|
},
|
|
58
66
|
"peerDependencies": {
|
|
@@ -63,7 +71,6 @@
|
|
|
63
71
|
"@ai-sdk/openai": "^3.0.0",
|
|
64
72
|
"@types/node": "^20.11.0",
|
|
65
73
|
"ai": "^6.0.0",
|
|
66
|
-
"chrono-node": "^2.6.0",
|
|
67
74
|
"dotenv": "^16.4.0",
|
|
68
75
|
"tsx": "^4.7.0",
|
|
69
76
|
"typescript": "^5.3.0",
|
|
@@ -73,9 +80,10 @@
|
|
|
73
80
|
"build": "tsc -p tsconfig.json",
|
|
74
81
|
"clean": "rm -rf dist",
|
|
75
82
|
"prepublishOnly": "npm run clean && npm run build",
|
|
76
|
-
"test": "npm run build && node --test test/*.test.js"
|
|
83
|
+
"test": "npm run build && node --test test/*.test.js test/**/*.test.js"
|
|
77
84
|
},
|
|
78
85
|
"dependencies": {
|
|
79
|
-
"@ariaflowagents/config": "^0.
|
|
86
|
+
"@ariaflowagents/config": "^0.8.0",
|
|
87
|
+
"chrono-node": "^2.6.0"
|
|
80
88
|
}
|
|
81
89
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type ToolSet } from 'ai';
|
|
2
|
-
import { Agent } from './Agent.js';
|
|
3
|
-
import type { AgentContext, AgentStreamPart, LLMAgentConfig } from '../types/index.js';
|
|
4
|
-
export declare class LLMAgent extends Agent<LLMAgentConfig> {
|
|
5
|
-
private model;
|
|
6
|
-
private tools;
|
|
7
|
-
constructor(config: LLMAgentConfig);
|
|
8
|
-
process(_input: string, context: AgentContext): AsyncGenerator<AgentStreamPart>;
|
|
9
|
-
protected getToolsForContext(_context: AgentContext): ToolSet;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=LLMAgent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LLMAgent.d.ts","sourceRoot":"","sources":["../../src/agents/LLMAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,OAAO,EAAE,MAAM,IAAI,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAIvF,qBAAa,QAAS,SAAQ,KAAK,CAAC,cAAc,CAAC;IACjD,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,KAAK,CAAU;gBAEX,MAAM,EAAE,cAAc;IAS3B,OAAO,CACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,cAAc,CAAC,eAAe,CAAC;IAgBlC,SAAS,CAAC,kBAAkB,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO;CAG9D"}
|
package/dist/agents/LLMAgent.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { streamText } from 'ai';
|
|
2
|
-
import { Agent } from './Agent.js';
|
|
3
|
-
import { processAIStream } from '../utils/aiStream.js';
|
|
4
|
-
export class LLMAgent extends Agent {
|
|
5
|
-
model;
|
|
6
|
-
tools;
|
|
7
|
-
constructor(config) {
|
|
8
|
-
super(config);
|
|
9
|
-
if (!config.model) {
|
|
10
|
-
throw new Error(`LLMAgent "${config.id}" requires a model`);
|
|
11
|
-
}
|
|
12
|
-
this.model = config.model;
|
|
13
|
-
this.tools = config.tools ?? {};
|
|
14
|
-
}
|
|
15
|
-
async *process(_input, context) {
|
|
16
|
-
const systemPrompt = this.buildSystemPrompt(context);
|
|
17
|
-
const result = streamText({
|
|
18
|
-
model: this.model,
|
|
19
|
-
system: systemPrompt,
|
|
20
|
-
messages: context.messages,
|
|
21
|
-
tools: this.getToolsForContext(context),
|
|
22
|
-
abortSignal: context.abortSignal,
|
|
23
|
-
});
|
|
24
|
-
yield* processAIStream(result.fullStream);
|
|
25
|
-
yield { type: 'turn-end', metadata: { response: await result.response } };
|
|
26
|
-
}
|
|
27
|
-
getToolsForContext(_context) {
|
|
28
|
-
return this.tools;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=LLMAgent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LLMAgent.js","sourceRoot":"","sources":["../../src/agents/LLMAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAoC,MAAM,IAAI,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,OAAO,QAAS,SAAQ,KAAqB;IACzC,KAAK,CAAgB;IACrB,KAAK,CAAU;IAEvB,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,aAAa,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAC;QAC9D,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,CAAC,OAAO,CACZ,MAAc,EACd,OAAqB;QAErB,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAErD,MAAM,MAAM,GAAG,UAAU,CAAC;YACxB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,YAAY;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAe;YACjC,KAAK,EAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAS;YAChD,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC,CAAC;QAEH,KAAK,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAE1C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC5E,CAAC;IAES,kBAAkB,CAAC,QAAsB;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|