@falai/agent 0.9.0-alpha-2 → 0.9.2
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 +42 -34
- package/dist/cjs/src/core/Agent.d.ts +48 -44
- package/dist/cjs/src/core/Agent.d.ts.map +1 -1
- package/dist/cjs/src/core/Agent.js +151 -1110
- package/dist/cjs/src/core/Agent.js.map +1 -1
- package/dist/cjs/src/core/ResponseModal.d.ts +211 -0
- package/dist/cjs/src/core/ResponseModal.d.ts.map +1 -0
- package/dist/cjs/src/core/ResponseModal.js +1394 -0
- package/dist/cjs/src/core/ResponseModal.js.map +1 -0
- package/dist/cjs/src/core/ResponsePipeline.d.ts +8 -4
- package/dist/cjs/src/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/cjs/src/core/ResponsePipeline.js +48 -20
- package/dist/cjs/src/core/ResponsePipeline.js.map +1 -1
- package/dist/cjs/src/core/Route.d.ts +12 -5
- package/dist/cjs/src/core/Route.d.ts.map +1 -1
- package/dist/cjs/src/core/Route.js +26 -5
- package/dist/cjs/src/core/Route.js.map +1 -1
- package/dist/cjs/src/core/RoutingEngine.d.ts +5 -0
- package/dist/cjs/src/core/RoutingEngine.d.ts.map +1 -1
- package/dist/cjs/src/core/RoutingEngine.js +37 -25
- package/dist/cjs/src/core/RoutingEngine.js.map +1 -1
- package/dist/cjs/src/core/SessionManager.d.ts +9 -1
- package/dist/cjs/src/core/SessionManager.d.ts.map +1 -1
- package/dist/cjs/src/core/SessionManager.js +27 -5
- package/dist/cjs/src/core/SessionManager.js.map +1 -1
- package/dist/cjs/src/core/Step.d.ts +60 -7
- package/dist/cjs/src/core/Step.d.ts.map +1 -1
- package/dist/cjs/src/core/Step.js +151 -4
- package/dist/cjs/src/core/Step.js.map +1 -1
- package/dist/cjs/src/core/ToolManager.d.ts +234 -0
- package/dist/cjs/src/core/ToolManager.d.ts.map +1 -0
- package/dist/cjs/src/core/ToolManager.js +1117 -0
- package/dist/cjs/src/core/ToolManager.js.map +1 -0
- package/dist/cjs/src/index.d.ts +5 -4
- package/dist/cjs/src/index.d.ts.map +1 -1
- package/dist/cjs/src/index.js +11 -3
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/types/agent.d.ts +2 -1
- package/dist/cjs/src/types/agent.d.ts.map +1 -1
- package/dist/cjs/src/types/ai.d.ts +1 -1
- package/dist/cjs/src/types/ai.d.ts.map +1 -1
- package/dist/cjs/src/types/index.d.ts +3 -2
- package/dist/cjs/src/types/index.d.ts.map +1 -1
- package/dist/cjs/src/types/index.js +3 -1
- package/dist/cjs/src/types/index.js.map +1 -1
- package/dist/cjs/src/types/route.d.ts +6 -4
- package/dist/cjs/src/types/route.d.ts.map +1 -1
- package/dist/cjs/src/types/tool.d.ts +84 -14
- package/dist/cjs/src/types/tool.d.ts.map +1 -1
- package/dist/cjs/src/types/tool.js +13 -0
- package/dist/cjs/src/types/tool.js.map +1 -1
- package/dist/cjs/src/utils/clone.d.ts.map +1 -1
- package/dist/cjs/src/utils/clone.js +0 -4
- package/dist/cjs/src/utils/clone.js.map +1 -1
- package/dist/cjs/src/utils/history.d.ts +30 -1
- package/dist/cjs/src/utils/history.d.ts.map +1 -1
- package/dist/cjs/src/utils/history.js +169 -23
- package/dist/cjs/src/utils/history.js.map +1 -1
- package/dist/cjs/src/utils/index.d.ts +1 -1
- package/dist/cjs/src/utils/index.d.ts.map +1 -1
- package/dist/cjs/src/utils/index.js +5 -1
- package/dist/cjs/src/utils/index.js.map +1 -1
- package/dist/src/core/Agent.d.ts +48 -44
- package/dist/src/core/Agent.d.ts.map +1 -1
- package/dist/src/core/Agent.js +152 -1111
- package/dist/src/core/Agent.js.map +1 -1
- package/dist/src/core/ResponseModal.d.ts +211 -0
- package/dist/src/core/ResponseModal.d.ts.map +1 -0
- package/dist/src/core/ResponseModal.js +1389 -0
- package/dist/src/core/ResponseModal.js.map +1 -0
- package/dist/src/core/ResponsePipeline.d.ts +8 -4
- package/dist/src/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/src/core/ResponsePipeline.js +48 -20
- package/dist/src/core/ResponsePipeline.js.map +1 -1
- package/dist/src/core/Route.d.ts +12 -5
- package/dist/src/core/Route.d.ts.map +1 -1
- package/dist/src/core/Route.js +26 -5
- package/dist/src/core/Route.js.map +1 -1
- package/dist/src/core/RoutingEngine.d.ts +5 -0
- package/dist/src/core/RoutingEngine.d.ts.map +1 -1
- package/dist/src/core/RoutingEngine.js +37 -25
- package/dist/src/core/RoutingEngine.js.map +1 -1
- package/dist/src/core/SessionManager.d.ts +9 -1
- package/dist/src/core/SessionManager.d.ts.map +1 -1
- package/dist/src/core/SessionManager.js +27 -5
- package/dist/src/core/SessionManager.js.map +1 -1
- package/dist/src/core/Step.d.ts +60 -7
- package/dist/src/core/Step.d.ts.map +1 -1
- package/dist/src/core/Step.js +151 -4
- package/dist/src/core/Step.js.map +1 -1
- package/dist/src/core/ToolManager.d.ts +234 -0
- package/dist/src/core/ToolManager.d.ts.map +1 -0
- package/dist/src/core/ToolManager.js +1111 -0
- package/dist/src/core/ToolManager.js.map +1 -0
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/types/agent.d.ts +2 -1
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/ai.d.ts +1 -1
- package/dist/src/types/ai.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +3 -2
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +1 -0
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/route.d.ts +6 -4
- package/dist/src/types/route.d.ts.map +1 -1
- package/dist/src/types/tool.d.ts +84 -14
- package/dist/src/types/tool.d.ts.map +1 -1
- package/dist/src/types/tool.js +12 -1
- package/dist/src/types/tool.js.map +1 -1
- package/dist/src/utils/clone.d.ts.map +1 -1
- package/dist/src/utils/clone.js +0 -4
- package/dist/src/utils/clone.js.map +1 -1
- package/dist/src/utils/history.d.ts +30 -1
- package/dist/src/utils/history.d.ts.map +1 -1
- package/dist/src/utils/history.js +165 -23
- package/dist/src/utils/history.js.map +1 -1
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +1 -1
- package/dist/src/utils/index.js.map +1 -1
- package/docs/CONTRIBUTING.md +40 -0
- package/docs/README.md +14 -6
- package/docs/api/README.md +235 -45
- package/docs/api/overview.md +140 -33
- package/docs/core/agent/session-management.md +152 -5
- package/docs/core/ai-integration/response-processing.md +115 -4
- package/docs/core/conversation-flows/routes.md +130 -0
- package/docs/core/error-handling.md +638 -0
- package/docs/core/tools/tool-definition.md +684 -60
- package/docs/core/tools/tool-scoping.md +244 -53
- package/docs/guides/error-handling-patterns.md +578 -0
- package/docs/guides/getting-started/README.md +139 -28
- package/docs/guides/migration/README.md +72 -0
- package/docs/guides/migration/response-modal-refactor.md +518 -0
- package/examples/advanced-patterns/knowledge-based-agent.ts +6 -6
- package/examples/advanced-patterns/persistent-onboarding.ts +30 -43
- package/examples/advanced-patterns/streaming-responses.ts +169 -96
- package/examples/ai-providers/anthropic-integration.ts +9 -5
- package/examples/ai-providers/openai-integration.ts +11 -7
- package/examples/core-concepts/basic-agent.ts +106 -67
- package/examples/core-concepts/modern-streaming-api.ts +309 -0
- package/examples/core-concepts/schema-driven-extraction.ts +10 -7
- package/examples/core-concepts/session-management.ts +71 -18
- package/examples/integrations/healthcare-integration.ts +15 -29
- package/examples/integrations/server-session-management.ts +3 -3
- package/examples/persistence/memory-sessions.ts +3 -3
- package/examples/tools/basic-tools.ts +293 -89
- package/examples/tools/data-enrichment-tools.ts +185 -75
- package/package.json +1 -1
- package/src/core/Agent.ts +190 -1529
- package/src/core/ResponseModal.ts +1798 -0
- package/src/core/ResponsePipeline.ts +83 -57
- package/src/core/Route.ts +39 -12
- package/src/core/RoutingEngine.ts +46 -42
- package/src/core/SessionManager.ts +39 -7
- package/src/core/Step.ts +198 -20
- package/src/core/ToolManager.ts +1394 -0
- package/src/index.ts +19 -3
- package/src/types/agent.ts +2 -1
- package/src/types/ai.ts +1 -1
- package/src/types/index.ts +13 -2
- package/src/types/route.ts +6 -4
- package/src/types/tool.ts +116 -25
- package/src/utils/clone.ts +6 -8
- package/src/utils/history.ts +190 -27
- package/src/utils/index.ts +4 -0
- package/dist/cjs/src/core/ToolExecutor.d.ts +0 -45
- package/dist/cjs/src/core/ToolExecutor.d.ts.map +0 -1
- package/dist/cjs/src/core/ToolExecutor.js +0 -84
- package/dist/cjs/src/core/ToolExecutor.js.map +0 -1
- package/dist/src/core/ToolExecutor.d.ts +0 -45
- package/dist/src/core/ToolExecutor.d.ts.map +0 -1
- package/dist/src/core/ToolExecutor.js +0 -80
- package/dist/src/core/ToolExecutor.js.map +0 -1
- package/docs/core/tools/tool-execution.md +0 -815
- package/src/core/ToolExecutor.ts +0 -126
|
@@ -1,37 +1,123 @@
|
|
|
1
|
-
# Tool Scoping &
|
|
1
|
+
# Tool Scoping & Registry System
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The unified Tool interface supports sophisticated hierarchical scoping with a central registry that enables fine-grained control over tool availability and access. Tools can be registered globally for reuse or added to specific scopes (agent, route, step) with intelligent resolution and security controls.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The scoping system provides:
|
|
7
|
+
The unified Tool scoping and registry system provides:
|
|
8
8
|
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
9
|
+
- **Central Tool Registry**: Global registry for reusable tools referenced by ID across contexts
|
|
10
|
+
- **Hierarchical Scoping**: Agent → Route → Step level tool definitions with clear priority
|
|
11
|
+
- **Intelligent Resolution**: Automatic tool lookup across scopes with fallback to registry
|
|
12
|
+
- **Flexible Returns**: Support for both simple return values and complex ToolResult objects
|
|
13
|
+
- **Security Boundaries**: Fine-grained access control based on context and permissions
|
|
14
|
+
- **Performance Optimization**: Efficient tool evaluation limited to relevant contexts
|
|
15
|
+
- **Conflict Resolution**: Predictable tool selection when IDs conflict across scopes
|
|
16
|
+
- **Dynamic Availability**: Conditional tool access based on runtime context
|
|
14
17
|
|
|
15
|
-
## Scoping Hierarchy
|
|
18
|
+
## Tool Scoping Hierarchy
|
|
16
19
|
|
|
17
|
-
###
|
|
20
|
+
### Central Tool Registry
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
The system maintains a central registry for tools that can be referenced by ID across different contexts:
|
|
20
23
|
|
|
21
24
|
```typescript
|
|
25
|
+
import { Agent, GeminiProvider } from "@falai/agent";
|
|
26
|
+
|
|
22
27
|
const agent = new Agent({
|
|
23
28
|
name: "Multi-Purpose Agent",
|
|
24
|
-
provider:
|
|
29
|
+
provider: new GeminiProvider({
|
|
30
|
+
apiKey: process.env.GEMINI_API_KEY!,
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
// Register tools in the central registry for reuse
|
|
35
|
+
agent.tool.register({
|
|
36
|
+
id: "global_search",
|
|
37
|
+
name: "Universal Search",
|
|
38
|
+
description: "Search across all available data sources",
|
|
39
|
+
parameters: {
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
query: { type: "string", description: "Search query" },
|
|
43
|
+
scope: { type: "string", enum: ["all", "documents", "users"], default: "all" },
|
|
44
|
+
},
|
|
45
|
+
required: ["query"],
|
|
46
|
+
},
|
|
47
|
+
handler: async ({ context, data }, args) => {
|
|
48
|
+
const results = await searchService.search(args.query, args.scope);
|
|
49
|
+
return `Found ${results.length} results for "${args.query}"`; // Simple return value
|
|
50
|
+
},
|
|
51
|
+
});
|
|
32
52
|
|
|
33
|
-
|
|
53
|
+
agent.tool.register({
|
|
54
|
+
id: "user_profile_manager",
|
|
55
|
+
name: "User Profile Manager",
|
|
56
|
+
description: "Manage user profile operations",
|
|
57
|
+
parameters: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
action: { type: "string", enum: ["get", "update", "delete"] },
|
|
61
|
+
userId: { type: "string", description: "User ID" },
|
|
62
|
+
updates: { type: "object", description: "Profile updates for update action" },
|
|
63
|
+
},
|
|
64
|
+
required: ["action"],
|
|
65
|
+
},
|
|
66
|
+
handler: async ({ context, data }, args) => {
|
|
67
|
+
const result = await userService.manageProfile(args.action, args.userId, args.updates);
|
|
68
|
+
return {
|
|
69
|
+
data: `Profile ${args.action} completed`,
|
|
70
|
+
success: true,
|
|
71
|
+
contextUpdate: { lastProfileAction: args.action }
|
|
72
|
+
}; // Complex ToolResult pattern
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Register multiple tools at once for efficiency
|
|
77
|
+
agent.tool.registerMany([
|
|
78
|
+
{
|
|
79
|
+
id: "system_health_check",
|
|
80
|
+
description: "Check system health and status",
|
|
81
|
+
handler: async () => {
|
|
82
|
+
const health = await systemService.checkHealth();
|
|
83
|
+
return `System status: ${health.status}`; // Simple return
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "audit_logger",
|
|
88
|
+
description: "Create audit log entries",
|
|
89
|
+
handler: async ({ context }, args) => {
|
|
90
|
+
await auditService.log(context.userId, args.action, args.details);
|
|
91
|
+
return {
|
|
92
|
+
data: "Audit entry created",
|
|
93
|
+
contextUpdate: { lastAuditAction: args.action }
|
|
94
|
+
}; // ToolResult with context update
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
// Check registry status
|
|
100
|
+
console.log("Registered tools:", Array.from(agent.tool.getRegistered().keys()));
|
|
101
|
+
console.log("Is search registered?", agent.tool.isRegistered("global_search"));
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Agent-Level Tools
|
|
105
|
+
|
|
106
|
+
Available to all routes and steps within the agent:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// Add tools directly to agent scope - simple return value
|
|
110
|
+
agent.addTool({
|
|
111
|
+
id: "agent_search",
|
|
112
|
+
description: "Agent-wide search functionality",
|
|
113
|
+
handler: async ({ context, data }) => {
|
|
114
|
+
return "Agent search results"; // Simple return
|
|
115
|
+
},
|
|
34
116
|
});
|
|
117
|
+
|
|
118
|
+
// All routes can access agent-level tools
|
|
119
|
+
const route1 = agent.createRoute({ title: "Route 1" });
|
|
120
|
+
const route2 = agent.createRoute({ title: "Route 2" });
|
|
35
121
|
```
|
|
36
122
|
|
|
37
123
|
**Use Cases:**
|
|
@@ -47,15 +133,35 @@ Specific to a single route and its steps:
|
|
|
47
133
|
```typescript
|
|
48
134
|
const supportRoute = agent.createRoute({
|
|
49
135
|
title: "Customer Support",
|
|
136
|
+
});
|
|
50
137
|
|
|
51
|
-
|
|
52
|
-
|
|
138
|
+
// Add tools to route scope - mixed return patterns
|
|
139
|
+
supportRoute.addTool({
|
|
140
|
+
id: "create_ticket",
|
|
141
|
+
description: "Create support ticket",
|
|
142
|
+
handler: async ({ context, data }) => {
|
|
143
|
+
const ticketId = await ticketService.create(data);
|
|
144
|
+
return {
|
|
145
|
+
data: "Ticket created successfully",
|
|
146
|
+
success: true,
|
|
147
|
+
dataUpdate: { ticketId: ticketId }
|
|
148
|
+
}; // Complex ToolResult
|
|
149
|
+
},
|
|
150
|
+
});
|
|
53
151
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
152
|
+
supportRoute.addTool({
|
|
153
|
+
id: "search_knowledge",
|
|
154
|
+
description: "Search knowledge base",
|
|
155
|
+
handler: async ({ context, data }) => {
|
|
156
|
+
const results = await knowledgeBase.search(data.query);
|
|
157
|
+
return `Found ${results.length} knowledge articles`; // Simple return
|
|
57
158
|
},
|
|
58
159
|
});
|
|
160
|
+
|
|
161
|
+
const initialStep = supportRoute.initialStep.nextStep({
|
|
162
|
+
prompt: "How can I help you?",
|
|
163
|
+
tools: ["create_ticket", "search_knowledge"], // Reference by ID
|
|
164
|
+
});
|
|
59
165
|
```
|
|
60
166
|
|
|
61
167
|
**Use Cases:**
|
|
@@ -69,15 +175,35 @@ const supportRoute = agent.createRoute({
|
|
|
69
175
|
Limited to a specific conversation step:
|
|
70
176
|
|
|
71
177
|
```typescript
|
|
72
|
-
const dataCollectionStep = {
|
|
178
|
+
const dataCollectionStep = supportRoute.initialStep.nextStep({
|
|
73
179
|
prompt: "Please provide your payment information",
|
|
74
180
|
collect: ["paymentDetails"],
|
|
75
|
-
|
|
76
|
-
// Available ONLY in this step
|
|
77
|
-
tools: [paymentValidationTool, fraudCheckTool, secureStorageTool],
|
|
78
|
-
|
|
79
181
|
requires: ["userConsent", "securityVerified"],
|
|
80
|
-
}
|
|
182
|
+
}).addTool({
|
|
183
|
+
id: "validate_payment",
|
|
184
|
+
description: "Validate payment information",
|
|
185
|
+
handler: async ({ context, data }) => {
|
|
186
|
+
const isValid = await paymentValidator.validate(data.paymentDetails);
|
|
187
|
+
return isValid ? "Payment validated successfully" : "Payment validation failed"; // Simple return
|
|
188
|
+
},
|
|
189
|
+
}).addTool({
|
|
190
|
+
id: "fraud_check",
|
|
191
|
+
description: "Perform fraud detection",
|
|
192
|
+
handler: async ({ context, data }) => {
|
|
193
|
+
const fraudResult = await fraudDetector.check(data.paymentDetails);
|
|
194
|
+
return {
|
|
195
|
+
data: fraudResult.passed ? "Fraud check passed" : "Fraud detected",
|
|
196
|
+
success: fraudResult.passed,
|
|
197
|
+
contextUpdate: { fraudScore: fraudResult.score }
|
|
198
|
+
}; // Complex ToolResult with security data
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Or reference registered tools by ID
|
|
203
|
+
const secureStep = route.initialStep.nextStep({
|
|
204
|
+
prompt: "Processing secure operation...",
|
|
205
|
+
tools: ['registered_security_tool'], // Reference by ID
|
|
206
|
+
});
|
|
81
207
|
```
|
|
82
208
|
|
|
83
209
|
**Use Cases:**
|
|
@@ -90,40 +216,105 @@ const dataCollectionStep = {
|
|
|
90
216
|
|
|
91
217
|
### Priority Order
|
|
92
218
|
|
|
93
|
-
|
|
219
|
+
ToolManager resolves tools with the following priority:
|
|
94
220
|
|
|
95
221
|
```typescript
|
|
96
|
-
// 1. Step-level tools (highest priority)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
agent.tools.find((tool) => tool.id === toolId || tool.name === toolId);
|
|
222
|
+
// 1. Step-level inline tools (highest priority)
|
|
223
|
+
// 2. Step-level tool references (by ID) → Registry lookup
|
|
224
|
+
// 3. Route-level tools
|
|
225
|
+
// 4. Agent-level tools
|
|
226
|
+
// 5. Registered tools (fallback for unresolved IDs)
|
|
102
227
|
```
|
|
103
228
|
|
|
104
|
-
###
|
|
229
|
+
### Tool Resolution Example
|
|
230
|
+
|
|
231
|
+
The system resolves tools with clear priority rules and intelligent fallback to the registry:
|
|
105
232
|
|
|
106
233
|
```typescript
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
234
|
+
import { Agent, GeminiProvider } from "@falai/agent";
|
|
235
|
+
|
|
236
|
+
const agent = new Agent({
|
|
237
|
+
name: "Resolution Demo",
|
|
238
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY! })
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// 1. Register tool in central registry
|
|
242
|
+
agent.tool.register({
|
|
243
|
+
id: "search",
|
|
244
|
+
description: "Registry-based search with fallback capability",
|
|
245
|
+
handler: async ({ context, data }, args) => "Registry search executed", // Simple return
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// 2. Add agent-level tool (overrides registry for this agent)
|
|
249
|
+
agent.addTool({
|
|
250
|
+
id: "search",
|
|
251
|
+
description: "Agent-wide search functionality",
|
|
252
|
+
handler: async ({ context, data }, args) => ({
|
|
253
|
+
data: "Agent search executed",
|
|
254
|
+
contextUpdate: { lastSearchLevel: "agent" }
|
|
255
|
+
}), // ToolResult pattern
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const route = agent.createRoute({ title: "Support Route" });
|
|
259
|
+
|
|
260
|
+
// 3. Add route-level tool (overrides agent-level for this route)
|
|
261
|
+
route.addTool({
|
|
262
|
+
id: "search",
|
|
263
|
+
description: "Route-specific search",
|
|
264
|
+
handler: async ({ context, data }, args) => "Route search executed", // Simple return
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// 4. Step with inline tool (highest priority)
|
|
268
|
+
const step = route.initialStep.nextStep({
|
|
269
|
+
prompt: "What would you like to search for?",
|
|
270
|
+
tools: [
|
|
110
271
|
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
272
|
+
id: "search",
|
|
273
|
+
description: "Step-specific search with custom logic",
|
|
274
|
+
handler: async ({ context, data }, args) => ({
|
|
275
|
+
data: "Step search executed",
|
|
276
|
+
success: true,
|
|
277
|
+
dataUpdate: { lastStepSearch: new Date() }
|
|
278
|
+
}), // Advanced ToolResult
|
|
117
279
|
},
|
|
118
280
|
],
|
|
119
281
|
});
|
|
120
282
|
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
283
|
+
// 5. Step referencing registered tool by ID
|
|
284
|
+
const registryStep = route.initialStep.nextStep({
|
|
285
|
+
prompt: "Using registry search...",
|
|
286
|
+
tools: ['global_search'] // References registered tool by ID
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Resolution Priority (highest to lowest):
|
|
290
|
+
// 1. Step-level inline tools → "Step search executed"
|
|
291
|
+
// 2. Step-level tool references (by ID) → Registry lookup
|
|
292
|
+
// 3. Route-level tools → "Route search executed"
|
|
293
|
+
// 4. Agent-level tools → "Agent search executed"
|
|
294
|
+
// 5. Registry fallback → "Registry search executed"
|
|
295
|
+
|
|
296
|
+
// Test resolution
|
|
297
|
+
const foundTool = agent.tool.find('search');
|
|
298
|
+
console.log("Resolved tool:", foundTool?.description);
|
|
299
|
+
|
|
300
|
+
// Get all available tools for current context
|
|
301
|
+
const availableTools = agent.tool.getAvailable();
|
|
302
|
+
console.log("Available tools:", availableTools.map(t => t.id));
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Using Tool Resolution
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
// Find tool across all scopes
|
|
309
|
+
const tool = agent.tool.find('search');
|
|
310
|
+
|
|
311
|
+
// Get available tools for current context
|
|
312
|
+
const availableTools = agent.tool.getAvailable();
|
|
313
|
+
|
|
314
|
+
// Check if tool is registered
|
|
315
|
+
if (agent.tool.isRegistered('search')) {
|
|
316
|
+
console.log('Tool available in registry');
|
|
317
|
+
}
|
|
127
318
|
```
|
|
128
319
|
|
|
129
320
|
## Dynamic Tool Availability
|