@falai/agent 0.1.0-alpha2 → 0.1.0-alpha3

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.
Files changed (59) hide show
  1. package/README.md +106 -0
  2. package/dist/cjs/src/core/BatchExecutor.d.ts +353 -0
  3. package/dist/cjs/src/core/BatchExecutor.d.ts.map +1 -0
  4. package/dist/cjs/src/core/BatchExecutor.js +842 -0
  5. package/dist/cjs/src/core/BatchExecutor.js.map +1 -0
  6. package/dist/cjs/src/core/BatchPromptBuilder.d.ts +86 -0
  7. package/dist/cjs/src/core/BatchPromptBuilder.d.ts.map +1 -0
  8. package/dist/cjs/src/core/BatchPromptBuilder.js +201 -0
  9. package/dist/cjs/src/core/BatchPromptBuilder.js.map +1 -0
  10. package/dist/cjs/src/core/ResponseModal.d.ts +34 -0
  11. package/dist/cjs/src/core/ResponseModal.d.ts.map +1 -1
  12. package/dist/cjs/src/core/ResponseModal.js +460 -34
  13. package/dist/cjs/src/core/ResponseModal.js.map +1 -1
  14. package/dist/cjs/src/index.d.ts +2 -0
  15. package/dist/cjs/src/index.d.ts.map +1 -1
  16. package/dist/cjs/src/index.js +7 -1
  17. package/dist/cjs/src/index.js.map +1 -1
  18. package/dist/cjs/src/types/agent.d.ts +9 -1
  19. package/dist/cjs/src/types/agent.d.ts.map +1 -1
  20. package/dist/cjs/src/types/route.d.ts +98 -0
  21. package/dist/cjs/src/types/route.d.ts.map +1 -1
  22. package/dist/src/core/BatchExecutor.d.ts +353 -0
  23. package/dist/src/core/BatchExecutor.d.ts.map +1 -0
  24. package/dist/src/core/BatchExecutor.js +837 -0
  25. package/dist/src/core/BatchExecutor.js.map +1 -0
  26. package/dist/src/core/BatchPromptBuilder.d.ts +86 -0
  27. package/dist/src/core/BatchPromptBuilder.d.ts.map +1 -0
  28. package/dist/src/core/BatchPromptBuilder.js +197 -0
  29. package/dist/src/core/BatchPromptBuilder.js.map +1 -0
  30. package/dist/src/core/ResponseModal.d.ts +34 -0
  31. package/dist/src/core/ResponseModal.d.ts.map +1 -1
  32. package/dist/src/core/ResponseModal.js +460 -34
  33. package/dist/src/core/ResponseModal.js.map +1 -1
  34. package/dist/src/index.d.ts +2 -0
  35. package/dist/src/index.d.ts.map +1 -1
  36. package/dist/src/index.js +2 -0
  37. package/dist/src/index.js.map +1 -1
  38. package/dist/src/types/agent.d.ts +9 -1
  39. package/dist/src/types/agent.d.ts.map +1 -1
  40. package/dist/src/types/route.d.ts +98 -0
  41. package/dist/src/types/route.d.ts.map +1 -1
  42. package/docs/api/overview.md +124 -0
  43. package/docs/architecture/multi-step-execution.md +243 -0
  44. package/docs/core/ai-integration/prompt-composition.md +135 -0
  45. package/docs/core/ai-integration/response-processing.md +146 -0
  46. package/docs/core/conversation-flows/data-collection.md +143 -0
  47. package/docs/core/conversation-flows/step-transitions.md +132 -0
  48. package/docs/core/conversation-flows/steps.md +112 -0
  49. package/docs/core/error-handling.md +193 -0
  50. package/docs/guides/getting-started/README.md +102 -0
  51. package/docs/guides/migration/README.md +23 -0
  52. package/docs/guides/migration/multi-step-execution.md +303 -0
  53. package/package.json +4 -2
  54. package/src/core/BatchExecutor.ts +1156 -0
  55. package/src/core/BatchPromptBuilder.ts +275 -0
  56. package/src/core/ResponseModal.ts +605 -35
  57. package/src/index.ts +2 -0
  58. package/src/types/agent.ts +9 -1
  59. package/src/types/route.ts +119 -0
package/src/index.ts CHANGED
@@ -19,6 +19,8 @@ export { adaptEvent, convertHistoryToEvents } from "./core/Events";
19
19
  export { PersistenceManager } from "./core/PersistenceManager";
20
20
  export { SessionManager } from "./core/SessionManager";
21
21
  export { ToolManager, ToolCreationError, ToolExecutionError } from "./core/ToolManager";
22
+ export { BatchExecutor, needsInput, type NeedsInputStep, type DetermineBatchParams } from "./core/BatchExecutor";
23
+ export { BatchPromptBuilder, type BuildBatchPromptParams, type BatchPromptResult } from "./core/BatchPromptBuilder";
22
24
 
23
25
  // Providers
24
26
  export { GeminiProvider } from "./providers/GeminiProvider";
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type { AgentStructuredResponse, AiProvider } from "./ai";
6
6
  import type { Tool } from "./tool";
7
- import type { RouteOptions } from "./route";
7
+ import type { RouteOptions, StepRef, StoppedReason } from "./route";
8
8
  import type { PersistenceConfig } from "./persistence";
9
9
  import type { SessionState } from "./session";
10
10
  import type { StructuredSchema } from "./schema";
@@ -157,6 +157,10 @@ export interface AgentResponse<TData = Record<string, unknown>> {
157
157
  session?: SessionState<TData>;
158
158
  toolCalls?: Array<{ toolName: string; arguments: Record<string, unknown> }>;
159
159
  isRouteComplete?: boolean;
160
+ /** Steps executed in this response (for multi-step execution) */
161
+ executedSteps?: StepRef[];
162
+ /** Why execution stopped (for multi-step execution) */
163
+ stoppedReason?: StoppedReason;
160
164
  }
161
165
 
162
166
  export interface AgentResponseStreamChunk<TData = Record<string, unknown>> {
@@ -166,6 +170,10 @@ export interface AgentResponseStreamChunk<TData = Record<string, unknown>> {
166
170
  session?: SessionState<TData>;
167
171
  toolCalls?: Array<{ toolName: string; arguments: Record<string, unknown> }>;
168
172
  isRouteComplete?: boolean;
173
+ /** Steps executed in this response (for multi-step execution) */
174
+ executedSteps?: StepRef[];
175
+ /** Why execution stopped (for multi-step execution) */
176
+ stoppedReason?: StoppedReason;
169
177
  metadata?: {
170
178
  model?: string;
171
179
  tokensUsed?: number;
@@ -7,6 +7,77 @@ import type { StructuredSchema } from "./schema";
7
7
  import type { Guideline, Term } from "./agent";
8
8
  import { Template, ConditionTemplate } from "./template";
9
9
 
10
+ /**
11
+ * Reason why batch execution stopped
12
+ * Used to indicate the stopping condition for multi-step execution
13
+ */
14
+ export type StoppedReason =
15
+ | 'needs_input' // Step requires uncollected data
16
+ | 'end_route' // Reached END_ROUTE
17
+ | 'route_complete' // All Steps processed
18
+ | 'prepare_error' // Error in prepare hook
19
+ | 'llm_error' // Error during LLM call
20
+ | 'validation_error' // Error validating collected data
21
+ | 'finalize_error'; // Error in finalize hook (non-fatal, logged)
22
+
23
+ /**
24
+ * Event types for batch execution observability
25
+ */
26
+ export type BatchExecutionEventType =
27
+ | 'batch_start'
28
+ | 'step_included'
29
+ | 'step_skipped'
30
+ | 'batch_stop'
31
+ | 'batch_complete';
32
+
33
+ /**
34
+ * Event emitted during batch execution for debugging and observability
35
+ *
36
+ * **Validates: Requirements 11.3**
37
+ */
38
+ export interface BatchExecutionEvent {
39
+ /** Type of batch execution event */
40
+ type: BatchExecutionEventType;
41
+ /** Timestamp when the event occurred */
42
+ timestamp: Date;
43
+ /** Event-specific details */
44
+ details: {
45
+ /** Step ID related to this event (for step_included, step_skipped) */
46
+ stepId?: string;
47
+ /** Reason for the event (e.g., why step was skipped or batch stopped) */
48
+ reason?: string;
49
+ /** Current batch size (for batch_start, batch_complete) */
50
+ batchSize?: number;
51
+ /** Stopped reason (for batch_stop, batch_complete) */
52
+ stoppedReason?: StoppedReason;
53
+ /** Phase timing information (for batch_complete) */
54
+ timing?: BatchExecutionTiming;
55
+ };
56
+ }
57
+
58
+ /**
59
+ * Timing information for batch execution phases
60
+ */
61
+ export interface BatchExecutionTiming {
62
+ /** Total batch execution time in milliseconds */
63
+ totalMs: number;
64
+ /** Time spent in batch determination phase */
65
+ determinationMs?: number;
66
+ /** Time spent executing prepare hooks */
67
+ prepareHooksMs?: number;
68
+ /** Time spent in LLM call */
69
+ llmCallMs?: number;
70
+ /** Time spent collecting data */
71
+ dataCollectionMs?: number;
72
+ /** Time spent executing finalize hooks */
73
+ finalizeHooksMs?: number;
74
+ }
75
+
76
+ /**
77
+ * Callback type for batch execution event listeners
78
+ */
79
+ export type BatchExecutionEventListener = (event: BatchExecutionEvent) => void;
80
+
10
81
  /**
11
82
  * Reference to a route
12
83
  */
@@ -25,6 +96,54 @@ export interface StepRef {
25
96
  routeId: string;
26
97
  }
27
98
 
99
+ /**
100
+ * Result of batch determination - which steps can execute together
101
+ * @template TContext - Type of context data
102
+ * @template TData - Type of collected data
103
+ */
104
+ export interface BatchResult<TContext = unknown, TData = unknown> {
105
+ /** Steps included in this batch */
106
+ steps: StepOptions<TContext, TData>[];
107
+ /** Why the batch stopped */
108
+ stoppedReason: StoppedReason;
109
+ /** The Step that caused the stop (if applicable) */
110
+ stoppedAtStep?: StepOptions<TContext, TData>;
111
+ }
112
+
113
+ /**
114
+ * Error details for batch execution failures
115
+ */
116
+ export interface BatchExecutionError {
117
+ /** Type of error that occurred */
118
+ type: 'pre_extraction' | 'skipif_evaluation' | 'prepare_hook' |
119
+ 'llm_call' | 'data_validation' | 'finalize_hook';
120
+ /** Error message */
121
+ message: string;
122
+ /** Step where error occurred (if applicable) */
123
+ stepId?: string;
124
+ /** Additional error details */
125
+ details?: unknown;
126
+ }
127
+
128
+ /**
129
+ * Result of executing a batch of steps
130
+ * @template TData - Type of collected data
131
+ */
132
+ export interface BatchExecutionResult<TData = unknown> {
133
+ /** The generated message */
134
+ message: string;
135
+ /** Updated session state */
136
+ session: import('./session').SessionState<TData>;
137
+ /** Steps that were executed */
138
+ executedSteps: StepRef[];
139
+ /** Why execution stopped */
140
+ stoppedReason: StoppedReason;
141
+ /** Collected data from the batch */
142
+ collectedData?: Partial<TData>;
143
+ /** Any errors that occurred */
144
+ error?: BatchExecutionError;
145
+ }
146
+
28
147
  /**
29
148
  * Route lifecycle hooks for managing route-specific data and behavior
30
149
  */