@ariaflowagents/core 0.7.1 → 0.9.0
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/capabilities/AutoRetrieveCapability.d.ts +30 -0
- package/dist/capabilities/AutoRetrieveCapability.d.ts.map +1 -0
- package/dist/capabilities/AutoRetrieveCapability.js +36 -0
- package/dist/capabilities/AutoRetrieveCapability.js.map +1 -0
- package/dist/capabilities/ExtractionCapability.d.ts +25 -0
- package/dist/capabilities/ExtractionCapability.d.ts.map +1 -0
- package/dist/capabilities/ExtractionCapability.js +74 -0
- package/dist/capabilities/ExtractionCapability.js.map +1 -0
- package/dist/capabilities/FlowCapability.d.ts +81 -0
- package/dist/capabilities/FlowCapability.d.ts.map +1 -0
- package/dist/capabilities/FlowCapability.js +482 -0
- package/dist/capabilities/FlowCapability.js.map +1 -0
- package/dist/capabilities/GuardrailCapability.d.ts +30 -0
- package/dist/capabilities/GuardrailCapability.d.ts.map +1 -0
- package/dist/capabilities/GuardrailCapability.js +38 -0
- package/dist/capabilities/GuardrailCapability.js.map +1 -0
- package/dist/capabilities/HandoffCapability.d.ts +19 -0
- package/dist/capabilities/HandoffCapability.d.ts.map +1 -0
- package/dist/capabilities/HandoffCapability.js +58 -0
- package/dist/capabilities/HandoffCapability.js.map +1 -0
- package/dist/capabilities/LivePromptAssembler.d.ts +108 -0
- package/dist/capabilities/LivePromptAssembler.d.ts.map +1 -0
- package/dist/capabilities/LivePromptAssembler.js +157 -0
- package/dist/capabilities/LivePromptAssembler.js.map +1 -0
- package/dist/capabilities/TriageCapability.d.ts +16 -0
- package/dist/capabilities/TriageCapability.d.ts.map +1 -0
- package/dist/capabilities/TriageCapability.js +61 -0
- package/dist/capabilities/TriageCapability.js.map +1 -0
- package/dist/capabilities/adapters/ai-sdk.d.ts +14 -0
- package/dist/capabilities/adapters/ai-sdk.d.ts.map +1 -0
- package/dist/capabilities/adapters/ai-sdk.js +29 -0
- package/dist/capabilities/adapters/ai-sdk.js.map +1 -0
- package/dist/capabilities/adapters/gemini.d.ts +15 -0
- package/dist/capabilities/adapters/gemini.d.ts.map +1 -0
- package/dist/capabilities/adapters/gemini.js +40 -0
- package/dist/capabilities/adapters/gemini.js.map +1 -0
- package/dist/capabilities/index.d.ts +154 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +128 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/eval/EvalRunner.d.ts +12 -0
- package/dist/eval/EvalRunner.d.ts.map +1 -0
- package/dist/eval/EvalRunner.js +64 -0
- package/dist/eval/EvalRunner.js.map +1 -0
- package/dist/eval/scoring.d.ts +15 -0
- package/dist/eval/scoring.d.ts.map +1 -0
- package/dist/eval/scoring.js +152 -0
- package/dist/eval/scoring.js.map +1 -0
- package/dist/eval/types.d.ts +59 -0
- package/dist/eval/types.d.ts.map +1 -0
- package/dist/eval/types.js +2 -0
- package/dist/eval/types.js.map +1 -0
- package/dist/flows/FlowGraph.d.ts +3 -1
- package/dist/flows/FlowGraph.d.ts.map +1 -1
- package/dist/flows/FlowGraph.js +5 -0
- package/dist/flows/FlowGraph.js.map +1 -1
- package/dist/flows/FlowManager.d.ts +68 -1
- package/dist/flows/FlowManager.d.ts.map +1 -1
- package/dist/flows/FlowManager.js +499 -36
- package/dist/flows/FlowManager.js.map +1 -1
- package/dist/flows/extraction.d.ts +16 -1
- package/dist/flows/extraction.d.ts.map +1 -1
- package/dist/flows/extraction.js +34 -0
- package/dist/flows/extraction.js.map +1 -1
- package/dist/flows/index.d.ts +2 -0
- package/dist/flows/index.d.ts.map +1 -1
- package/dist/flows/index.js +1 -0
- package/dist/flows/index.js.map +1 -1
- package/dist/flows/validation.d.ts +1 -1
- package/dist/flows/validation.d.ts.map +1 -1
- package/dist/flows/validation.js +13 -1
- package/dist/flows/validation.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 +5 -1
- package/dist/hooks/HookRunner.d.ts.map +1 -1
- package/dist/hooks/HookRunner.js +7 -0
- package/dist/hooks/HookRunner.js.map +1 -1
- package/dist/hooks/builtin/metrics.d.ts.map +1 -1
- package/dist/hooks/builtin/metrics.js +12 -0
- package/dist/hooks/builtin/metrics.js.map +1 -1
- package/dist/hooks/builtin/observability.d.ts +21 -0
- package/dist/hooks/builtin/observability.d.ts.map +1 -0
- package/dist/hooks/builtin/observability.js +535 -0
- package/dist/hooks/builtin/observability.js.map +1 -0
- package/dist/index.d.ts +24 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- 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/orchestration/DefaultOrchestrationAuthority.d.ts +91 -0
- package/dist/orchestration/DefaultOrchestrationAuthority.d.ts.map +1 -0
- package/dist/orchestration/DefaultOrchestrationAuthority.js +786 -0
- package/dist/orchestration/DefaultOrchestrationAuthority.js.map +1 -0
- package/dist/orchestration/OrchestrationAuthority.d.ts +119 -0
- package/dist/orchestration/OrchestrationAuthority.d.ts.map +1 -0
- package/dist/orchestration/OrchestrationAuthority.js +2 -0
- package/dist/orchestration/OrchestrationAuthority.js.map +1 -0
- package/dist/orchestration/RealtimeExtractionRunner.d.ts +25 -0
- package/dist/orchestration/RealtimeExtractionRunner.d.ts.map +1 -0
- package/dist/orchestration/RealtimeExtractionRunner.js +62 -0
- package/dist/orchestration/RealtimeExtractionRunner.js.map +1 -0
- package/dist/orchestration/index.d.ts +5 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +4 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/types.d.ts +134 -0
- package/dist/orchestration/types.d.ts.map +1 -0
- package/dist/orchestration/types.js +2 -0
- package/dist/orchestration/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/realtime/RealtimeAudioClient.d.ts +105 -0
- package/dist/realtime/RealtimeAudioClient.d.ts.map +1 -0
- package/dist/realtime/RealtimeAudioClient.js +15 -0
- package/dist/realtime/RealtimeAudioClient.js.map +1 -0
- package/dist/realtime/RealtimeRuntime.d.ts +136 -0
- package/dist/realtime/RealtimeRuntime.d.ts.map +1 -0
- package/dist/realtime/RealtimeRuntime.js +270 -0
- package/dist/realtime/RealtimeRuntime.js.map +1 -0
- package/dist/realtime/index.d.ts +4 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +2 -0
- package/dist/realtime/index.js.map +1 -0
- 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/ExtractionEngine.d.ts +2 -1
- package/dist/runtime/ExtractionEngine.d.ts.map +1 -1
- package/dist/runtime/ExtractionEngine.js +11 -0
- package/dist/runtime/ExtractionEngine.js.map +1 -1
- package/dist/runtime/FlowExecutor.d.ts +22 -15
- package/dist/runtime/FlowExecutor.d.ts.map +1 -1
- package/dist/runtime/FlowExecutor.js +102 -149
- package/dist/runtime/FlowExecutor.js.map +1 -1
- package/dist/runtime/Runtime.d.ts +53 -78
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +272 -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 +958 -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 +238 -9
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/telemetry.d.ts +107 -0
- package/dist/types/telemetry.d.ts.map +1 -1
- package/guides/AGENTS.md +173 -0
- package/guides/README.md +12 -0
- package/guides/TOOLS.md +93 -27
- package/package.json +25 -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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isHandoffResult } from '../tools/handoff.js';
|
|
3
|
+
// ─── HandoffCapability ───────────────────────────────────────────────────────
|
|
4
|
+
/**
|
|
5
|
+
* Exposes a single `transfer_to_agent` tool for agents that have explicit
|
|
6
|
+
* `canHandoffTo` targets. Unlike TriageCapability (one tool per route),
|
|
7
|
+
* this uses a single tool with an enum parameter for the target agent.
|
|
8
|
+
*/
|
|
9
|
+
export class HandoffCapability {
|
|
10
|
+
targets;
|
|
11
|
+
constructor(targets) {
|
|
12
|
+
this.targets = targets;
|
|
13
|
+
}
|
|
14
|
+
getTools() {
|
|
15
|
+
if (this.targets.length === 0)
|
|
16
|
+
return [];
|
|
17
|
+
const agentIds = this.targets.map(t => t.id);
|
|
18
|
+
const agentDescriptions = this.targets
|
|
19
|
+
.map(t => `- ${t.id} (${t.name})${t.description ? `: ${t.description}` : ''}`)
|
|
20
|
+
.join('\n');
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
name: 'transfer_to_agent',
|
|
24
|
+
description: `Transfer the conversation to a specialized agent.\n` +
|
|
25
|
+
`Do NOT mention this transfer to the user.\n\n` +
|
|
26
|
+
`Available agents:\n${agentDescriptions}`,
|
|
27
|
+
parameters: z.object({
|
|
28
|
+
targetAgentId: z.enum(agentIds).describe('The ID of the agent to transfer to'),
|
|
29
|
+
reason: z.string().describe('Why you are transferring — include relevant context'),
|
|
30
|
+
summary: z.string().optional().describe('Optional summary of what has been done so far'),
|
|
31
|
+
}),
|
|
32
|
+
execute: async (args) => ({
|
|
33
|
+
__handoff: true,
|
|
34
|
+
targetAgentId: args.targetAgentId,
|
|
35
|
+
targetAgent: args.targetAgentId,
|
|
36
|
+
reason: args.reason,
|
|
37
|
+
summary: args.summary,
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
getPromptSections() {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
processToolResult(toolName, args, result) {
|
|
46
|
+
// Match both 'transfer_to_agent' (capability name) and 'handoff' (legacy flow injection key)
|
|
47
|
+
if (toolName !== 'transfer_to_agent' && toolName !== 'handoff')
|
|
48
|
+
return null;
|
|
49
|
+
if (!isHandoffResult(result))
|
|
50
|
+
return null;
|
|
51
|
+
return {
|
|
52
|
+
type: 'handoff',
|
|
53
|
+
targetAgent: result.targetAgentId,
|
|
54
|
+
reason: result.reason,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=HandoffCapability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandoffCapability.js","sourceRoot":"","sources":["../../src/capabilities/HandoffCapability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAUtD,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IACpB,OAAO,CAAkB;IAEjC,YAAY,OAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,QAAQ;QACN,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QAEzC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAA0B,CAAC;QAEtE,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO;aACnC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;aAC7E,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,OAAO;YACL;gBACE,IAAI,EAAE,mBAAmB;gBACzB,WAAW,EACT,qDAAqD;oBACrD,+CAA+C;oBAC/C,sBAAsB,iBAAiB,EAAE;gBAC3C,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC;oBACnB,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,oCAAoC,CAAC;oBAC9E,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qDAAqD,CAAC;oBAClF,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;iBACzF,CAAC;gBACF,OAAO,EAAE,KAAK,EAAE,IAAiE,EAAE,EAAE,CAAC,CAAC;oBACrF,SAAS,EAAE,IAAa;oBACxB,aAAa,EAAE,IAAI,CAAC,aAAa;oBACjC,WAAW,EAAE,IAAI,CAAC,aAAa;oBAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC;aACH;SACF,CAAC;IACJ,CAAC;IAED,iBAAiB;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,iBAAiB,CAAC,QAAgB,EAAE,IAAa,EAAE,MAAe;QAChE,6FAA6F;QAC7F,IAAI,QAAQ,KAAK,mBAAmB,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QAC5E,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAC;QAE1C,OAAO;YACL,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,MAAM,CAAC,aAAa;YACjC,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LivePromptAssembler — Port for building system prompts optimized for
|
|
3
|
+
* realtime audio models (Gemini Live, OpenAI Realtime, etc.).
|
|
4
|
+
*
|
|
5
|
+
* This is the PORT (interface) in the Ports & Adapters pattern.
|
|
6
|
+
* The default implementation (`DefaultLivePromptAssembler`) bridges
|
|
7
|
+
* CapabilityHost with Runtime context (working memory, long-term memory,
|
|
8
|
+
* policy injections) and structures the output per audio-model best practices.
|
|
9
|
+
*
|
|
10
|
+
* Adapters (Gemini, OpenAI Realtime, LiveKit) can extend or replace
|
|
11
|
+
* the default with backend-specific voice rules and guardrails.
|
|
12
|
+
*
|
|
13
|
+
* Prompt structure follows Google's Live API best practices and
|
|
14
|
+
* OpenAI's Realtime Prompting Guide:
|
|
15
|
+
*
|
|
16
|
+
* 1. Persona — WHO you are
|
|
17
|
+
* 2. Voice Rules — Audio-specific constraints
|
|
18
|
+
* 3. Conversation Flow — Current task + collected state
|
|
19
|
+
* 4. Tool Directives — WHEN to call each tool
|
|
20
|
+
* 5. Context — Working memory + long-term memory
|
|
21
|
+
* 6. Guardrails — Safety, escalation, unclear audio
|
|
22
|
+
*
|
|
23
|
+
* @see https://ai.google.dev/gemini-api/docs/live-api/best-practices
|
|
24
|
+
* @see https://developers.openai.com/cookbook/examples/realtime_prompting_guide
|
|
25
|
+
*/
|
|
26
|
+
import type { Session } from '../types/index.js';
|
|
27
|
+
import type { CapabilityHost, ToolDeclaration } from './index.js';
|
|
28
|
+
import type { MemoryService } from '../memory/MemoryService.js';
|
|
29
|
+
import { type ContextBudgetConfig } from '../runtime/ContextBudget.js';
|
|
30
|
+
/**
|
|
31
|
+
* Input context for prompt assembly. Passed on every connect/reconfigure.
|
|
32
|
+
*/
|
|
33
|
+
export interface LivePromptContext {
|
|
34
|
+
/** The CapabilityHost providing tools and prompt sections. */
|
|
35
|
+
host: CapabilityHost;
|
|
36
|
+
/** Base agent prompt (persona, role, core instructions). */
|
|
37
|
+
basePrompt: string;
|
|
38
|
+
/** Current session — used for working memory injection. */
|
|
39
|
+
session?: Session;
|
|
40
|
+
/** Cross-session memory service for long-term context. */
|
|
41
|
+
memoryService?: MemoryService;
|
|
42
|
+
/** Latest user input — used as search query for memory retrieval. */
|
|
43
|
+
lastUserInput?: string;
|
|
44
|
+
/** Policy injection strings (from InjectionQueue.getFor('system')). */
|
|
45
|
+
policyInjections?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* PORT: Assembles system prompts for realtime audio LLM sessions.
|
|
49
|
+
*
|
|
50
|
+
* Implementations control voice rules, guardrails, tool directive formatting,
|
|
51
|
+
* and section ordering. The CapabilityCallWorker calls this on every connect
|
|
52
|
+
* and reconfigure, passing the current CapabilityHost state and session context.
|
|
53
|
+
*/
|
|
54
|
+
export interface LivePromptAssembler {
|
|
55
|
+
/**
|
|
56
|
+
* Build a complete system prompt string from the given context.
|
|
57
|
+
* May be async to support memory preloading.
|
|
58
|
+
*/
|
|
59
|
+
assemble(ctx: LivePromptContext): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Synchronous variant for initial connect (before any user input).
|
|
62
|
+
* Skips async memory preloading.
|
|
63
|
+
*/
|
|
64
|
+
assembleSync(ctx: Omit<LivePromptContext, 'memoryService' | 'lastUserInput'>): string;
|
|
65
|
+
}
|
|
66
|
+
export declare const DEFAULT_VOICE_RULES = "## Voice Rules\n- Keep responses to 2-3 sentences per turn. Be concise.\n- Do NOT output markdown, bullet points, numbered lists, or any formatting.\n- Do NOT include sound effects, onomatopoeia, or non-speech sounds.\n- Speak numbers digit-by-digit when reading codes or IDs: \"4-1-5\" not \"four fifteen\".\n- If user audio is unclear, ask for clarification. Do not guess.\n- Do NOT repeat back what the user just said. Move the conversation forward.\n- Vary your responses. Do not use the same opening or confirmation phrase twice in a row.";
|
|
67
|
+
export declare const DEFAULT_GUARDRAILS = "## Guardrails\n- Only respond to clear audio or text input.\n- If you cannot help with a request, say so briefly and offer to help with something else.\n- All claims must be grounded in provided context or tool results. Do not fabricate information.\n- If unsure about any action, ask for clarification rather than guessing.";
|
|
68
|
+
export interface DefaultLivePromptAssemblerConfig {
|
|
69
|
+
/** Custom voice rules to override DEFAULT_VOICE_RULES. */
|
|
70
|
+
voiceRules?: string;
|
|
71
|
+
/** Custom guardrails to override DEFAULT_GUARDRAILS. */
|
|
72
|
+
guardrails?: string;
|
|
73
|
+
/** Working memory allowlist — only these keys are injected. */
|
|
74
|
+
promptMemoryAllowlist?: string[];
|
|
75
|
+
/** Token budget overrides. */
|
|
76
|
+
budget?: Partial<ContextBudgetConfig>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Default LivePromptAssembler implementation.
|
|
80
|
+
*
|
|
81
|
+
* Backend-agnostic — produces a plain string suitable for any realtime
|
|
82
|
+
* audio model. Adapters can extend this class to add backend-specific
|
|
83
|
+
* sections or override the voice rules.
|
|
84
|
+
*/
|
|
85
|
+
export declare class DefaultLivePromptAssembler implements LivePromptAssembler {
|
|
86
|
+
private voiceRules;
|
|
87
|
+
private guardrails;
|
|
88
|
+
private allowlist?;
|
|
89
|
+
private budget;
|
|
90
|
+
constructor(config?: DefaultLivePromptAssemblerConfig);
|
|
91
|
+
assemble(ctx: LivePromptContext): Promise<string>;
|
|
92
|
+
assembleSync(ctx: Omit<LivePromptContext, 'memoryService' | 'lastUserInput'>): string;
|
|
93
|
+
/**
|
|
94
|
+
* Build the core sections array. Shared by both sync and async paths.
|
|
95
|
+
* Subclasses can override to add/reorder sections.
|
|
96
|
+
*/
|
|
97
|
+
protected buildCoreSections(ctx: Omit<LivePromptContext, 'memoryService' | 'lastUserInput'>): string[];
|
|
98
|
+
/**
|
|
99
|
+
* Format tool declarations as in-prompt directives.
|
|
100
|
+
* Subclasses can override for backend-specific formatting.
|
|
101
|
+
*/
|
|
102
|
+
protected buildToolDirectives(tools: ToolDeclaration[]): string;
|
|
103
|
+
/**
|
|
104
|
+
* Extract and format working memory from the session.
|
|
105
|
+
*/
|
|
106
|
+
private buildWorkingMemorySection;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=LivePromptAssembler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LivePromptAssembler.d.ts","sourceRoot":"","sources":["../../src/capabilities/LivePromptAssembler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;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,YAAW,mBAAmB;IACpE,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAC,CAAW;IAC7B,OAAO,CAAC,MAAM,CAAsB;gBAExB,MAAM,GAAE,gCAAqC;IAOnD,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBvD,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,eAAe,CAAC,GAAG,MAAM;IAIrF;;;OAGG;IACH,SAAS,CAAC,iBAAiB,CACzB,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,eAAe,CAAC,GAC9D,MAAM,EAAE;IAwCX;;;OAGG;IACH,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM;IAiB/D;;OAEG;IACH,OAAO,CAAC,yBAAyB;CAelC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LivePromptAssembler — Port for building system prompts optimized for
|
|
3
|
+
* realtime audio models (Gemini Live, OpenAI Realtime, etc.).
|
|
4
|
+
*
|
|
5
|
+
* This is the PORT (interface) in the Ports & Adapters pattern.
|
|
6
|
+
* The default implementation (`DefaultLivePromptAssembler`) bridges
|
|
7
|
+
* CapabilityHost with Runtime context (working memory, long-term memory,
|
|
8
|
+
* policy injections) and structures the output per audio-model best practices.
|
|
9
|
+
*
|
|
10
|
+
* Adapters (Gemini, OpenAI Realtime, LiveKit) can extend or replace
|
|
11
|
+
* the default with backend-specific voice rules and guardrails.
|
|
12
|
+
*
|
|
13
|
+
* Prompt structure follows Google's Live API best practices and
|
|
14
|
+
* OpenAI's Realtime Prompting Guide:
|
|
15
|
+
*
|
|
16
|
+
* 1. Persona — WHO you are
|
|
17
|
+
* 2. Voice Rules — Audio-specific constraints
|
|
18
|
+
* 3. Conversation Flow — Current task + collected state
|
|
19
|
+
* 4. Tool Directives — WHEN to call each tool
|
|
20
|
+
* 5. Context — Working memory + long-term memory
|
|
21
|
+
* 6. Guardrails — Safety, escalation, unclear audio
|
|
22
|
+
*
|
|
23
|
+
* @see https://ai.google.dev/gemini-api/docs/live-api/best-practices
|
|
24
|
+
* @see https://developers.openai.com/cookbook/examples/realtime_prompting_guide
|
|
25
|
+
*/
|
|
26
|
+
import { preloadMemoryContext } from '../memory/preloadMemory.js';
|
|
27
|
+
import { formatMemoryWithBudget, DEFAULT_CONTEXT_BUDGET, } from '../runtime/ContextBudget.js';
|
|
28
|
+
// ─── Default Voice Rules & Guardrails ───────────────────────────────────────
|
|
29
|
+
export const DEFAULT_VOICE_RULES = `## Voice Rules
|
|
30
|
+
- Keep responses to 2-3 sentences per turn. Be concise.
|
|
31
|
+
- Do NOT output markdown, bullet points, numbered lists, or any formatting.
|
|
32
|
+
- Do NOT include sound effects, onomatopoeia, or non-speech sounds.
|
|
33
|
+
- Speak numbers digit-by-digit when reading codes or IDs: "4-1-5" not "four fifteen".
|
|
34
|
+
- If user audio is unclear, ask for clarification. Do not guess.
|
|
35
|
+
- Do NOT repeat back what the user just said. Move the conversation forward.
|
|
36
|
+
- Vary your responses. Do not use the same opening or confirmation phrase twice in a row.`;
|
|
37
|
+
export const DEFAULT_GUARDRAILS = `## Guardrails
|
|
38
|
+
- Only respond to clear audio or text input.
|
|
39
|
+
- If you cannot help with a request, say so briefly and offer to help with something else.
|
|
40
|
+
- All claims must be grounded in provided context or tool results. Do not fabricate information.
|
|
41
|
+
- If unsure about any action, ask for clarification rather than guessing.`;
|
|
42
|
+
// ─── Default Adapter (Implementation) ───────────────────────────────────────
|
|
43
|
+
const INTERNAL_MEMORY_KEYS = [
|
|
44
|
+
'runtimeEventLog',
|
|
45
|
+
'__ariaSessionTurn',
|
|
46
|
+
'__ariaRedactCarry',
|
|
47
|
+
'flowStateByAgent',
|
|
48
|
+
'__ariaAssistantText',
|
|
49
|
+
'__ariaContextBudget',
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* Default LivePromptAssembler implementation.
|
|
53
|
+
*
|
|
54
|
+
* Backend-agnostic — produces a plain string suitable for any realtime
|
|
55
|
+
* audio model. Adapters can extend this class to add backend-specific
|
|
56
|
+
* sections or override the voice rules.
|
|
57
|
+
*/
|
|
58
|
+
export class DefaultLivePromptAssembler {
|
|
59
|
+
voiceRules;
|
|
60
|
+
guardrails;
|
|
61
|
+
allowlist;
|
|
62
|
+
budget;
|
|
63
|
+
constructor(config = {}) {
|
|
64
|
+
this.voiceRules = config.voiceRules ?? DEFAULT_VOICE_RULES;
|
|
65
|
+
this.guardrails = config.guardrails ?? DEFAULT_GUARDRAILS;
|
|
66
|
+
this.allowlist = config.promptMemoryAllowlist;
|
|
67
|
+
this.budget = { ...DEFAULT_CONTEXT_BUDGET, ...(config.budget ?? {}) };
|
|
68
|
+
}
|
|
69
|
+
async assemble(ctx) {
|
|
70
|
+
const sections = this.buildCoreSections(ctx);
|
|
71
|
+
// Async: long-term memory preload
|
|
72
|
+
if (ctx.memoryService && ctx.session && ctx.lastUserInput) {
|
|
73
|
+
const preloaded = await preloadMemoryContext(ctx.memoryService, ctx.session, ctx.lastUserInput, this.budget.maxLongTermMemoryTokens);
|
|
74
|
+
if (preloaded) {
|
|
75
|
+
// Insert before guardrails (last section)
|
|
76
|
+
sections.splice(sections.length - 1, 0, preloaded);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return sections.join('\n\n');
|
|
80
|
+
}
|
|
81
|
+
assembleSync(ctx) {
|
|
82
|
+
return this.buildCoreSections(ctx).join('\n\n');
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Build the core sections array. Shared by both sync and async paths.
|
|
86
|
+
* Subclasses can override to add/reorder sections.
|
|
87
|
+
*/
|
|
88
|
+
buildCoreSections(ctx) {
|
|
89
|
+
const sections = [];
|
|
90
|
+
// 1. Persona
|
|
91
|
+
if (ctx.basePrompt.trim()) {
|
|
92
|
+
sections.push(ctx.basePrompt.trim());
|
|
93
|
+
}
|
|
94
|
+
// 2. Voice Rules
|
|
95
|
+
sections.push(this.voiceRules);
|
|
96
|
+
// 3. Conversation Flow (capability prompt sections — task, state, extraction)
|
|
97
|
+
const capSections = ctx.host.getSystemPrompt();
|
|
98
|
+
if (capSections.trim()) {
|
|
99
|
+
sections.push(capSections);
|
|
100
|
+
}
|
|
101
|
+
// 4. Tool Directives
|
|
102
|
+
const tools = ctx.host.getAllTools();
|
|
103
|
+
if (tools.length > 0) {
|
|
104
|
+
sections.push(this.buildToolDirectives(tools));
|
|
105
|
+
}
|
|
106
|
+
// 5. Working Memory
|
|
107
|
+
if (ctx.session) {
|
|
108
|
+
const memBlock = this.buildWorkingMemorySection(ctx.session);
|
|
109
|
+
if (memBlock)
|
|
110
|
+
sections.push(memBlock);
|
|
111
|
+
}
|
|
112
|
+
// 6. Policy Injections
|
|
113
|
+
if (ctx.policyInjections?.trim()) {
|
|
114
|
+
sections.push(ctx.policyInjections.trim());
|
|
115
|
+
}
|
|
116
|
+
// 7. Guardrails (always last)
|
|
117
|
+
sections.push(this.guardrails);
|
|
118
|
+
return sections;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Format tool declarations as in-prompt directives.
|
|
122
|
+
* Subclasses can override for backend-specific formatting.
|
|
123
|
+
*/
|
|
124
|
+
buildToolDirectives(tools) {
|
|
125
|
+
const lines = ['## Available Tools'];
|
|
126
|
+
for (const tool of tools) {
|
|
127
|
+
lines.push(`- ${tool.name}: ${tool.description}`);
|
|
128
|
+
}
|
|
129
|
+
lines.push('');
|
|
130
|
+
lines.push('## Voice Tool Protocol');
|
|
131
|
+
lines.push('- When the user\'s request matches an available tool\'s purpose, call the tool IMMEDIATELY in this turn. Do not only say you will check.');
|
|
132
|
+
lines.push('- If required parameters are available from the conversation, call the tool now. Only ask a clarifying question when a required parameter is genuinely missing or ambiguous.');
|
|
133
|
+
lines.push('- After receiving a tool result, summarize it in 1-2 spoken sentences. Do not read raw data or JSON to the user.');
|
|
134
|
+
lines.push('- If a tool fails, say so once and offer an alternative. Do not retry.');
|
|
135
|
+
lines.push('- Never reveal tool names, function signatures, or internal routing to the user.');
|
|
136
|
+
return lines.join('\n');
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Extract and format working memory from the session.
|
|
140
|
+
*/
|
|
141
|
+
buildWorkingMemorySection(session) {
|
|
142
|
+
const memory = session.workingMemory ?? {};
|
|
143
|
+
const filtered = {};
|
|
144
|
+
for (const [key, value] of Object.entries(memory)) {
|
|
145
|
+
if (INTERNAL_MEMORY_KEYS.includes(key))
|
|
146
|
+
continue;
|
|
147
|
+
if (this.allowlist && !this.allowlist.includes(key))
|
|
148
|
+
continue;
|
|
149
|
+
filtered[key] = value;
|
|
150
|
+
}
|
|
151
|
+
if (Object.keys(filtered).length === 0)
|
|
152
|
+
return null;
|
|
153
|
+
const block = formatMemoryWithBudget(filtered, this.budget.maxWorkingMemoryTokens);
|
|
154
|
+
return block.trim() || null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=LivePromptAssembler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LivePromptAssembler.js","sourceRoot":"","sources":["../../src/capabilities/LivePromptAssembler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAKH,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EACL,sBAAsB,EAEtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AAgDrC,+EAA+E;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;0FAOuD,CAAC;AAE3F,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;0EAIwC,CAAC;AAkB3E,+EAA+E;AAE/E,MAAM,oBAAoB,GAAG;IAC3B,iBAAiB;IACjB,mBAAmB;IACnB,mBAAmB;IACnB,kBAAkB;IAClB,qBA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YAAE,OAAO,IAAI,CAAC;QAEpD,MAAM,KAAK,GAAG,sBAAsB,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;QACnF,OAAO,KAAK,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Capability, ToolDeclaration, PromptSection, CapabilityAction } from './index.js';
|
|
2
|
+
import type { AgentRoute } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Exposes triage routing as tools: one `route_to_<agentId>` tool per route.
|
|
5
|
+
* The LLM selects the appropriate route; processToolResult converts the
|
|
6
|
+
* tool result to a `handoff` action for the host.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TriageCapability implements Capability {
|
|
9
|
+
private routes;
|
|
10
|
+
private defaultAgent;
|
|
11
|
+
constructor(routes: AgentRoute[], defaultAgent?: string);
|
|
12
|
+
getTools(): ToolDeclaration[];
|
|
13
|
+
getPromptSections(): PromptSection[];
|
|
14
|
+
processToolResult(toolName: string, args: unknown, result: unknown): CapabilityAction | null;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=TriageCapability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TriageCapability.d.ts","sourceRoot":"","sources":["../../src/capabilities/TriageCapability.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAqB;gBAE7B,MAAM,EAAE,UAAU,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM;IAKvD,QAAQ,IAAI,eAAe,EAAE;IAgB7B,iBAAiB,IAAI,aAAa,EAAE;IAsBpC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI;CAU7F"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isHandoffResult } from '../tools/handoff.js';
|
|
3
|
+
// ─── TriageCapability ────────────────────────────────────────────────────────
|
|
4
|
+
/**
|
|
5
|
+
* Exposes triage routing as tools: one `route_to_<agentId>` tool per route.
|
|
6
|
+
* The LLM selects the appropriate route; processToolResult converts the
|
|
7
|
+
* tool result to a `handoff` action for the host.
|
|
8
|
+
*/
|
|
9
|
+
export class TriageCapability {
|
|
10
|
+
routes;
|
|
11
|
+
defaultAgent;
|
|
12
|
+
constructor(routes, defaultAgent) {
|
|
13
|
+
this.routes = routes;
|
|
14
|
+
this.defaultAgent = defaultAgent;
|
|
15
|
+
}
|
|
16
|
+
getTools() {
|
|
17
|
+
return this.routes.map(route => ({
|
|
18
|
+
name: `route_to_${route.agentId}`,
|
|
19
|
+
description: route.description,
|
|
20
|
+
parameters: z.object({
|
|
21
|
+
reason: z.string().describe('Why this route was chosen — include relevant context from the conversation'),
|
|
22
|
+
}),
|
|
23
|
+
execute: async (args) => ({
|
|
24
|
+
__handoff: true,
|
|
25
|
+
targetAgentId: route.agentId,
|
|
26
|
+
targetAgent: route.agentId,
|
|
27
|
+
reason: args.reason,
|
|
28
|
+
}),
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
getPromptSections() {
|
|
32
|
+
if (this.routes.length === 0)
|
|
33
|
+
return [];
|
|
34
|
+
const routeList = this.routes
|
|
35
|
+
.map(r => `- route_to_${r.agentId}: ${r.description}`)
|
|
36
|
+
.join('\n');
|
|
37
|
+
const defaultNote = this.defaultAgent
|
|
38
|
+
? `\nIf no route clearly matches, route to ${this.defaultAgent}.`
|
|
39
|
+
: '';
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
role: 'routing',
|
|
43
|
+
content: `Route the user to the most appropriate agent using the routing tools below.\n` +
|
|
44
|
+
`Do NOT mention routing or agent transfers to the user.\n\n` +
|
|
45
|
+
`Available routes:\n${routeList}${defaultNote}`,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
processToolResult(toolName, args, result) {
|
|
50
|
+
if (!toolName.startsWith('route_to_'))
|
|
51
|
+
return null;
|
|
52
|
+
if (!isHandoffResult(result))
|
|
53
|
+
return null;
|
|
54
|
+
return {
|
|
55
|
+
type: 'handoff',
|
|
56
|
+
targetAgent: result.targetAgentId,
|
|
57
|
+
reason: result.reason,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=TriageCapability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TriageCapability.js","sourceRoot":"","sources":["../../src/capabilities/TriageCapability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAe;IACrB,YAAY,CAAqB;IAEzC,YAAY,MAAoB,EAAE,YAAqB;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC/B,IAAI,EAAE,YAAY,KAAK,CAAC,OAAO,EAAE;YACjC,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC;gBACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ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
import type { ToolDeclaration } from '../index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Convert ToolDeclarations to Vercel AI SDK ToolSet format.
|
|
5
|
+
*
|
|
6
|
+
* ai v6 uses `inputSchema` (not `parameters`). The execute function
|
|
7
|
+
* signature is `(input, options) => ...` — we ignore options since
|
|
8
|
+
* ToolDeclaration.execute only takes args.
|
|
9
|
+
*
|
|
10
|
+
* Follows the Hare pattern: closes over context at registration time
|
|
11
|
+
* so tools don't need context at call time.
|
|
12
|
+
*/
|
|
13
|
+
export declare function toAISDKTools(tools: ToolDeclaration[]): ToolSet;
|
|
14
|
+
//# sourceMappingURL=ai-sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../../../src/capabilities/adapters/ai-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,IAAI,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,OAAO,CAiB9D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { tool as aiTool } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Convert ToolDeclarations to Vercel AI SDK ToolSet format.
|
|
4
|
+
*
|
|
5
|
+
* ai v6 uses `inputSchema` (not `parameters`). The execute function
|
|
6
|
+
* signature is `(input, options) => ...` — we ignore options since
|
|
7
|
+
* ToolDeclaration.execute only takes args.
|
|
8
|
+
*
|
|
9
|
+
* Follows the Hare pattern: closes over context at registration time
|
|
10
|
+
* so tools don't need context at call time.
|
|
11
|
+
*/
|
|
12
|
+
export function toAISDKTools(tools) {
|
|
13
|
+
return Object.fromEntries(tools.map(t => [
|
|
14
|
+
t.name,
|
|
15
|
+
aiTool({
|
|
16
|
+
description: t.description,
|
|
17
|
+
inputSchema: t.parameters,
|
|
18
|
+
execute: async (args, options) => {
|
|
19
|
+
try {
|
|
20
|
+
return await t.execute(args, options);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
]));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ai-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk.js","sourceRoot":"","sources":["../../../src/capabilities/adapters/ai-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,MAAM,EAAgB,MAAM,IAAI,CAAC;AAGlD;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,OAAO,MAAM,CAAC,WAAW,CACvB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACb,CAAC,CAAC,IAAI;QACN,MAAM,CAAC;YACL,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,WAAW,EAAE,CAAC,CAAC,UAAU;YACzB,OAAO,EAAE,KAAK,EAAE,IAAa,EAAE,OAAiB,EAAE,EAAE;gBAClD,IAAI,CAAC;oBACH,OAAO,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACxC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3E,CAAC;YACH,CAAC;SACF,CAAC;KACH,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ToolDeclaration } from '../index.js';
|
|
2
|
+
export interface GeminiFunctionDeclaration {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Convert ToolDeclarations to Gemini FunctionDeclarations.
|
|
9
|
+
*
|
|
10
|
+
* Gemini expects OpenAPI 3.x style JSON Schema for parameters.
|
|
11
|
+
* This adapter handles the Zod → JSON Schema conversion and
|
|
12
|
+
* strips unsupported JSON Schema features ($ref, oneOf, const).
|
|
13
|
+
*/
|
|
14
|
+
export declare function toGeminiDeclarations(tools: ToolDeclaration[]): GeminiFunctionDeclaration[];
|
|
15
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/capabilities/adapters/gemini.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,yBAAyB,EAAE,CAQ1F"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Convert ToolDeclarations to Gemini FunctionDeclarations.
|
|
4
|
+
*
|
|
5
|
+
* Gemini expects OpenAPI 3.x style JSON Schema for parameters.
|
|
6
|
+
* This adapter handles the Zod → JSON Schema conversion and
|
|
7
|
+
* strips unsupported JSON Schema features ($ref, oneOf, const).
|
|
8
|
+
*/
|
|
9
|
+
export function toGeminiDeclarations(tools) {
|
|
10
|
+
return tools.map(tool => ({
|
|
11
|
+
name: tool.name,
|
|
12
|
+
description: tool.description,
|
|
13
|
+
parameters: tool.parameters
|
|
14
|
+
? stripUnsupported(zodToJsonSchema(tool.parameters, { target: 'openApi3' }))
|
|
15
|
+
: { type: 'object', properties: {} },
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Recursively strip JSON Schema features that Gemini doesn't support.
|
|
20
|
+
*/
|
|
21
|
+
function stripUnsupported(schema) {
|
|
22
|
+
const cleaned = {};
|
|
23
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
24
|
+
// Skip unsupported top-level and nested keys
|
|
25
|
+
if (key === '$schema' || key === '$ref' || key === 'additionalProperties')
|
|
26
|
+
continue;
|
|
27
|
+
// Recurse into objects
|
|
28
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
29
|
+
cleaned[key] = stripUnsupported(value);
|
|
30
|
+
}
|
|
31
|
+
else if (Array.isArray(value)) {
|
|
32
|
+
cleaned[key] = value.map(item => item && typeof item === 'object' ? stripUnsupported(item) : item);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
cleaned[key] = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return cleaned;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=gemini.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/capabilities/adapters/gemini.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AASrD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAwB;IAC3D,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;YACzB,CAAC,CAAC,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,CAA4B,CAAC;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