@rong/agentscript 0.1.4 → 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/CHANGELOG.md +10 -0
- package/README.md +16 -10
- package/dist/parser/parser.js +14 -6
- package/dist/parser/tokenizer.js +2 -1
- package/dist/runtime/evaluator.js +8 -0
- package/docs/cn/context-engineering.md +1 -1
- package/docs/cn/final-expression-return.md +4 -4
- package/docs/cn/generate.md +35 -39
- package/docs/cn/language.md +67 -41
- package/docs/cn/use-as.md +10 -10
- package/docs/en/context-engineering.md +1 -1
- package/docs/en/final-expression-return.md +2 -2
- package/docs/en/generate.md +33 -37
- package/docs/en/language.md +67 -41
- package/docs/en/use-as.md +10 -10
- package/examples/changelog.as +1 -1
- package/examples/extract.as +1 -1
- package/examples/review.as +2 -2
- package/examples/summarize.as +1 -1
- package/examples/translate.as +1 -1
- package/package.json +1 -1
- package/tutorials/memory.as +4 -4
- package/tutorials/plan-execute.as +4 -4
- package/tutorials/react.as +5 -5
- package/tutorials/self-improve.as +8 -8
package/docs/cn/use-as.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
```agentscript
|
|
12
12
|
use input.question as user question
|
|
13
|
-
use scratch.summary
|
|
13
|
+
use scratch.summary max 2k as observations
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
含义是:
|
|
@@ -25,9 +25,9 @@ use scratch.summary < 2k as observations
|
|
|
25
25
|
|
|
26
26
|
```agentscript
|
|
27
27
|
use expr
|
|
28
|
-
use expr
|
|
28
|
+
use expr max budget
|
|
29
29
|
use expr as label
|
|
30
|
-
use expr
|
|
30
|
+
use expr max budget as label
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
固定顺序是:
|
|
@@ -40,8 +40,8 @@ use expr < budget as label
|
|
|
40
40
|
|
|
41
41
|
```agentscript
|
|
42
42
|
use input.question as user question
|
|
43
|
-
use docs.summary
|
|
44
|
-
use scratch.summary
|
|
43
|
+
use docs.summary max 4k as retrieved evidence
|
|
44
|
+
use scratch.summary max 2k as observations
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
## Context label
|
|
@@ -50,7 +50,7 @@ use scratch.summary < 2k as observations
|
|
|
50
50
|
|
|
51
51
|
```agentscript
|
|
52
52
|
use docs as evidence
|
|
53
|
-
use docs.summary
|
|
53
|
+
use docs.summary max 4k as retrieved evidence
|
|
54
54
|
use input.question as user
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -92,7 +92,7 @@ developer
|
|
|
92
92
|
```agentscript
|
|
93
93
|
main func(input) {
|
|
94
94
|
scratch = []
|
|
95
|
-
use scratch.summary
|
|
95
|
+
use scratch.summary max 2k as observations
|
|
96
96
|
|
|
97
97
|
scratch.add({ fact: "A" })
|
|
98
98
|
scratch.add({ fact: "B" })
|
|
@@ -150,15 +150,15 @@ use helper
|
|
|
150
150
|
|
|
151
151
|
```agentscript
|
|
152
152
|
results = Search.search(input.question)
|
|
153
|
-
use results
|
|
153
|
+
use results max 4k as search results
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
## Budget 语义
|
|
157
157
|
|
|
158
|
-
`use expr
|
|
158
|
+
`use expr max budget` 是 context item budget,限制该 source 渲染进 prompt 的大小。
|
|
159
159
|
|
|
160
160
|
```agentscript
|
|
161
|
-
use docs.summary
|
|
161
|
+
use docs.summary max 4k as evidence
|
|
162
162
|
```
|
|
163
163
|
|
|
164
164
|
这不同于 `generate({ max_output: ... })` 的 output generation budget。详见 [`generate`](./generate.md)。
|
|
@@ -175,10 +175,10 @@ For typical LLM calls, omit `return`:
|
|
|
175
175
|
|
|
176
176
|
```agentscript
|
|
177
177
|
func summarize(content) {
|
|
178
|
-
use content
|
|
178
|
+
use content max 8k
|
|
179
179
|
|
|
180
180
|
generate({
|
|
181
|
-
input: "Summarize the content"
|
|
181
|
+
input: "Summarize the content",
|
|
182
182
|
max_output: 1000
|
|
183
183
|
}) -> {
|
|
184
184
|
title string
|
package/docs/en/generate.md
CHANGED
|
@@ -21,12 +21,12 @@ Ordinary code can compute values, call tools, call agents, and organize state. O
|
|
|
21
21
|
|
|
22
22
|
```agentscript
|
|
23
23
|
generate({
|
|
24
|
-
input: "Classify the issue"
|
|
25
|
-
max_output: 300
|
|
26
|
-
attempts: 2
|
|
27
|
-
temperature: 0.2
|
|
28
|
-
think: "medium"
|
|
29
|
-
strict: true
|
|
24
|
+
input: "Classify the issue",
|
|
25
|
+
max_output: 300,
|
|
26
|
+
attempts: 2,
|
|
27
|
+
temperature: 0.2,
|
|
28
|
+
think: "medium",
|
|
29
|
+
strict: true,
|
|
30
30
|
debug: false
|
|
31
31
|
}) -> {
|
|
32
32
|
category string
|
|
@@ -40,7 +40,7 @@ The output shape after `->` is optional:
|
|
|
40
40
|
generate({ input: "Draft a response." })
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
When no shape is declared, the runtime should not inject a schema or require structured JSON output.
|
|
43
|
+
When no shape is declared, the runtime should not inject a schema or require structured JSON output. Free-form generate is allowed but not recommended for agent workflows; prefer an explicit output shape so retries, validation, trace, and downstream agent calls stay auditable.
|
|
44
44
|
|
|
45
45
|
## Configuration fields
|
|
46
46
|
|
|
@@ -110,7 +110,7 @@ Selected context comes from visible `use` declarations:
|
|
|
110
110
|
|
|
111
111
|
```agentscript
|
|
112
112
|
use input.question as user question
|
|
113
|
-
use scratch.summary
|
|
113
|
+
use scratch.summary max 2k as observations
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
A rendered prompt section may look like:
|
|
@@ -162,7 +162,7 @@ The runtime asks the provider for structured output when possible and validates
|
|
|
162
162
|
|
|
163
163
|
```agentscript
|
|
164
164
|
generate({
|
|
165
|
-
input: "Answer briefly"
|
|
165
|
+
input: "Answer briefly",
|
|
166
166
|
max_output: 300
|
|
167
167
|
}) -> {
|
|
168
168
|
answer string
|
|
@@ -178,10 +178,10 @@ max_output = provider-side generation budget requested by AgentScript
|
|
|
178
178
|
It is separate from `use` input context budgets:
|
|
179
179
|
|
|
180
180
|
```agentscript
|
|
181
|
-
use docs.summary
|
|
181
|
+
use docs.summary max 4k
|
|
182
182
|
|
|
183
183
|
generate({
|
|
184
|
-
input: "Answer from the selected docs"
|
|
184
|
+
input: "Answer from the selected docs",
|
|
185
185
|
max_output: 800
|
|
186
186
|
}) -> {
|
|
187
187
|
answer string
|
|
@@ -191,18 +191,18 @@ generate({
|
|
|
191
191
|
Difference:
|
|
192
192
|
|
|
193
193
|
```text
|
|
194
|
-
use ...
|
|
194
|
+
use ... max 4k = input context budget
|
|
195
195
|
max_output: 800 = output generation budget
|
|
196
196
|
```
|
|
197
197
|
|
|
198
198
|
## `attempts`
|
|
199
199
|
|
|
200
|
-
`attempts` controls how many times the runtime may try to obtain a valid structured result.
|
|
200
|
+
`attempts` controls how many times the runtime may try to obtain a valid structured result. `attempts` is the maximum total number of attempts, including the first one.
|
|
201
201
|
|
|
202
202
|
```agentscript
|
|
203
203
|
generate({
|
|
204
|
-
input: "Extract metadata"
|
|
205
|
-
max_output: 500
|
|
204
|
+
input: "Extract metadata",
|
|
205
|
+
max_output: 500,
|
|
206
206
|
attempts: 3
|
|
207
207
|
}) -> {
|
|
208
208
|
title string
|
|
@@ -242,8 +242,8 @@ attempts: 1
|
|
|
242
242
|
|
|
243
243
|
```agentscript
|
|
244
244
|
generate({
|
|
245
|
-
input: "Brainstorm alternatives"
|
|
246
|
-
max_output: 1000
|
|
245
|
+
input: "Brainstorm alternatives",
|
|
246
|
+
max_output: 1000,
|
|
247
247
|
temperature: 0.7
|
|
248
248
|
}) -> {
|
|
249
249
|
ideas list[string]
|
|
@@ -264,11 +264,11 @@ If unsupported, adapter may ignore, warn, or fail according to capability policy
|
|
|
264
264
|
Recommended values:
|
|
265
265
|
|
|
266
266
|
```agentscript
|
|
267
|
-
think: false
|
|
268
|
-
think: true
|
|
269
|
-
think: "auto"
|
|
270
|
-
think: "low"
|
|
271
|
-
think: "medium"
|
|
267
|
+
think: false,
|
|
268
|
+
think: true,
|
|
269
|
+
think: "auto",
|
|
270
|
+
think: "low",
|
|
271
|
+
think: "medium",
|
|
272
272
|
think: "high"
|
|
273
273
|
```
|
|
274
274
|
|
|
@@ -287,8 +287,8 @@ Example:
|
|
|
287
287
|
|
|
288
288
|
```agentscript
|
|
289
289
|
generate({
|
|
290
|
-
input: "Analyze the tradeoffs"
|
|
291
|
-
max_output: 1200
|
|
290
|
+
input: "Analyze the tradeoffs",
|
|
291
|
+
max_output: 1200,
|
|
292
292
|
think: "high"
|
|
293
293
|
}) -> {
|
|
294
294
|
decision string
|
|
@@ -297,20 +297,16 @@ generate({
|
|
|
297
297
|
}
|
|
298
298
|
```
|
|
299
299
|
|
|
300
|
-
`think` is a provider/model capability hint. Not every model guarantees support.
|
|
300
|
+
`think` is a provider/model capability hint. Not every model guarantees support. If unsupported, the adapter may ignore, warn, or fail according to capability policy.
|
|
301
301
|
|
|
302
|
-
|
|
302
|
+
## Capability policy for provider hints
|
|
303
303
|
|
|
304
|
-
|
|
305
|
-
ignore
|
|
306
|
-
warn
|
|
307
|
-
fail
|
|
308
|
-
```
|
|
304
|
+
`temperature` and `think` are provider/model capability hints. Unsupported provider hints default to warn in debug mode and ignore otherwise.
|
|
309
305
|
|
|
310
|
-
|
|
306
|
+
Adapters may ignore, warn, or fail for unsupported hints according to runtime capability policy, but documentation should treat the default as:
|
|
311
307
|
|
|
312
308
|
```text
|
|
313
|
-
warn in debug mode
|
|
309
|
+
unsupported provider hints default to warn in debug mode and ignore otherwise
|
|
314
310
|
```
|
|
315
311
|
|
|
316
312
|
## `strict`
|
|
@@ -319,8 +315,8 @@ warn in debug mode, otherwise ignore
|
|
|
319
315
|
|
|
320
316
|
```agentscript
|
|
321
317
|
generate({
|
|
322
|
-
input: "Classify the issue"
|
|
323
|
-
max_output: 300
|
|
318
|
+
input: "Classify the issue",
|
|
319
|
+
max_output: 300,
|
|
324
320
|
strict: true
|
|
325
321
|
}) -> {
|
|
326
322
|
category string
|
|
@@ -377,8 +373,8 @@ strict is AgentScript runtime control over the output contract.
|
|
|
377
373
|
|
|
378
374
|
```agentscript
|
|
379
375
|
generate({
|
|
380
|
-
input: "Answer the question"
|
|
381
|
-
max_output: 800
|
|
376
|
+
input: "Answer the question",
|
|
377
|
+
max_output: 800,
|
|
382
378
|
debug: true
|
|
383
379
|
}) -> {
|
|
384
380
|
answer string
|
package/docs/en/language.md
CHANGED
|
@@ -150,16 +150,18 @@ Supported shape types: `string`, `number`, `boolean`, `json`, `list`, `list[T]`
|
|
|
150
150
|
|
|
151
151
|
Shapes are not a full static type system.
|
|
152
152
|
|
|
153
|
+
Object literals use JSON-like syntax: fields are written as `key: value`, and multiple fields must be separated with commas.
|
|
154
|
+
|
|
153
155
|
## Explicit context with `use`
|
|
154
156
|
|
|
155
157
|
`use` selects values that may be included in later `generate` prompts within the current scope and child scopes.
|
|
156
158
|
|
|
157
159
|
```agentscript
|
|
158
160
|
use input.question
|
|
159
|
-
use Requirements
|
|
160
|
-
use past_lessons
|
|
161
|
+
use Requirements max 4k
|
|
162
|
+
use past_lessons max 2k
|
|
161
163
|
use input.question as user
|
|
162
|
-
use docs.summary
|
|
164
|
+
use docs.summary max 4k as evidence
|
|
163
165
|
```
|
|
164
166
|
|
|
165
167
|
### Rules
|
|
@@ -168,9 +170,9 @@ use docs.summary < 4k as evidence
|
|
|
168
170
|
- Tool outputs do not automatically enter prompts.
|
|
169
171
|
- Memory query results do not automatically enter prompts.
|
|
170
172
|
- Trace events do not automatically enter prompts.
|
|
171
|
-
- `use value
|
|
173
|
+
- `use value max n` applies a context budget.
|
|
172
174
|
- `use value as label` attaches a literal context label to the selected source.
|
|
173
|
-
- `use value
|
|
175
|
+
- `use value max n as label` applies the budget first, then attaches the label.
|
|
174
176
|
- `llm`, `tool`, `agent`, `memory` bindings cannot be used.
|
|
175
177
|
- Function bindings cannot be used.
|
|
176
178
|
- `use` declarations are inherited by child scopes.
|
|
@@ -181,7 +183,7 @@ The label after `as` is literal label text. It is not an expression, is not eval
|
|
|
181
183
|
|
|
182
184
|
```agentscript
|
|
183
185
|
use docs as evidence
|
|
184
|
-
use docs.summary
|
|
186
|
+
use docs.summary max 4k as retrieved evidence
|
|
185
187
|
use input.question as user
|
|
186
188
|
```
|
|
187
189
|
|
|
@@ -189,7 +191,7 @@ use input.question as user
|
|
|
189
191
|
|
|
190
192
|
### Deferred evaluation
|
|
191
193
|
|
|
192
|
-
`use expr
|
|
194
|
+
`use expr max budget` declares a context source, not a snapshot. The expression is re-evaluated when `generate` builds the prompt. This means updates to a variable made after `use` but before `generate` are visible at generation time.
|
|
193
195
|
|
|
194
196
|
For the full design semantics, see [`use ... as ...`](./use-as.md).
|
|
195
197
|
|
|
@@ -199,9 +201,9 @@ For the full design semantics, see [`use ... as ...`](./use-as.md).
|
|
|
199
201
|
|
|
200
202
|
```agentscript
|
|
201
203
|
answer = generate({
|
|
202
|
-
input: "Answer using the selected context."
|
|
203
|
-
max_output: 800
|
|
204
|
-
attempts: 3
|
|
204
|
+
input: "Answer using the selected context.",
|
|
205
|
+
max_output: 800,
|
|
206
|
+
attempts: 3,
|
|
205
207
|
debug: true
|
|
206
208
|
}) -> {
|
|
207
209
|
ok boolean
|
|
@@ -214,13 +216,13 @@ answer = generate({
|
|
|
214
216
|
|
|
215
217
|
- `input` is the per-generation instruction. Required.
|
|
216
218
|
- `max_output` is the output generation budget (number or `2k` style). Optional.
|
|
217
|
-
- `attempts` controls retry for JSON parse errors or shape mismatch. Optional, defaults to 1.
|
|
218
|
-
- `temperature` is a provider sampling hint. Optional.
|
|
219
|
-
- `think` is a provider/model reasoning hint. Optional.
|
|
219
|
+
- `attempts` controls retry for JSON parse errors or shape mismatch. It is the maximum total number of attempts, including the first one. Optional, defaults to 1.
|
|
220
|
+
- `temperature` is a provider sampling hint. Optional. Unsupported provider hints default to warn in debug mode and ignore otherwise.
|
|
221
|
+
- `think` is a provider/model reasoning hint. Optional. Unsupported provider hints default to warn in debug mode and ignore otherwise.
|
|
220
222
|
- `strict` controls shape validation strictness. Optional, defaults to false.
|
|
221
223
|
- `debug` prints the full prompt to stderr. Optional, defaults to false.
|
|
222
224
|
- The optional `-> { ... }` block declares the expected output shape.
|
|
223
|
-
- Without `-> { ... }`, the generate output is unconstrained: AgentScript does not add a return schema to the prompt, does not request provider structured output, and does not coerce or validate the returned value.
|
|
225
|
+
- Without `-> { ... }`, the generate output is unconstrained: AgentScript does not add a return schema to the prompt, does not request provider structured output, and does not coerce or validate the returned value. Free-form generate is allowed but not recommended for agent workflows.
|
|
224
226
|
- Provider errors (auth, network, timeout, missing model) fail directly without retry.
|
|
225
227
|
- Shape validation includes coercion (e.g. `"true"` -> `true`, `"42"` -> `42`).
|
|
226
228
|
|
|
@@ -238,14 +240,14 @@ if answer.ok and not input.dry_run {
|
|
|
238
240
|
}
|
|
239
241
|
```
|
|
240
242
|
|
|
241
|
-
Supported operators: `==`, `!=`, `and`, `or`, `not`.
|
|
243
|
+
Supported operators: `==`, `!=`, `<`, `and`, `or`, `not`. Context budgets and loop limits use `max`, so `<` remains an ordinary comparison operator like `==`.
|
|
242
244
|
|
|
243
245
|
### Loop until
|
|
244
246
|
|
|
245
247
|
```agentscript
|
|
246
248
|
done = false
|
|
247
249
|
|
|
248
|
-
loop until done
|
|
250
|
+
loop until done max 6 {
|
|
249
251
|
observation = observe(input)
|
|
250
252
|
done = observation.ok
|
|
251
253
|
}
|
|
@@ -269,7 +271,7 @@ Each iteration creates a child scope. Outer variables updated inside the loop pe
|
|
|
269
271
|
### For in
|
|
270
272
|
|
|
271
273
|
```agentscript
|
|
272
|
-
for step in plan.steps
|
|
274
|
+
for step in plan.steps max 12 {
|
|
273
275
|
result = Executor(step)
|
|
274
276
|
results.add(result)
|
|
275
277
|
}
|
|
@@ -289,7 +291,7 @@ summary = items.summary
|
|
|
289
291
|
- `list[index]` is read-only. Index must be a non-negative integer.
|
|
290
292
|
- `list.add(value)` mutates the list. Takes exactly one argument.
|
|
291
293
|
- `.length` returns the list length.
|
|
292
|
-
- `.summary` returns a JSON-safe runtime view of the list. It is not an LLM-generated summary or semantic compression; any prompt-size reduction comes from explicit context budgets such as `use scratch.summary
|
|
294
|
+
- `.summary` returns a JSON-safe runtime view of the list. It is not an LLM-generated summary or semantic compression; any prompt-size reduction comes from explicit context budgets such as `use scratch.summary max 2k`.
|
|
293
295
|
|
|
294
296
|
## Tools
|
|
295
297
|
|
|
@@ -307,9 +309,9 @@ import tool Http from "https://api.example.com"
|
|
|
307
309
|
|
|
308
310
|
```agentscript
|
|
309
311
|
files = Find.run({
|
|
310
|
-
path: "."
|
|
311
|
-
name: "*.ts"
|
|
312
|
-
type: "file"
|
|
312
|
+
path: ".",
|
|
313
|
+
name: "*.ts",
|
|
314
|
+
type: "file",
|
|
313
315
|
max: 50
|
|
314
316
|
})
|
|
315
317
|
```
|
|
@@ -318,9 +320,9 @@ files = Find.run({
|
|
|
318
320
|
|
|
319
321
|
```agentscript
|
|
320
322
|
matches = Grep.run({
|
|
321
|
-
path: "src"
|
|
322
|
-
pattern: "TODO"
|
|
323
|
-
include: "*.ts"
|
|
323
|
+
path: "src",
|
|
324
|
+
pattern: "TODO",
|
|
325
|
+
include: "*.ts",
|
|
324
326
|
max: 100
|
|
325
327
|
})
|
|
326
328
|
```
|
|
@@ -329,8 +331,8 @@ matches = Grep.run({
|
|
|
329
331
|
|
|
330
332
|
```agentscript
|
|
331
333
|
lines = Sed.run({
|
|
332
|
-
path: "src/main.as"
|
|
333
|
-
start: 1
|
|
334
|
+
path: "src/main.as",
|
|
335
|
+
start: 1,
|
|
334
336
|
max: 20
|
|
335
337
|
})
|
|
336
338
|
```
|
|
@@ -338,10 +340,21 @@ lines = Sed.run({
|
|
|
338
340
|
### File
|
|
339
341
|
|
|
340
342
|
```agentscript
|
|
341
|
-
content = File.read({
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
343
|
+
content = File.read({
|
|
344
|
+
path: "README.md"
|
|
345
|
+
})
|
|
346
|
+
entries = File.list({
|
|
347
|
+
path: "src"
|
|
348
|
+
})
|
|
349
|
+
result = File.write({
|
|
350
|
+
path: "output.md",
|
|
351
|
+
content: "# Result"
|
|
352
|
+
})
|
|
353
|
+
result = File.patch({
|
|
354
|
+
path: "file.as",
|
|
355
|
+
search: "old",
|
|
356
|
+
replace: "new"
|
|
357
|
+
})
|
|
345
358
|
result = File.undo(effects)
|
|
346
359
|
```
|
|
347
360
|
|
|
@@ -350,14 +363,24 @@ Write and patch operations return undoable effect records. `File.undo` accepts a
|
|
|
350
363
|
### Env
|
|
351
364
|
|
|
352
365
|
```agentscript
|
|
353
|
-
home = Env.get({
|
|
366
|
+
home = Env.get({
|
|
367
|
+
name: "HOME"
|
|
368
|
+
})
|
|
354
369
|
```
|
|
355
370
|
|
|
356
371
|
### Http
|
|
357
372
|
|
|
358
373
|
```agentscript
|
|
359
|
-
response = Http.get({
|
|
360
|
-
|
|
374
|
+
response = Http.get({
|
|
375
|
+
url: "/api/data",
|
|
376
|
+
headers: { Authorization: "Bearer ..." },
|
|
377
|
+
timeout: 10000
|
|
378
|
+
})
|
|
379
|
+
response = Http.post({
|
|
380
|
+
url: "/api/submit",
|
|
381
|
+
body: { key: "value" },
|
|
382
|
+
timeout: 10000
|
|
383
|
+
})
|
|
361
384
|
```
|
|
362
385
|
|
|
363
386
|
HTTP requests are restricted to the origin of the import URI.
|
|
@@ -387,7 +410,7 @@ import file Requirements from "./requirements.md"
|
|
|
387
410
|
import file Config from "./config.json"
|
|
388
411
|
|
|
389
412
|
func answer(input) {
|
|
390
|
-
use Requirements
|
|
413
|
+
use Requirements max 4k
|
|
391
414
|
use Config
|
|
392
415
|
generate({ input: "Answer from the referenced file." }) -> {
|
|
393
416
|
ok boolean
|
|
@@ -402,18 +425,18 @@ Text files are loaded as strings. JSON files are parsed as JSON values. File con
|
|
|
402
425
|
|
|
403
426
|
```agentscript
|
|
404
427
|
Lessons.add({
|
|
405
|
-
kind: "lesson"
|
|
406
|
-
text: reflection.insight
|
|
428
|
+
kind: "lesson",
|
|
429
|
+
text: reflection.insight,
|
|
407
430
|
goal: input.goal
|
|
408
431
|
})
|
|
409
432
|
|
|
410
433
|
past = Lessons.query({
|
|
411
|
-
kind: "lesson"
|
|
412
|
-
text: input.goal
|
|
434
|
+
kind: "lesson",
|
|
435
|
+
text: input.goal,
|
|
413
436
|
limit: 5
|
|
414
437
|
})
|
|
415
438
|
|
|
416
|
-
use past
|
|
439
|
+
use past max 2k
|
|
417
440
|
```
|
|
418
441
|
|
|
419
442
|
### Rules
|
|
@@ -437,8 +460,11 @@ main agent Controller {
|
|
|
437
460
|
main func(input) {
|
|
438
461
|
plan = Planner(input)
|
|
439
462
|
results = []
|
|
440
|
-
for step in plan.steps
|
|
441
|
-
result = Executor({
|
|
463
|
+
for step in plan.steps max 10 {
|
|
464
|
+
result = Executor({
|
|
465
|
+
goal: input.goal,
|
|
466
|
+
step: step
|
|
467
|
+
})
|
|
442
468
|
results.add(result)
|
|
443
469
|
}
|
|
444
470
|
results.summary
|
package/docs/en/use-as.md
CHANGED
|
@@ -10,7 +10,7 @@ For the larger mental model, see [Context Engineering](./context-engineering.md)
|
|
|
10
10
|
|
|
11
11
|
```agentscript
|
|
12
12
|
use input.question as user question
|
|
13
|
-
use scratch.summary
|
|
13
|
+
use scratch.summary max 2k as observations
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
The meaning is:
|
|
@@ -25,9 +25,9 @@ Local variables not selected with `use` do not enter the prompt.
|
|
|
25
25
|
|
|
26
26
|
```agentscript
|
|
27
27
|
use expr
|
|
28
|
-
use expr
|
|
28
|
+
use expr max budget
|
|
29
29
|
use expr as label
|
|
30
|
-
use expr
|
|
30
|
+
use expr max budget as label
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
The fixed order is:
|
|
@@ -40,8 +40,8 @@ Examples:
|
|
|
40
40
|
|
|
41
41
|
```agentscript
|
|
42
42
|
use input.question as user question
|
|
43
|
-
use docs.summary
|
|
44
|
-
use scratch.summary
|
|
43
|
+
use docs.summary max 4k as retrieved evidence
|
|
44
|
+
use scratch.summary max 2k as observations
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
## Context labels
|
|
@@ -50,7 +50,7 @@ The label after `as` is literal label text. It is not an expression, is not eval
|
|
|
50
50
|
|
|
51
51
|
```agentscript
|
|
52
52
|
use docs as evidence
|
|
53
|
-
use docs.summary
|
|
53
|
+
use docs.summary max 4k as retrieved evidence
|
|
54
54
|
use input.question as user
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -92,7 +92,7 @@ developer
|
|
|
92
92
|
```agentscript
|
|
93
93
|
main func(input) {
|
|
94
94
|
scratch = []
|
|
95
|
-
use scratch.summary
|
|
95
|
+
use scratch.summary max 2k as observations
|
|
96
96
|
|
|
97
97
|
scratch.add({ fact: "A" })
|
|
98
98
|
scratch.add({ fact: "B" })
|
|
@@ -150,15 +150,15 @@ Use the data returned by these capabilities instead:
|
|
|
150
150
|
|
|
151
151
|
```agentscript
|
|
152
152
|
results = Search.search(input.question)
|
|
153
|
-
use results
|
|
153
|
+
use results max 4k as search results
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
## Budget semantics
|
|
157
157
|
|
|
158
|
-
`use expr
|
|
158
|
+
`use expr max budget` is a context item budget. It limits how much of that source may be rendered into the prompt.
|
|
159
159
|
|
|
160
160
|
```agentscript
|
|
161
|
-
use docs.summary
|
|
161
|
+
use docs.summary max 4k as evidence
|
|
162
162
|
```
|
|
163
163
|
|
|
164
164
|
This is different from `generate({ max_output: ... })`, which is an output generation budget. See [`generate`](./generate.md).
|
package/examples/changelog.as
CHANGED
package/examples/extract.as
CHANGED
package/examples/review.as
CHANGED
|
@@ -23,8 +23,8 @@ main agent CodeReviewAssistant {
|
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
use input.path as source path
|
|
26
|
-
use todos
|
|
27
|
-
use fixmes
|
|
26
|
+
use todos max 4k as todo findings
|
|
27
|
+
use fixmes max 4k as fixme findings
|
|
28
28
|
|
|
29
29
|
generate({ input: "Turn TODO and FIXME scan results into prioritized repair suggestions", max_output: 1200 }) -> {
|
|
30
30
|
summary string
|
package/examples/summarize.as
CHANGED
package/examples/translate.as
CHANGED
|
@@ -19,7 +19,7 @@ main agent MarkdownTranslator {
|
|
|
19
19
|
|
|
20
20
|
use input.path as source path
|
|
21
21
|
use input.target_language as target language
|
|
22
|
-
use files
|
|
22
|
+
use files max 4k as markdown files
|
|
23
23
|
|
|
24
24
|
generate({ input: "Create a practical markdown translation plan", max_output: 1000 }) -> {
|
|
25
25
|
target_language string
|
package/package.json
CHANGED
package/tutorials/memory.as
CHANGED
|
@@ -5,14 +5,14 @@ main agent MemoryDemo {
|
|
|
5
5
|
topic string
|
|
6
6
|
}) {
|
|
7
7
|
Notes.add({
|
|
8
|
-
kind: "note"
|
|
9
|
-
text: input.topic
|
|
8
|
+
kind: "note",
|
|
9
|
+
text: input.topic,
|
|
10
10
|
topic: input.topic
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
Notes.query({
|
|
14
|
-
kind: "note"
|
|
15
|
-
text: input.topic
|
|
14
|
+
kind: "note",
|
|
15
|
+
text: input.topic,
|
|
16
16
|
limit: 3
|
|
17
17
|
})
|
|
18
18
|
}
|