@falai/agent 0.4.1 → 0.5.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 +21 -74
- package/dist/cjs/core/Agent.d.ts +22 -29
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +464 -291
- package/dist/cjs/core/Agent.js.map +1 -1
- package/dist/cjs/core/Events.d.ts +10 -1
- package/dist/cjs/core/Events.d.ts.map +1 -1
- package/dist/cjs/core/Events.js +3 -2
- package/dist/cjs/core/Events.js.map +1 -1
- package/dist/cjs/core/PersistenceManager.d.ts +19 -0
- package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
- package/dist/cjs/core/PersistenceManager.js +57 -0
- package/dist/cjs/core/PersistenceManager.js.map +1 -1
- package/dist/cjs/core/PromptComposer.d.ts +24 -0
- package/dist/cjs/core/PromptComposer.d.ts.map +1 -0
- package/dist/cjs/core/PromptComposer.js +127 -0
- package/dist/cjs/core/PromptComposer.js.map +1 -0
- package/dist/cjs/core/ResponseEngine.d.ts +19 -0
- package/dist/cjs/core/ResponseEngine.d.ts.map +1 -0
- package/dist/cjs/core/ResponseEngine.js +51 -0
- package/dist/cjs/core/ResponseEngine.js.map +1 -0
- package/dist/cjs/core/Route.d.ts +18 -12
- package/dist/cjs/core/Route.d.ts.map +1 -1
- package/dist/cjs/core/Route.js +15 -9
- package/dist/cjs/core/Route.js.map +1 -1
- package/dist/cjs/core/RoutingEngine.d.ts +38 -0
- package/dist/cjs/core/RoutingEngine.d.ts.map +1 -0
- package/dist/cjs/core/RoutingEngine.js +110 -0
- package/dist/cjs/core/RoutingEngine.js.map +1 -0
- package/dist/cjs/core/State.d.ts +15 -4
- package/dist/cjs/core/State.d.ts.map +1 -1
- package/dist/cjs/core/State.js +21 -2
- package/dist/cjs/core/State.js.map +1 -1
- package/dist/cjs/core/ToolExecutor.d.ts +29 -0
- package/dist/cjs/core/ToolExecutor.d.ts.map +1 -0
- package/dist/cjs/core/ToolExecutor.js +73 -0
- package/dist/cjs/core/ToolExecutor.js.map +1 -0
- package/dist/cjs/core/Transition.d.ts +5 -5
- package/dist/cjs/core/Transition.d.ts.map +1 -1
- package/dist/cjs/core/Transition.js.map +1 -1
- package/dist/cjs/index.d.ts +6 -8
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +8 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/AnthropicProvider.d.ts.map +1 -1
- package/dist/cjs/providers/AnthropicProvider.js +10 -13
- package/dist/cjs/providers/AnthropicProvider.js.map +1 -1
- package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/GeminiProvider.js +12 -8
- package/dist/cjs/providers/GeminiProvider.js.map +1 -1
- package/dist/cjs/providers/OpenAIProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenAIProvider.js +10 -53
- package/dist/cjs/providers/OpenAIProvider.js.map +1 -1
- package/dist/cjs/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenRouterProvider.js +10 -53
- package/dist/cjs/providers/OpenRouterProvider.js.map +1 -1
- package/dist/cjs/types/agent.d.ts +13 -12
- package/dist/cjs/types/agent.d.ts.map +1 -1
- package/dist/cjs/types/ai.d.ts +8 -2
- package/dist/cjs/types/ai.d.ts.map +1 -1
- package/dist/cjs/types/history.d.ts +8 -0
- package/dist/cjs/types/history.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +0 -3
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +1 -3
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/route.d.ts +39 -4
- package/dist/cjs/types/route.d.ts.map +1 -1
- package/dist/cjs/types/routing.d.ts +16 -0
- package/dist/cjs/types/routing.d.ts.map +1 -0
- package/dist/cjs/types/routing.js +3 -0
- package/dist/cjs/types/routing.js.map +1 -0
- package/dist/cjs/types/schema.d.ts +22 -0
- package/dist/cjs/types/schema.d.ts.map +1 -0
- package/dist/cjs/types/schema.js +3 -0
- package/dist/cjs/types/schema.js.map +1 -0
- package/dist/cjs/types/session.d.ts +72 -0
- package/dist/cjs/types/session.d.ts.map +1 -0
- package/dist/cjs/types/session.js +140 -0
- package/dist/cjs/types/session.js.map +1 -0
- package/dist/cjs/types/tool.d.ts +11 -5
- package/dist/cjs/types/tool.d.ts.map +1 -1
- package/dist/cjs/utils/id.d.ts +0 -5
- package/dist/cjs/utils/id.d.ts.map +1 -1
- package/dist/cjs/utils/id.js +0 -10
- package/dist/cjs/utils/id.js.map +1 -1
- package/dist/cjs/utils/schema.d.ts +17 -0
- package/dist/cjs/utils/schema.d.ts.map +1 -0
- package/dist/cjs/utils/schema.js +32 -0
- package/dist/cjs/utils/schema.js.map +1 -0
- package/dist/core/Agent.d.ts +22 -29
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +464 -291
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/Events.d.ts +10 -1
- package/dist/core/Events.d.ts.map +1 -1
- package/dist/core/Events.js +3 -2
- package/dist/core/Events.js.map +1 -1
- package/dist/core/PersistenceManager.d.ts +19 -0
- package/dist/core/PersistenceManager.d.ts.map +1 -1
- package/dist/core/PersistenceManager.js +57 -0
- package/dist/core/PersistenceManager.js.map +1 -1
- package/dist/core/PromptComposer.d.ts +24 -0
- package/dist/core/PromptComposer.d.ts.map +1 -0
- package/dist/core/PromptComposer.js +123 -0
- package/dist/core/PromptComposer.js.map +1 -0
- package/dist/core/ResponseEngine.d.ts +19 -0
- package/dist/core/ResponseEngine.d.ts.map +1 -0
- package/dist/core/ResponseEngine.js +47 -0
- package/dist/core/ResponseEngine.js.map +1 -0
- package/dist/core/Route.d.ts +18 -12
- package/dist/core/Route.d.ts.map +1 -1
- package/dist/core/Route.js +15 -9
- package/dist/core/Route.js.map +1 -1
- package/dist/core/RoutingEngine.d.ts +38 -0
- package/dist/core/RoutingEngine.d.ts.map +1 -0
- package/dist/core/RoutingEngine.js +106 -0
- package/dist/core/RoutingEngine.js.map +1 -0
- package/dist/core/State.d.ts +15 -4
- package/dist/core/State.d.ts.map +1 -1
- package/dist/core/State.js +21 -2
- package/dist/core/State.js.map +1 -1
- package/dist/core/ToolExecutor.d.ts +29 -0
- package/dist/core/ToolExecutor.d.ts.map +1 -0
- package/dist/core/ToolExecutor.js +69 -0
- package/dist/core/ToolExecutor.js.map +1 -0
- package/dist/core/Transition.d.ts +5 -5
- package/dist/core/Transition.d.ts.map +1 -1
- package/dist/core/Transition.js.map +1 -1
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/providers/AnthropicProvider.d.ts.map +1 -1
- package/dist/providers/AnthropicProvider.js +10 -13
- package/dist/providers/AnthropicProvider.js.map +1 -1
- package/dist/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/GeminiProvider.js +12 -8
- package/dist/providers/GeminiProvider.js.map +1 -1
- package/dist/providers/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/OpenAIProvider.js +10 -53
- package/dist/providers/OpenAIProvider.js.map +1 -1
- package/dist/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/providers/OpenRouterProvider.js +10 -53
- package/dist/providers/OpenRouterProvider.js.map +1 -1
- package/dist/types/agent.d.ts +13 -12
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/ai.d.ts +8 -2
- package/dist/types/ai.d.ts.map +1 -1
- package/dist/types/history.d.ts +8 -0
- package/dist/types/history.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/route.d.ts +39 -4
- package/dist/types/route.d.ts.map +1 -1
- package/dist/types/routing.d.ts +16 -0
- package/dist/types/routing.d.ts.map +1 -0
- package/dist/types/routing.js +2 -0
- package/dist/types/routing.js.map +1 -0
- package/dist/types/schema.d.ts +22 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +2 -0
- package/dist/types/schema.js.map +1 -0
- package/dist/types/session.d.ts +72 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +132 -0
- package/dist/types/session.js.map +1 -0
- package/dist/types/tool.d.ts +11 -5
- package/dist/types/tool.d.ts.map +1 -1
- package/dist/utils/id.d.ts +0 -5
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +0 -9
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/schema.d.ts +17 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +27 -0
- package/dist/utils/schema.js.map +1 -0
- package/docs/ADAPTERS.md +83 -3
- package/docs/API_REFERENCE.md +95 -104
- package/docs/ARCHITECTURE.md +284 -286
- package/docs/CONSTRUCTOR_OPTIONS.md +192 -135
- package/docs/CONTEXT_MANAGEMENT.md +311 -28
- package/docs/CONTRIBUTING.md +1 -1
- package/docs/DOMAINS.md +61 -0
- package/docs/GETTING_STARTED.md +177 -88
- package/docs/PERSISTENCE.md +170 -23
- package/docs/README.md +7 -10
- package/examples/business-onboarding.ts +21 -9
- package/examples/company-qna-agent.ts +508 -0
- package/examples/declarative-agent.ts +143 -26
- package/examples/domain-scoping.ts +31 -10
- package/examples/extracted-data-modification.ts +415 -0
- package/examples/healthcare-agent.ts +194 -90
- package/examples/openai-agent.ts +67 -25
- package/examples/opensearch-persistence.ts +455 -151
- package/examples/persistent-onboarding.ts +162 -96
- package/examples/prisma-persistence.ts +371 -125
- package/examples/redis-persistence.ts +393 -23
- package/examples/rules-prohibitions.ts +32 -11
- package/examples/streaming-agent.ts +61 -13
- package/examples/travel-agent.ts +266 -133
- package/package.json +1 -1
- package/src/core/Agent.ts +674 -356
- package/src/core/Events.ts +12 -2
- package/src/core/PersistenceManager.ts +83 -0
- package/src/core/PromptComposer.ts +143 -0
- package/src/core/ResponseEngine.ts +82 -0
- package/src/core/Route.ts +32 -17
- package/src/core/RoutingEngine.ts +165 -0
- package/src/core/State.ts +55 -15
- package/src/core/ToolExecutor.ts +117 -0
- package/src/core/Transition.ts +5 -5
- package/src/index.ts +12 -21
- package/src/providers/AnthropicProvider.ts +10 -13
- package/src/providers/GeminiProvider.ts +12 -8
- package/src/providers/OpenAIProvider.ts +10 -56
- package/src/providers/OpenRouterProvider.ts +10 -56
- package/src/types/agent.ts +16 -13
- package/src/types/ai.ts +6 -2
- package/src/types/history.ts +8 -0
- package/src/types/index.ts +0 -11
- package/src/types/route.ts +41 -5
- package/src/types/routing.ts +18 -0
- package/src/types/schema.ts +23 -0
- package/src/types/session.ts +207 -0
- package/src/types/tool.ts +29 -7
- package/src/utils/id.ts +0 -10
- package/src/utils/schema.ts +32 -0
- package/dist/cjs/core/ConditionEvaluator.d.ts +0 -72
- package/dist/cjs/core/ConditionEvaluator.d.ts.map +0 -1
- package/dist/cjs/core/ConditionEvaluator.js +0 -272
- package/dist/cjs/core/ConditionEvaluator.js.map +0 -1
- package/dist/cjs/core/Observation.d.ts +0 -24
- package/dist/cjs/core/Observation.d.ts.map +0 -1
- package/dist/cjs/core/Observation.js +0 -39
- package/dist/cjs/core/Observation.js.map +0 -1
- package/dist/cjs/core/PreparationEngine.d.ts +0 -116
- package/dist/cjs/core/PreparationEngine.d.ts.map +0 -1
- package/dist/cjs/core/PreparationEngine.js +0 -353
- package/dist/cjs/core/PreparationEngine.js.map +0 -1
- package/dist/cjs/core/PromptBuilder.d.ts +0 -136
- package/dist/cjs/core/PromptBuilder.d.ts.map +0 -1
- package/dist/cjs/core/PromptBuilder.js +0 -421
- package/dist/cjs/core/PromptBuilder.js.map +0 -1
- package/dist/cjs/types/observation.d.ts +0 -27
- package/dist/cjs/types/observation.d.ts.map +0 -1
- package/dist/cjs/types/observation.js +0 -6
- package/dist/cjs/types/observation.js.map +0 -1
- package/dist/cjs/types/prompt.d.ts +0 -46
- package/dist/cjs/types/prompt.d.ts.map +0 -1
- package/dist/cjs/types/prompt.js +0 -19
- package/dist/cjs/types/prompt.js.map +0 -1
- package/dist/core/ConditionEvaluator.d.ts +0 -72
- package/dist/core/ConditionEvaluator.d.ts.map +0 -1
- package/dist/core/ConditionEvaluator.js +0 -268
- package/dist/core/ConditionEvaluator.js.map +0 -1
- package/dist/core/Observation.d.ts +0 -24
- package/dist/core/Observation.d.ts.map +0 -1
- package/dist/core/Observation.js +0 -35
- package/dist/core/Observation.js.map +0 -1
- package/dist/core/PreparationEngine.d.ts +0 -116
- package/dist/core/PreparationEngine.d.ts.map +0 -1
- package/dist/core/PreparationEngine.js +0 -349
- package/dist/core/PreparationEngine.js.map +0 -1
- package/dist/core/PromptBuilder.d.ts +0 -136
- package/dist/core/PromptBuilder.d.ts.map +0 -1
- package/dist/core/PromptBuilder.js +0 -417
- package/dist/core/PromptBuilder.js.map +0 -1
- package/dist/types/observation.d.ts +0 -27
- package/dist/types/observation.d.ts.map +0 -1
- package/dist/types/observation.js +0 -5
- package/dist/types/observation.js.map +0 -1
- package/dist/types/prompt.d.ts +0 -46
- package/dist/types/prompt.d.ts.map +0 -1
- package/dist/types/prompt.js +0 -16
- package/dist/types/prompt.js.map +0 -1
- package/docs/STRUCTURE.md +0 -58
- package/src/core/ConditionEvaluator.ts +0 -381
- package/src/core/Observation.ts +0 -47
- package/src/core/PreparationEngine.ts +0 -561
- package/src/core/PromptBuilder.ts +0 -617
- package/src/types/observation.ts +0 -29
- package/src/types/prompt.ts +0 -49
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ConditionEvaluator - Handles AI-powered condition evaluation
|
|
3
|
-
*
|
|
4
|
-
* This class is responsible for:
|
|
5
|
-
* - Evaluating guideline conditions
|
|
6
|
-
* - Evaluating transition conditions
|
|
7
|
-
* - Extracting tool arguments from context and history
|
|
8
|
-
*/
|
|
9
|
-
import { EventKind } from "../types/history";
|
|
10
|
-
/**
|
|
11
|
-
* ConditionEvaluator - Evaluates conditions using AI
|
|
12
|
-
*/
|
|
13
|
-
export class ConditionEvaluator {
|
|
14
|
-
constructor(ai) {
|
|
15
|
-
this.ai = ai;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Evaluate a guideline condition against context and history
|
|
19
|
-
*/
|
|
20
|
-
async evaluateGuidelineCondition(guideline, context, history) {
|
|
21
|
-
try {
|
|
22
|
-
const recentMessages = this.extractRecentMessages(history);
|
|
23
|
-
const prompt = `You are evaluating whether a guideline condition is met.
|
|
24
|
-
|
|
25
|
-
Guideline Condition: ${guideline.condition}
|
|
26
|
-
Action: ${guideline.action}
|
|
27
|
-
|
|
28
|
-
Current Context:
|
|
29
|
-
${JSON.stringify(context, null, 2)}
|
|
30
|
-
|
|
31
|
-
Recent Conversation:
|
|
32
|
-
${recentMessages || "(No recent messages)"}
|
|
33
|
-
|
|
34
|
-
Evaluate whether the guideline condition is currently met based on the context and conversation.
|
|
35
|
-
|
|
36
|
-
Your response must be a JSON object with this exact structure:
|
|
37
|
-
{
|
|
38
|
-
"matches": boolean (true or false),
|
|
39
|
-
"rationale": string (brief explanation)
|
|
40
|
-
}`;
|
|
41
|
-
const result = await this.ai.generateMessage({
|
|
42
|
-
prompt,
|
|
43
|
-
history,
|
|
44
|
-
context,
|
|
45
|
-
parameters: {
|
|
46
|
-
jsonMode: true,
|
|
47
|
-
maxOutputTokens: 500,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
// Parse structured response
|
|
51
|
-
if (result.structured) {
|
|
52
|
-
return {
|
|
53
|
-
matches: result.structured.matches === true,
|
|
54
|
-
rationale: result.structured.rationale,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
// Fallback parsing
|
|
58
|
-
return this.parseGuidelineResponse(result.message);
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.error(`[ConditionEvaluator] Failed to evaluate guideline condition: ${guideline.id}`, error);
|
|
62
|
-
return {
|
|
63
|
-
matches: false,
|
|
64
|
-
rationale: "Failed to evaluate condition",
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Evaluate a transition condition
|
|
70
|
-
*/
|
|
71
|
-
async evaluateTransitionCondition(condition, context, history) {
|
|
72
|
-
try {
|
|
73
|
-
const recentMessages = this.extractRecentMessages(history);
|
|
74
|
-
const prompt = `You are evaluating whether a state transition condition is met.
|
|
75
|
-
|
|
76
|
-
Transition Condition: ${condition}
|
|
77
|
-
|
|
78
|
-
Current Context:
|
|
79
|
-
${JSON.stringify(context, null, 2)}
|
|
80
|
-
|
|
81
|
-
Recent Conversation:
|
|
82
|
-
${recentMessages || "(No recent messages)"}
|
|
83
|
-
|
|
84
|
-
Evaluate whether this transition should be followed based on the condition, context, and conversation.
|
|
85
|
-
|
|
86
|
-
Your response must be a JSON object with this exact structure:
|
|
87
|
-
{
|
|
88
|
-
"shouldFollow": boolean (true or false),
|
|
89
|
-
"rationale": string (brief explanation)
|
|
90
|
-
}`;
|
|
91
|
-
const result = await this.ai.generateMessage({
|
|
92
|
-
prompt,
|
|
93
|
-
history,
|
|
94
|
-
context,
|
|
95
|
-
parameters: {
|
|
96
|
-
jsonMode: true,
|
|
97
|
-
maxOutputTokens: 300,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
// Parse structured response
|
|
101
|
-
if (result.structured) {
|
|
102
|
-
return {
|
|
103
|
-
shouldFollow: result.structured.shouldFollow === true,
|
|
104
|
-
rationale: result.structured.rationale,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
// Fallback parsing
|
|
108
|
-
return this.parseTransitionResponse(result.message);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
console.error(`[ConditionEvaluator] Failed to evaluate transition condition`, error);
|
|
112
|
-
return {
|
|
113
|
-
shouldFollow: false,
|
|
114
|
-
rationale: "Failed to evaluate condition",
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Extract tool arguments from context and history
|
|
120
|
-
*/
|
|
121
|
-
async extractToolArguments(tool, context, history) {
|
|
122
|
-
try {
|
|
123
|
-
const recentMessages = this.extractRecentMessages(history);
|
|
124
|
-
const prompt = `You are extracting arguments for a tool call.
|
|
125
|
-
|
|
126
|
-
Tool: ${tool.name}
|
|
127
|
-
Description: ${tool.description || "No description"}
|
|
128
|
-
Parameters: ${JSON.stringify(tool.parameters, null, 2)}
|
|
129
|
-
|
|
130
|
-
Current Context:
|
|
131
|
-
${JSON.stringify(context, null, 2)}
|
|
132
|
-
|
|
133
|
-
Recent Conversation:
|
|
134
|
-
${recentMessages || "(No recent messages)"}
|
|
135
|
-
|
|
136
|
-
Extract the arguments needed to call this tool based on the context and conversation.
|
|
137
|
-
If a parameter is not available, use null or a reasonable default value.
|
|
138
|
-
|
|
139
|
-
Your response must be a JSON object with this exact structure:
|
|
140
|
-
{
|
|
141
|
-
"arguments": [arg1, arg2, ...] (array of argument values),
|
|
142
|
-
"rationale": string (optional explanation)
|
|
143
|
-
}`;
|
|
144
|
-
const result = await this.ai.generateMessage({
|
|
145
|
-
prompt,
|
|
146
|
-
history,
|
|
147
|
-
context,
|
|
148
|
-
parameters: {
|
|
149
|
-
jsonMode: true,
|
|
150
|
-
maxOutputTokens: 500,
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
// Parse structured response
|
|
154
|
-
if (result.structured) {
|
|
155
|
-
if (result.structured.arguments &&
|
|
156
|
-
Array.isArray(result.structured.arguments)) {
|
|
157
|
-
return {
|
|
158
|
-
arguments: result.structured.arguments,
|
|
159
|
-
rationale: result.structured.rationale,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// Fallback: try to parse from message
|
|
164
|
-
return this.parseArgumentResponse(result.message);
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
console.error(`[ConditionEvaluator] Failed to extract tool arguments: ${tool.name}`, error);
|
|
168
|
-
return {
|
|
169
|
-
arguments: [],
|
|
170
|
-
rationale: "Failed to extract arguments",
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Simple argument extraction from context (fallback)
|
|
176
|
-
*/
|
|
177
|
-
simpleArgumentExtraction(tool, context) {
|
|
178
|
-
const contextObj = context;
|
|
179
|
-
const args = [];
|
|
180
|
-
// If parameters is an object with properties, try to match context keys
|
|
181
|
-
if (tool.parameters &&
|
|
182
|
-
typeof tool.parameters === "object" &&
|
|
183
|
-
!Array.isArray(tool.parameters)) {
|
|
184
|
-
const params = tool.parameters;
|
|
185
|
-
// Try to match parameter names with context keys
|
|
186
|
-
for (const [paramName, paramDef] of Object.entries(params)) {
|
|
187
|
-
if (contextObj[paramName] !== undefined) {
|
|
188
|
-
args.push(contextObj[paramName]);
|
|
189
|
-
}
|
|
190
|
-
else if (typeof paramDef === "object" &&
|
|
191
|
-
paramDef !== null &&
|
|
192
|
-
"default" in paramDef &&
|
|
193
|
-
typeof paramDef.default !== "undefined") {
|
|
194
|
-
args.push(paramDef.default);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return args;
|
|
199
|
-
}
|
|
200
|
-
// Private helper methods
|
|
201
|
-
/**
|
|
202
|
-
* Extract recent messages from history
|
|
203
|
-
*/
|
|
204
|
-
extractRecentMessages(history, count = 5) {
|
|
205
|
-
return history
|
|
206
|
-
.slice(-count)
|
|
207
|
-
.map((event) => {
|
|
208
|
-
if (event.kind === EventKind.MESSAGE) {
|
|
209
|
-
const data = event.data;
|
|
210
|
-
return `${data.participant.display_name}: ${data.message}`;
|
|
211
|
-
}
|
|
212
|
-
return null;
|
|
213
|
-
})
|
|
214
|
-
.filter((msg) => msg !== null)
|
|
215
|
-
.join("\n");
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Parse guideline evaluation from text response (fallback)
|
|
219
|
-
*/
|
|
220
|
-
parseGuidelineResponse(message) {
|
|
221
|
-
const lowerMessage = message.toLowerCase();
|
|
222
|
-
const matches = lowerMessage.includes("true") || lowerMessage.includes('"matches": true');
|
|
223
|
-
return {
|
|
224
|
-
matches,
|
|
225
|
-
rationale: matches ? "Parsed from text response" : "Condition not met",
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Parse transition evaluation from text response (fallback)
|
|
230
|
-
*/
|
|
231
|
-
parseTransitionResponse(message) {
|
|
232
|
-
const lowerMessage = message.toLowerCase();
|
|
233
|
-
const shouldFollow = lowerMessage.includes("true") ||
|
|
234
|
-
lowerMessage.includes('"shouldfollow": true');
|
|
235
|
-
return {
|
|
236
|
-
shouldFollow,
|
|
237
|
-
rationale: shouldFollow
|
|
238
|
-
? "Parsed from text response"
|
|
239
|
-
: "Condition not met",
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Parse argument extraction from text response (fallback)
|
|
244
|
-
*/
|
|
245
|
-
parseArgumentResponse(message) {
|
|
246
|
-
try {
|
|
247
|
-
// Try to extract JSON from the message
|
|
248
|
-
const jsonMatch = message.match(/\{[\s\S]*\}/);
|
|
249
|
-
if (jsonMatch) {
|
|
250
|
-
const parsed = JSON.parse(jsonMatch[0]);
|
|
251
|
-
if (parsed.arguments && Array.isArray(parsed.arguments)) {
|
|
252
|
-
return {
|
|
253
|
-
arguments: parsed.arguments,
|
|
254
|
-
rationale: parsed.rationale,
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
// Ignore parse errors
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
arguments: [],
|
|
264
|
-
rationale: "Failed to parse arguments from response",
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
//# sourceMappingURL=ConditionEvaluator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionEvaluator.js","sourceRoot":"","sources":["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AM,CAAC;YACP,sBAAsB;QACxB,CAAC;QAED,OAAO;YACL,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,yCAAyC;SACrD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Observation for route disambiguation
|
|
3
|
-
*/
|
|
4
|
-
import type { Observation as IObservation, ObservationOptions } from "../types/observation";
|
|
5
|
-
import type { RouteRef } from "../types/route";
|
|
6
|
-
import type { Route } from "./Route";
|
|
7
|
-
/**
|
|
8
|
-
* An observation that can trigger disambiguation between routes
|
|
9
|
-
*/
|
|
10
|
-
export declare class Observation implements IObservation {
|
|
11
|
-
readonly id: string;
|
|
12
|
-
readonly description: string;
|
|
13
|
-
routes: RouteRef[];
|
|
14
|
-
constructor(options: ObservationOptions);
|
|
15
|
-
/**
|
|
16
|
-
* Set routes that this observation can disambiguate between
|
|
17
|
-
*/
|
|
18
|
-
disambiguate(routes: (Route<any> | RouteRef)[]): this;
|
|
19
|
-
/**
|
|
20
|
-
* Get the routes this observation disambiguates
|
|
21
|
-
*/
|
|
22
|
-
getRoutes(): RouteRef[];
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=Observation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Observation.d.ts","sourceRoot":"","sources":["../../src/core/Observation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,WAAW,IAAI,YAAY,EAC3B,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGrC;;GAEG;AACH,qBAAa,WAAY,YAAW,YAAY;IAC9C,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,WAAW,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,QAAQ,EAAE,CAAM;gBAEnB,OAAO,EAAE,kBAAkB;IAMvC;;OAEG;IAEH,YAAY,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,EAAE,GAAG,IAAI;IAUrD;;OAEG;IACH,SAAS,IAAI,QAAQ,EAAE;CAGxB"}
|
package/dist/core/Observation.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Observation for route disambiguation
|
|
3
|
-
*/
|
|
4
|
-
import { generateObservationId } from "../utils/id";
|
|
5
|
-
/**
|
|
6
|
-
* An observation that can trigger disambiguation between routes
|
|
7
|
-
*/
|
|
8
|
-
export class Observation {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.routes = [];
|
|
11
|
-
// Use provided ID or generate a deterministic one from the description
|
|
12
|
-
this.id = options.id || generateObservationId(options.description);
|
|
13
|
-
this.description = options.description;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Set routes that this observation can disambiguate between
|
|
17
|
-
*/
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
disambiguate(routes) {
|
|
20
|
-
this.routes = routes.map((r) => {
|
|
21
|
-
if ("getRef" in r) {
|
|
22
|
-
return r.getRef();
|
|
23
|
-
}
|
|
24
|
-
return r;
|
|
25
|
-
});
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Get the routes this observation disambiguates
|
|
30
|
-
*/
|
|
31
|
-
getRoutes() {
|
|
32
|
-
return [...this.routes];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=Observation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Observation.js","sourceRoot":"","sources":["../../src/core/Observation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,WAAW;IAKtB,YAAY,OAA2B;QAFhC,WAAM,GAAe,EAAE,CAAC;QAG7B,uEAAuE;QACvE,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,qBAAqB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACnE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,8DAA8D;IAC9D,YAAY,CAAC,MAAiC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7B,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;gBAClB,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;YACpB,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PreparationEngine - Handles the preparation iteration loop
|
|
3
|
-
*
|
|
4
|
-
* This engine implements the core Parlant/Emcie architecture:
|
|
5
|
-
* 1. Before generating a message, run preparation iterations
|
|
6
|
-
* 2. Each iteration:
|
|
7
|
-
* - Match guidelines against current context
|
|
8
|
-
* - Walk the state machine and execute tool transitions
|
|
9
|
-
* - Execute tools when conditions are met
|
|
10
|
-
* - Update context from tool results
|
|
11
|
-
* - Check if prepared to respond
|
|
12
|
-
* 3. After preparation, the AI generates the final message
|
|
13
|
-
*
|
|
14
|
-
* The AI NEVER sees tools - tools execute automatically based on:
|
|
15
|
-
* - State machine transitions ({ toolState: tool })
|
|
16
|
-
* - Guideline matching with associated tools
|
|
17
|
-
*/
|
|
18
|
-
import type { Event, StateRef, AiProvider } from "../types/index";
|
|
19
|
-
import type { Guideline, GuidelineMatch } from "../types/agent";
|
|
20
|
-
import type { Route } from "./Route";
|
|
21
|
-
/**
|
|
22
|
-
* Tool execution result
|
|
23
|
-
*/
|
|
24
|
-
export interface ToolExecutionResult {
|
|
25
|
-
toolName: string;
|
|
26
|
-
arguments: Record<string, unknown>;
|
|
27
|
-
result: unknown;
|
|
28
|
-
success: boolean;
|
|
29
|
-
error?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Preparation iteration state
|
|
33
|
-
*/
|
|
34
|
-
export interface IterationState {
|
|
35
|
-
iterationNumber: number;
|
|
36
|
-
matchedGuidelines: GuidelineMatch[];
|
|
37
|
-
executedTools: ToolExecutionResult[];
|
|
38
|
-
contextUpdates: Record<string, unknown>;
|
|
39
|
-
preparedToRespond: boolean;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Preparation context
|
|
43
|
-
*/
|
|
44
|
-
export interface PreparationContext<TContext = unknown> {
|
|
45
|
-
history: Event[];
|
|
46
|
-
currentState?: StateRef;
|
|
47
|
-
context: TContext;
|
|
48
|
-
routes: Route<TContext>[];
|
|
49
|
-
guidelines: Guideline[];
|
|
50
|
-
maxIterations: number;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Preparation result
|
|
54
|
-
*/
|
|
55
|
-
export interface PreparationResult<TContext = unknown> {
|
|
56
|
-
iterations: IterationState[];
|
|
57
|
-
finalContext: TContext;
|
|
58
|
-
toolExecutions: ToolExecutionResult[];
|
|
59
|
-
preparedToRespond: boolean;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* PreparationEngine - Executes the preparation iteration loop
|
|
63
|
-
*/
|
|
64
|
-
export interface PreparationEngineOptions {
|
|
65
|
-
maxParallelLlmCalls?: number;
|
|
66
|
-
maxParallelTools?: number;
|
|
67
|
-
}
|
|
68
|
-
export declare class PreparationEngine<TContext = unknown> {
|
|
69
|
-
private readonly conditionEvaluator?;
|
|
70
|
-
private readonly maxParallelLlmCalls;
|
|
71
|
-
private readonly maxParallelTools;
|
|
72
|
-
/**
|
|
73
|
-
* Run a list of async jobs with a concurrency limit, preserving order of results.
|
|
74
|
-
*/
|
|
75
|
-
private processWithConcurrency;
|
|
76
|
-
constructor(ai?: AiProvider, options?: PreparationEngineOptions);
|
|
77
|
-
/**
|
|
78
|
-
* Run preparation iterations before message generation
|
|
79
|
-
*
|
|
80
|
-
* This is the core engine that executes tools automatically
|
|
81
|
-
* based on state machine transitions and guideline matching.
|
|
82
|
-
*/
|
|
83
|
-
prepare(preparationContext: PreparationContext<TContext>): Promise<PreparationResult<TContext>>;
|
|
84
|
-
/**
|
|
85
|
-
* Run a single preparation iteration
|
|
86
|
-
*/
|
|
87
|
-
private runIteration;
|
|
88
|
-
/**
|
|
89
|
-
* Match guidelines against current context
|
|
90
|
-
*
|
|
91
|
-
* Evaluates guideline conditions against the current context and history
|
|
92
|
-
* using AI to determine relevance and priority
|
|
93
|
-
*/
|
|
94
|
-
private matchGuidelines;
|
|
95
|
-
/**
|
|
96
|
-
* Execute a single tool
|
|
97
|
-
*/
|
|
98
|
-
private executeTool;
|
|
99
|
-
/**
|
|
100
|
-
* Execute tool transitions in the state machine
|
|
101
|
-
*
|
|
102
|
-
* Walks through state transitions and executes tools when
|
|
103
|
-
* reaching a { toolState: tool } transition
|
|
104
|
-
*/
|
|
105
|
-
private executeStateToolTransitions;
|
|
106
|
-
/**
|
|
107
|
-
* Walk through a chain of states, executing tools along the way
|
|
108
|
-
*/
|
|
109
|
-
private walkStateChain;
|
|
110
|
-
/**
|
|
111
|
-
* Evaluate a transition condition
|
|
112
|
-
*/
|
|
113
|
-
private evaluateTransitionCondition;
|
|
114
|
-
}
|
|
115
|
-
export type _Internal = unknown;
|
|
116
|
-
//# sourceMappingURL=PreparationEngine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PreparationEngine.d.ts","sourceRoot":"","sources":["../../src/core/PreparationEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;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