@xano/developer-mcp 1.0.26 → 1.0.27
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/dist/xanoscript_docs/README.md +78 -64
- package/dist/xanoscript_docs/apis.md +81 -27
- package/dist/xanoscript_docs/branch.md +13 -13
- package/dist/xanoscript_docs/database.md +57 -17
- package/dist/xanoscript_docs/functions.md +43 -71
- package/dist/xanoscript_docs/performance.md +14 -23
- package/dist/xanoscript_docs/tables.md +47 -1
- package/dist/xanoscript_docs/tools.md +9 -7
- package/dist/xanoscript_docs/types.md +12 -10
- package/package.json +1 -1
- package/dist/api_docs/format.d.ts +0 -5
- package/dist/api_docs/format.js +0 -171
- package/dist/api_docs/index.d.ts +0 -52
- package/dist/api_docs/index.js +0 -111
- package/dist/api_docs/topics/agent.d.ts +0 -2
- package/dist/api_docs/topics/agent.js +0 -142
- package/dist/api_docs/topics/api.d.ts +0 -2
- package/dist/api_docs/topics/api.js +0 -176
- package/dist/api_docs/topics/apigroup.d.ts +0 -2
- package/dist/api_docs/topics/apigroup.js +0 -124
- package/dist/api_docs/topics/authentication.d.ts +0 -2
- package/dist/api_docs/topics/authentication.js +0 -61
- package/dist/api_docs/topics/branch.d.ts +0 -2
- package/dist/api_docs/topics/branch.js +0 -73
- package/dist/api_docs/topics/file.d.ts +0 -2
- package/dist/api_docs/topics/file.js +0 -70
- package/dist/api_docs/topics/function.d.ts +0 -2
- package/dist/api_docs/topics/function.js +0 -164
- package/dist/api_docs/topics/history.d.ts +0 -2
- package/dist/api_docs/topics/history.js +0 -149
- package/dist/api_docs/topics/mcp_server.d.ts +0 -2
- package/dist/api_docs/topics/mcp_server.js +0 -139
- package/dist/api_docs/topics/middleware.d.ts +0 -2
- package/dist/api_docs/topics/middleware.js +0 -156
- package/dist/api_docs/topics/realtime.d.ts +0 -2
- package/dist/api_docs/topics/realtime.js +0 -112
- package/dist/api_docs/topics/start.d.ts +0 -2
- package/dist/api_docs/topics/start.js +0 -107
- package/dist/api_docs/topics/table.d.ts +0 -2
- package/dist/api_docs/topics/table.js +0 -195
- package/dist/api_docs/topics/task.d.ts +0 -2
- package/dist/api_docs/topics/task.js +0 -165
- package/dist/api_docs/topics/tool.d.ts +0 -2
- package/dist/api_docs/topics/tool.js +0 -150
- package/dist/api_docs/topics/workflows.d.ts +0 -2
- package/dist/api_docs/topics/workflows.js +0 -131
- package/dist/api_docs/topics/workspace.d.ts +0 -2
- package/dist/api_docs/topics/workspace.js +0 -153
- package/dist/api_docs/types.d.ts +0 -79
- package/dist/api_docs/types.js +0 -4
- package/dist/templates/init-workspace.d.ts +0 -10
- package/dist/templates/init-workspace.js +0 -278
- package/dist/templates/xanoscript-index.d.ts +0 -11
- package/dist/templates/xanoscript-index.js +0 -72
- package/dist/xanoscript_docs/ephemeral.md +0 -330
- package/dist/xanoscript_docs_auto/README.md +0 -119
- package/dist/xanoscript_docs_auto/agents.md +0 -446
- package/dist/xanoscript_docs_auto/apis.md +0 -517
- package/dist/xanoscript_docs_auto/control-flow.md +0 -543
- package/dist/xanoscript_docs_auto/database.md +0 -551
- package/dist/xanoscript_docs_auto/debugging.md +0 -527
- package/dist/xanoscript_docs_auto/filters.md +0 -464
- package/dist/xanoscript_docs_auto/functions.md +0 -431
- package/dist/xanoscript_docs_auto/integrations.md +0 -657
- package/dist/xanoscript_docs_auto/mcp-servers.md +0 -408
- package/dist/xanoscript_docs_auto/operators.md +0 -368
- package/dist/xanoscript_docs_auto/syntax.md +0 -287
- package/dist/xanoscript_docs_auto/tables.md +0 -447
- package/dist/xanoscript_docs_auto/tasks.md +0 -479
- package/dist/xanoscript_docs_auto/testing.md +0 -574
- package/dist/xanoscript_docs_auto/tools.md +0 -485
- package/dist/xanoscript_docs_auto/triggers.md +0 -595
- package/dist/xanoscript_docs_auto/types.md +0 -323
- package/dist/xanoscript_docs_auto/variables.md +0 -462
- package/dist/xanoscript_docs_auto/version.json +0 -5
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# XanoScript Complete Reference
|
|
2
|
-
|
|
3
|
-
XanoScript is a declarative, statically-typed scripting language for [Xano](https://xano.com). It enables developers to build API endpoints, functions, scheduled tasks, database operations, and AI agents with structured, readable syntax.
|
|
4
|
-
|
|
5
|
-
## Quick Reference
|
|
6
|
-
|
|
7
|
-
### Top-Level Object Types
|
|
8
|
-
|
|
9
|
-
| Type | File Location | Purpose |
|
|
10
|
-
|------|---------------|---------|
|
|
11
|
-
| `query` | `apis/<group>/*.xs` | HTTP API endpoints with verbs, input, processing, response |
|
|
12
|
-
| `function` | `functions/**/*.xs` | Reusable logic blocks with optional testing |
|
|
13
|
-
| `task` | `tasks/*.xs` | Scheduled operations with cron-like triggers |
|
|
14
|
-
| `table` | `tables/*.xs` | Database schema definitions |
|
|
15
|
-
| `table_trigger` | `triggers/**/*.xs` | Trigger handlers for database events |
|
|
16
|
-
| `agent` | `agents/**/*.xs` | AI agent definitions |
|
|
17
|
-
| `tool` | `tools/**/*.xs` | Tool definitions for AI agents |
|
|
18
|
-
| `mcp_server` | `mcp_servers/**/*.xs` | Model Context Protocol server definitions |
|
|
19
|
-
| `middleware` | `middleware/**/*.xs` | Request/response interceptors |
|
|
20
|
-
| `addon` | `addons/*.xs` | Subqueries for related data |
|
|
21
|
-
| `branch` | `branch.xs` | Branch-level configuration |
|
|
22
|
-
| `workspace` | `workspace.xs` | Workspace-level settings |
|
|
23
|
-
| `realtime_channel` | Configuration | Real-time channel definitions |
|
|
24
|
-
| `api_group` | `apis/<group>/` | Collections of related API endpoints |
|
|
25
|
-
|
|
26
|
-
**Important:** Each `.xs` file must contain exactly one definition.
|
|
27
|
-
|
|
28
|
-
### Block Structure
|
|
29
|
-
|
|
30
|
-
```xs
|
|
31
|
-
<construct> "<name>" {
|
|
32
|
-
input { ... } // Parameters (optional)
|
|
33
|
-
stack { ... } // Logic
|
|
34
|
-
response = $var // Output
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### Variable Access
|
|
39
|
-
|
|
40
|
-
```xs
|
|
41
|
-
$input.field // Input parameters
|
|
42
|
-
$var.name // Stack variables (in some contexts)
|
|
43
|
-
$auth.id // Authenticated user ID
|
|
44
|
-
$env.MY_VAR // Environment variable
|
|
45
|
-
$db.table.field // Database field reference (in queries)
|
|
46
|
-
$this // Current item in loops/maps
|
|
47
|
-
$error // Error information (in catch blocks)
|
|
48
|
-
now // Current timestamp
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Language Blocks (Clauses)
|
|
52
|
-
|
|
53
|
-
| Block | Purpose |
|
|
54
|
-
|-------|---------|
|
|
55
|
-
| `stack` | Container for sequential operations |
|
|
56
|
-
| `input` | Define parameters with types and validation |
|
|
57
|
-
| `schema` | Database table schema |
|
|
58
|
-
| `response` | Specify output data |
|
|
59
|
-
| `schedule` | Execution times for tasks |
|
|
60
|
-
| `security` | Authentication and permissions |
|
|
61
|
-
| `auth` | Authentication configuration |
|
|
62
|
-
| `cache` | Caching configuration |
|
|
63
|
-
| `history` | History tracking |
|
|
64
|
-
| `index` | Database index definitions |
|
|
65
|
-
| `test` | Test definitions |
|
|
66
|
-
| `view` | View definitions |
|
|
67
|
-
| `middleware` | Middleware configuration |
|
|
68
|
-
|
|
69
|
-
## Workspace Structure
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
project/
|
|
73
|
-
├── workspace.xs // Workspace configuration
|
|
74
|
-
├── branch.xs // Branch configuration
|
|
75
|
-
├── tables/ // Database table schemas
|
|
76
|
-
├── functions/ // Reusable functions (supports subfolders)
|
|
77
|
-
├── apis/
|
|
78
|
-
│ └── <api-group>/ // API endpoints grouped by domain
|
|
79
|
-
├── tasks/ // Scheduled jobs
|
|
80
|
-
├── triggers/ // Event-driven handlers
|
|
81
|
-
├── agents/ // AI agents
|
|
82
|
-
├── tools/ // AI tools
|
|
83
|
-
├── mcp_servers/ // MCP server definitions
|
|
84
|
-
├── middleware/ // Request/response interceptors
|
|
85
|
-
├── addons/ // Query addons
|
|
86
|
-
├── static/ // Frontend files
|
|
87
|
-
└── run/ // Job and service configurations
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Comments
|
|
91
|
-
|
|
92
|
-
```xs
|
|
93
|
-
// Single-line comment
|
|
94
|
-
/* Multi-line comment */
|
|
95
|
-
var $total { value = 0 } // Inline comment
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Documentation Topics
|
|
99
|
-
|
|
100
|
-
| Topic | Description |
|
|
101
|
-
|-------|-------------|
|
|
102
|
-
| `syntax` | Expressions, operators, filters |
|
|
103
|
-
| `types` | Data types and validation |
|
|
104
|
-
| `operators` | Comparison, logical, math operators |
|
|
105
|
-
| `filters` | Pipe filters for transformations |
|
|
106
|
-
| `control-flow` | Conditionals, loops, error handling |
|
|
107
|
-
| `functions` | Function definitions and calls |
|
|
108
|
-
| `database` | All db.* operations |
|
|
109
|
-
| `apis` | HTTP endpoint definitions |
|
|
110
|
-
| `tables` | Database schema definitions |
|
|
111
|
-
| `tasks` | Scheduled jobs |
|
|
112
|
-
| `triggers` | Event-driven handlers |
|
|
113
|
-
| `agents` | AI agent configuration |
|
|
114
|
-
| `tools` | AI tools for agents |
|
|
115
|
-
| `mcp-servers` | MCP server definitions |
|
|
116
|
-
| `integrations` | Cloud storage, Redis, external APIs |
|
|
117
|
-
| `security-functions` | Encryption, hashing, auth tokens |
|
|
118
|
-
| `testing` | Unit tests and assertions |
|
|
119
|
-
| `variables` | System and built-in variables |
|
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
applyTo: "agents/**/*.xs"
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# AI Agents
|
|
6
|
-
|
|
7
|
-
AI agent configuration with LLM providers, tools, and conversation management.
|
|
8
|
-
|
|
9
|
-
## Quick Reference
|
|
10
|
-
|
|
11
|
-
```xs
|
|
12
|
-
agent "<name>" {
|
|
13
|
-
model = "openai:gpt-4"
|
|
14
|
-
system_prompt = "You are a helpful assistant."
|
|
15
|
-
tools = [search, calculator]
|
|
16
|
-
max_tokens = 1000
|
|
17
|
-
temperature = 0.7
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## Agent Definition
|
|
24
|
-
|
|
25
|
-
### Basic Agent
|
|
26
|
-
|
|
27
|
-
```xs
|
|
28
|
-
agent "customer_support" {
|
|
29
|
-
model = "openai:gpt-4"
|
|
30
|
-
system_prompt = "You are a customer support agent. Help users with their questions about our products and services."
|
|
31
|
-
max_tokens = 500
|
|
32
|
-
temperature = 0.7
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### Agent with Tools
|
|
37
|
-
|
|
38
|
-
```xs
|
|
39
|
-
agent "data_analyst" {
|
|
40
|
-
model = "openai:gpt-4"
|
|
41
|
-
system_prompt = "You are a data analyst. Use the available tools to query data and provide insights."
|
|
42
|
-
tools = [query_database, generate_chart, export_data]
|
|
43
|
-
max_tokens = 1000
|
|
44
|
-
temperature = 0.5
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
## Model Configuration
|
|
51
|
-
|
|
52
|
-
### OpenAI Models
|
|
53
|
-
|
|
54
|
-
```xs
|
|
55
|
-
model = "openai:gpt-4"
|
|
56
|
-
model = "openai:gpt-4-turbo"
|
|
57
|
-
model = "openai:gpt-3.5-turbo"
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Anthropic Models
|
|
61
|
-
|
|
62
|
-
```xs
|
|
63
|
-
model = "anthropic:claude-3-opus"
|
|
64
|
-
model = "anthropic:claude-3-sonnet"
|
|
65
|
-
model = "anthropic:claude-3-haiku"
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Custom Provider
|
|
69
|
-
|
|
70
|
-
```xs
|
|
71
|
-
model = "custom:my-model"
|
|
72
|
-
api_base = "https://my-llm-api.com/v1"
|
|
73
|
-
api_key = $env.CUSTOM_API_KEY
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
## Agent Parameters
|
|
79
|
-
|
|
80
|
-
| Parameter | Description | Default |
|
|
81
|
-
|-----------|-------------|---------|
|
|
82
|
-
| `model` | LLM model identifier | Required |
|
|
83
|
-
| `system_prompt` | Instructions for the agent | Required |
|
|
84
|
-
| `tools` | Available tools | `[]` |
|
|
85
|
-
| `max_tokens` | Maximum response tokens | `500` |
|
|
86
|
-
| `temperature` | Creativity (0-1) | `0.7` |
|
|
87
|
-
| `top_p` | Nucleus sampling | `1` |
|
|
88
|
-
| `stop` | Stop sequences | `[]` |
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## System Prompts
|
|
93
|
-
|
|
94
|
-
### Simple Prompt
|
|
95
|
-
|
|
96
|
-
```xs
|
|
97
|
-
agent "assistant" {
|
|
98
|
-
model = "openai:gpt-4"
|
|
99
|
-
system_prompt = "You are a helpful assistant."
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### Detailed Prompt
|
|
104
|
-
|
|
105
|
-
```xs
|
|
106
|
-
agent "product_expert" {
|
|
107
|
-
model = "openai:gpt-4"
|
|
108
|
-
system_prompt = """
|
|
109
|
-
You are a product expert for our e-commerce platform.
|
|
110
|
-
|
|
111
|
-
Your responsibilities:
|
|
112
|
-
- Answer questions about products
|
|
113
|
-
- Provide recommendations based on user needs
|
|
114
|
-
- Help with order-related queries
|
|
115
|
-
|
|
116
|
-
Guidelines:
|
|
117
|
-
- Be friendly and professional
|
|
118
|
-
- If you don't know something, say so
|
|
119
|
-
- Always verify information using available tools
|
|
120
|
-
"""
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Dynamic Prompt
|
|
125
|
-
|
|
126
|
-
```xs
|
|
127
|
-
agent "personalized_assistant" {
|
|
128
|
-
model = "openai:gpt-4"
|
|
129
|
-
system_prompt = "You are a personal assistant for " ~ $user.name ~ ". Their preferences are: " ~ $user.preferences|json_encode
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
---
|
|
134
|
-
|
|
135
|
-
## Running Agents
|
|
136
|
-
|
|
137
|
-
### Basic Execution
|
|
138
|
-
|
|
139
|
-
```xs
|
|
140
|
-
ai.agent.run {
|
|
141
|
-
agent = "customer_support"
|
|
142
|
-
message = $input.user_message
|
|
143
|
-
} as $response
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### With Conversation History
|
|
147
|
-
|
|
148
|
-
```xs
|
|
149
|
-
ai.agent.run {
|
|
150
|
-
agent = "customer_support"
|
|
151
|
-
message = $input.user_message
|
|
152
|
-
history = $conversation.messages
|
|
153
|
-
} as $response
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### With Context
|
|
157
|
-
|
|
158
|
-
```xs
|
|
159
|
-
ai.agent.run {
|
|
160
|
-
agent = "product_expert"
|
|
161
|
-
message = $input.question
|
|
162
|
-
context = {
|
|
163
|
-
user_id: $auth.id,
|
|
164
|
-
cart_items: $cart.items,
|
|
165
|
-
recent_orders: $recent_orders
|
|
166
|
-
}
|
|
167
|
-
} as $response
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
---
|
|
171
|
-
|
|
172
|
-
## Conversation Management
|
|
173
|
-
|
|
174
|
-
### Store Conversation
|
|
175
|
-
|
|
176
|
-
```xs
|
|
177
|
-
// Add user message
|
|
178
|
-
db.add message {
|
|
179
|
-
data = {
|
|
180
|
-
conversation_id: $input.conversation_id,
|
|
181
|
-
role: "user",
|
|
182
|
-
content: $input.message,
|
|
183
|
-
created_at: now
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Get agent response
|
|
188
|
-
ai.agent.run {
|
|
189
|
-
agent = "assistant"
|
|
190
|
-
message = $input.message
|
|
191
|
-
history = $previous_messages
|
|
192
|
-
} as $response
|
|
193
|
-
|
|
194
|
-
// Store agent response
|
|
195
|
-
db.add message {
|
|
196
|
-
data = {
|
|
197
|
-
conversation_id: $input.conversation_id,
|
|
198
|
-
role: "assistant",
|
|
199
|
-
content: $response.content,
|
|
200
|
-
created_at: now
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
### Load History
|
|
206
|
-
|
|
207
|
-
```xs
|
|
208
|
-
db.query message {
|
|
209
|
-
where = $db.message.conversation_id == $input.conversation_id
|
|
210
|
-
order_by = {field: "created_at", direction: "asc"}
|
|
211
|
-
return = {type: "list", paging: {per_page: 50}}
|
|
212
|
-
} as $history
|
|
213
|
-
|
|
214
|
-
var $formatted_history {
|
|
215
|
-
value = $history|map:{role: $$.role, content: $$.content}
|
|
216
|
-
}
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
## Tools Integration
|
|
222
|
-
|
|
223
|
-
### Linking Tools to Agents
|
|
224
|
-
|
|
225
|
-
```xs
|
|
226
|
-
agent "smart_assistant" {
|
|
227
|
-
model = "openai:gpt-4"
|
|
228
|
-
system_prompt = "Use tools to help users."
|
|
229
|
-
tools = [
|
|
230
|
-
search_products,
|
|
231
|
-
check_inventory,
|
|
232
|
-
create_order,
|
|
233
|
-
get_order_status
|
|
234
|
-
]
|
|
235
|
-
}
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
### Tool Execution
|
|
239
|
-
|
|
240
|
-
When the agent calls a tool, the response includes tool calls that Xano automatically executes:
|
|
241
|
-
|
|
242
|
-
```xs
|
|
243
|
-
ai.agent.run {
|
|
244
|
-
agent = "smart_assistant"
|
|
245
|
-
message = "Check if iPhone 15 is in stock"
|
|
246
|
-
} as $response
|
|
247
|
-
|
|
248
|
-
// $response.content contains the agent's response
|
|
249
|
-
// Tool calls are automatically executed
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
---
|
|
253
|
-
|
|
254
|
-
## Agent Triggers
|
|
255
|
-
|
|
256
|
-
Handle events from agent interactions:
|
|
257
|
-
|
|
258
|
-
```xs
|
|
259
|
-
agent_trigger "on_tool_call" {
|
|
260
|
-
agent = "smart_assistant"
|
|
261
|
-
event = "tool_call"
|
|
262
|
-
|
|
263
|
-
stack {
|
|
264
|
-
// Log tool usage
|
|
265
|
-
db.add agent_log {
|
|
266
|
-
data = {
|
|
267
|
-
agent: $trigger.agent,
|
|
268
|
-
tool: $trigger.tool_name,
|
|
269
|
-
input: $trigger.tool_input,
|
|
270
|
-
created_at: now
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
---
|
|
278
|
-
|
|
279
|
-
## Error Handling
|
|
280
|
-
|
|
281
|
-
```xs
|
|
282
|
-
try_catch {
|
|
283
|
-
try {
|
|
284
|
-
ai.agent.run {
|
|
285
|
-
agent = "assistant"
|
|
286
|
-
message = $input.message
|
|
287
|
-
timeout = 30000
|
|
288
|
-
} as $response
|
|
289
|
-
}
|
|
290
|
-
catch {
|
|
291
|
-
var $response {
|
|
292
|
-
value = {
|
|
293
|
-
content: "I'm sorry, I encountered an error. Please try again.",
|
|
294
|
-
error: true
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
---
|
|
302
|
-
|
|
303
|
-
## Streaming Responses
|
|
304
|
-
|
|
305
|
-
For real-time responses:
|
|
306
|
-
|
|
307
|
-
```xs
|
|
308
|
-
query "chat" verb=POST {
|
|
309
|
-
stack {
|
|
310
|
-
api.stream {
|
|
311
|
-
content_type = "text/event-stream"
|
|
312
|
-
run {
|
|
313
|
-
ai.agent.run {
|
|
314
|
-
agent = "assistant"
|
|
315
|
-
message = $input.message
|
|
316
|
-
stream = true
|
|
317
|
-
on_token {
|
|
318
|
-
api.stream.write {
|
|
319
|
-
data = "data: " ~ $this.token ~ "\n\n"
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
---
|
|
330
|
-
|
|
331
|
-
## Example: Customer Service Agent
|
|
332
|
-
|
|
333
|
-
```xs
|
|
334
|
-
agent "customer_service" {
|
|
335
|
-
model = "openai:gpt-4"
|
|
336
|
-
system_prompt = """
|
|
337
|
-
You are a customer service agent for TechStore.
|
|
338
|
-
|
|
339
|
-
Available actions:
|
|
340
|
-
- Look up orders by order number or email
|
|
341
|
-
- Check product availability
|
|
342
|
-
- Process returns and refunds
|
|
343
|
-
- Answer questions about products
|
|
344
|
-
|
|
345
|
-
Guidelines:
|
|
346
|
-
- Always verify customer identity before sharing order details
|
|
347
|
-
- Be polite and professional
|
|
348
|
-
- Escalate complex issues to human support
|
|
349
|
-
|
|
350
|
-
Use the provided tools to assist customers.
|
|
351
|
-
"""
|
|
352
|
-
tools = [
|
|
353
|
-
lookup_order,
|
|
354
|
-
check_inventory,
|
|
355
|
-
process_return,
|
|
356
|
-
search_products,
|
|
357
|
-
create_ticket
|
|
358
|
-
]
|
|
359
|
-
max_tokens = 1000
|
|
360
|
-
temperature = 0.5
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// Tool definitions
|
|
364
|
-
tool "lookup_order" {
|
|
365
|
-
description = "Look up an order by order number or customer email"
|
|
366
|
-
input {
|
|
367
|
-
text? order_number
|
|
368
|
-
email? customer_email
|
|
369
|
-
}
|
|
370
|
-
stack {
|
|
371
|
-
db.query order {
|
|
372
|
-
where = $db.order.order_number ==? $input.order_number
|
|
373
|
-
|| $db.order.customer_email ==? $input.customer_email
|
|
374
|
-
} as $orders
|
|
375
|
-
}
|
|
376
|
-
response = $orders
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
tool "check_inventory" {
|
|
380
|
-
description = "Check if a product is in stock"
|
|
381
|
-
input {
|
|
382
|
-
text product_name
|
|
383
|
-
}
|
|
384
|
-
stack {
|
|
385
|
-
db.query product {
|
|
386
|
-
where = $db.product.name ilike ("%" ~ $input.product_name ~ "%")
|
|
387
|
-
} as $products
|
|
388
|
-
}
|
|
389
|
-
response = $products|map:{name: $$.name, stock: $$.stock, available: $$.stock > 0}
|
|
390
|
-
}
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
---
|
|
394
|
-
|
|
395
|
-
## Example: Data Analysis Agent
|
|
396
|
-
|
|
397
|
-
```xs
|
|
398
|
-
agent "data_analyst" {
|
|
399
|
-
model = "openai:gpt-4"
|
|
400
|
-
system_prompt = """
|
|
401
|
-
You are a data analyst. Help users understand their data by:
|
|
402
|
-
- Running queries to find insights
|
|
403
|
-
- Generating summary statistics
|
|
404
|
-
- Creating visualizations
|
|
405
|
-
- Explaining trends and patterns
|
|
406
|
-
|
|
407
|
-
Always explain your analysis in plain language.
|
|
408
|
-
"""
|
|
409
|
-
tools = [
|
|
410
|
-
run_query,
|
|
411
|
-
calculate_stats,
|
|
412
|
-
generate_chart
|
|
413
|
-
]
|
|
414
|
-
max_tokens = 2000
|
|
415
|
-
temperature = 0.3
|
|
416
|
-
}
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
---
|
|
420
|
-
|
|
421
|
-
## Best Practices
|
|
422
|
-
|
|
423
|
-
### Clear System Prompts
|
|
424
|
-
|
|
425
|
-
- Define the agent's role clearly
|
|
426
|
-
- List available capabilities
|
|
427
|
-
- Specify guidelines and constraints
|
|
428
|
-
- Provide examples if helpful
|
|
429
|
-
|
|
430
|
-
### Appropriate Tool Selection
|
|
431
|
-
|
|
432
|
-
- Only include relevant tools
|
|
433
|
-
- Use descriptive tool names
|
|
434
|
-
- Document tool parameters well
|
|
435
|
-
|
|
436
|
-
### Handle Edge Cases
|
|
437
|
-
|
|
438
|
-
- Set reasonable timeouts
|
|
439
|
-
- Catch and handle errors
|
|
440
|
-
- Provide fallback responses
|
|
441
|
-
|
|
442
|
-
### Security
|
|
443
|
-
|
|
444
|
-
- Validate tool inputs
|
|
445
|
-
- Limit agent capabilities
|
|
446
|
-
- Log agent actions for auditing
|