@yugenlab/vaayu 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <p align="center">
2
+ <img src="assets/logos/vaayu-logo.png" alt="Vaayu Logo" width="360" />
3
+ </p>
4
+
1
5
  # VAAYU (वायु)
2
6
 
3
7
  **Like wind — swift, everywhere, carrying what matters.**
@@ -93,6 +97,22 @@ flowchart TB
93
97
 
94
98
  For full ASCII flow/state diagrams and concrete examples, see `docs/architecture.md`.
95
99
 
100
+ ### English-First Naming
101
+
102
+ For public docs and onboarding, use English names first:
103
+
104
+ | English (preferred) | Internal codename |
105
+ |------|------|
106
+ | NLU Engine | Saraswati |
107
+ | Planner | Brahma |
108
+ | Policy Gateway | Hanuman |
109
+ | Guardrail Manager | Vyasa |
110
+ | Tool Executor | Vishwakarma |
111
+ | Memory System | Smriti |
112
+ | Multi-Agent Broker | Kaala |
113
+
114
+ Full map (including Chitragupta names): `docs/aliases.md`.
115
+
96
116
  ---
97
117
 
98
118
  ## Quick Start
@@ -0,0 +1,147 @@
1
+ import "./chunk-IGKYKEKT.js";
2
+
3
+ // apps/gateway/dist/agent/agentic-tool-loop.js
4
+ async function runAgenticToolLoop(params) {
5
+ const { initialContent, initialModel, contextMessages, tools, getToolRegistration, isToolAllowed, reChat, maxIterations, signal, logger, sessionId } = params;
6
+ let currentToolCalls = params.toolCalls;
7
+ let allToolResults = [];
8
+ const accumulatedMessages = [...contextMessages];
9
+ let finalContent = initialContent;
10
+ let finalModel = initialModel;
11
+ let iteration = 0;
12
+ while (currentToolCalls.length > 0 && iteration < maxIterations) {
13
+ iteration++;
14
+ if (signal?.aborted) {
15
+ logger.info("agentic_loop_aborted", { sessionId, iteration });
16
+ break;
17
+ }
18
+ accumulatedMessages.push({
19
+ role: "assistant",
20
+ content: finalContent,
21
+ toolCalls: currentToolCalls
22
+ });
23
+ const iterationResults = [];
24
+ for (const call of currentToolCalls) {
25
+ const callId = call.id ?? `call_${call.name}_${iteration}`;
26
+ if (!isToolAllowed(call.name)) {
27
+ const errorMsg = `Tool "${call.name}" is not allowed by current policy.`;
28
+ logger.warn("agentic_tool_blocked", { sessionId, tool: call.name, iteration });
29
+ iterationResults.push({
30
+ name: call.name,
31
+ input: call.input,
32
+ output: { error: errorMsg },
33
+ ok: false,
34
+ callId
35
+ });
36
+ accumulatedMessages.push({
37
+ role: "tool",
38
+ content: JSON.stringify({ error: errorMsg }),
39
+ name: call.name,
40
+ toolCallId: callId
41
+ });
42
+ continue;
43
+ }
44
+ const registration = getToolRegistration(call.name);
45
+ if (!registration) {
46
+ const errorMsg = `Tool "${call.name}" not found in registry.`;
47
+ logger.warn("agentic_tool_not_found", { sessionId, tool: call.name, iteration });
48
+ iterationResults.push({
49
+ name: call.name,
50
+ input: call.input,
51
+ output: { error: errorMsg },
52
+ ok: false,
53
+ callId
54
+ });
55
+ accumulatedMessages.push({
56
+ role: "tool",
57
+ content: JSON.stringify({ error: errorMsg }),
58
+ name: call.name,
59
+ toolCallId: callId
60
+ });
61
+ continue;
62
+ }
63
+ try {
64
+ const ctx = {
65
+ sessionId,
66
+ signal
67
+ };
68
+ const result = await registration.handler(call.input, ctx);
69
+ const output = result.ok ? result.output : result.error;
70
+ iterationResults.push({
71
+ name: call.name,
72
+ input: call.input,
73
+ output,
74
+ ok: result.ok,
75
+ callId
76
+ });
77
+ accumulatedMessages.push({
78
+ role: "tool",
79
+ content: JSON.stringify(result.ok ? result.output : { error: result.error }),
80
+ name: call.name,
81
+ toolCallId: callId
82
+ });
83
+ logger.info("agentic_tool_executed", {
84
+ sessionId,
85
+ tool: call.name,
86
+ ok: result.ok,
87
+ iteration
88
+ });
89
+ } catch (error) {
90
+ const errorMsg = error instanceof Error ? error.message : String(error);
91
+ logger.warn("agentic_tool_error", {
92
+ sessionId,
93
+ tool: call.name,
94
+ error: errorMsg,
95
+ iteration
96
+ });
97
+ iterationResults.push({
98
+ name: call.name,
99
+ input: call.input,
100
+ output: { error: errorMsg },
101
+ ok: false,
102
+ callId
103
+ });
104
+ accumulatedMessages.push({
105
+ role: "tool",
106
+ content: JSON.stringify({ error: errorMsg }),
107
+ name: call.name,
108
+ toolCallId: callId
109
+ });
110
+ }
111
+ }
112
+ allToolResults = [...allToolResults, ...iterationResults];
113
+ try {
114
+ const response = await reChat(accumulatedMessages, tools);
115
+ finalContent = response.content;
116
+ finalModel = response.model;
117
+ currentToolCalls = response.toolCalls ?? [];
118
+ } catch (error) {
119
+ logger.warn("agentic_rechat_failed", {
120
+ sessionId,
121
+ iteration,
122
+ error: error instanceof Error ? error.message : String(error)
123
+ });
124
+ if (!finalContent && allToolResults.length > 0) {
125
+ finalContent = allToolResults.map((r) => `${r.name}: ${r.ok ? JSON.stringify(r.output) : `Error: ${JSON.stringify(r.output)}`}`).join("\n");
126
+ }
127
+ break;
128
+ }
129
+ }
130
+ if (iteration >= maxIterations && currentToolCalls.length > 0) {
131
+ logger.warn("agentic_loop_max_iterations", {
132
+ sessionId,
133
+ maxIterations,
134
+ remainingToolCalls: currentToolCalls.length
135
+ });
136
+ }
137
+ return {
138
+ finalContent,
139
+ toolResults: allToolResults,
140
+ iterations: iteration,
141
+ finalModel
142
+ };
143
+ }
144
+ export {
145
+ runAgenticToolLoop
146
+ };
147
+ //# sourceMappingURL=agentic-tool-loop-2FZK72JO.js.map