@rong/agentscript 0.1.0
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 +22 -0
- package/INSTALL.md +92 -0
- package/LICENSE +21 -0
- package/README.md +246 -0
- package/dist/ast/constants.js +1 -0
- package/dist/ast/format.js +41 -0
- package/dist/ast/types.js +1 -0
- package/dist/bin/agentscript.js +234 -0
- package/dist/bin/input.js +19 -0
- package/dist/bin/repl.js +290 -0
- package/dist/index.js +26 -0
- package/dist/parser/errors.js +8 -0
- package/dist/parser/parser.js +661 -0
- package/dist/parser/tokenizer.js +246 -0
- package/dist/providers/llm/anthropic.js +36 -0
- package/dist/providers/llm/index.js +3 -0
- package/dist/providers/llm/ollama.js +19 -0
- package/dist/providers/llm/openai.js +31 -0
- package/dist/providers/llm/protocol.js +45 -0
- package/dist/providers/llm/shared.js +147 -0
- package/dist/providers/llm/types.js +1 -0
- package/dist/providers/llm/uri.js +24 -0
- package/dist/providers/memory/file.js +44 -0
- package/dist/providers/memory/host.js +66 -0
- package/dist/providers/memory/index.js +1 -0
- package/dist/providers/memory/shared.js +56 -0
- package/dist/providers/memory/sqlite.js +98 -0
- package/dist/providers/mock/index.js +32 -0
- package/dist/providers/tools/env.js +11 -0
- package/dist/providers/tools/file.js +99 -0
- package/dist/providers/tools/host.js +34 -0
- package/dist/providers/tools/http.js +40 -0
- package/dist/providers/tools/index.js +2 -0
- package/dist/providers/tools/scheme.js +16 -0
- package/dist/providers/tools/shared.js +92 -0
- package/dist/providers/tools/shell.js +80 -0
- package/dist/runtime/context.js +160 -0
- package/dist/runtime/errors.js +14 -0
- package/dist/runtime/evaluator.js +276 -0
- package/dist/runtime/generate.js +175 -0
- package/dist/runtime/guards.js +39 -0
- package/dist/runtime/input.js +38 -0
- package/dist/runtime/interpreter.js +314 -0
- package/dist/runtime/json.js +59 -0
- package/dist/runtime/loader.js +146 -0
- package/dist/runtime/scope.js +47 -0
- package/dist/runtime/shape.js +132 -0
- package/dist/runtime/trace.js +54 -0
- package/dist/runtime/truth.js +13 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/uri.js +10 -0
- package/dist/semantic/analyzer.js +519 -0
- package/dist/semantic/diagnostics.js +16 -0
- package/dist/utils/assert.js +3 -0
- package/docs/cn/context-engineering.md +389 -0
- package/docs/cn/language.md +478 -0
- package/docs/design-history/v0-design.md +365 -0
- package/docs/design-history/v0-implement.md +274 -0
- package/docs/design-history/v1-design.md +323 -0
- package/docs/design-history/v1-implement.md +267 -0
- package/docs/design-history/v2-design.md +387 -0
- package/docs/design-history/v2-implement.md +399 -0
- package/docs/en/context-engineering.md +332 -0
- package/docs/en/language.md +478 -0
- package/examples/changelog.as +29 -0
- package/examples/extract.as +29 -0
- package/examples/review.as +38 -0
- package/examples/summarize.as +28 -0
- package/examples/translate.as +33 -0
- package/package.json +59 -0
- package/tutorials/cli.as +22 -0
- package/tutorials/helloworld.as +14 -0
- package/tutorials/memory.as +19 -0
- package/tutorials/plan-execute.as +155 -0
- package/tutorials/react.as +98 -0
- package/tutorials/repl.as +31 -0
- package/tutorials/self-improve.as +60 -0
package/tutorials/cli.as
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import llm Qwen from "ollama://localhost:11434/qwen3.6"
|
|
2
|
+
|
|
3
|
+
main agent {
|
|
4
|
+
model Qwen
|
|
5
|
+
role "CLI Assistant"
|
|
6
|
+
description "Answer a short request from a command-line user."
|
|
7
|
+
|
|
8
|
+
main func(input {
|
|
9
|
+
name string
|
|
10
|
+
request string
|
|
11
|
+
}) {
|
|
12
|
+
use input.name
|
|
13
|
+
use input.request
|
|
14
|
+
|
|
15
|
+
return generate({ input: "Reply to the CLI user by name", limit: 300 }) {
|
|
16
|
+
return {
|
|
17
|
+
ok boolean
|
|
18
|
+
message string
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import llm Qwen from "ollama://localhost:11434/qwen3.6"
|
|
2
|
+
|
|
3
|
+
main agent {
|
|
4
|
+
model Qwen
|
|
5
|
+
role "Assistant"
|
|
6
|
+
description "Return a simple hello world response."
|
|
7
|
+
|
|
8
|
+
main func(input {}) {
|
|
9
|
+
return {
|
|
10
|
+
ok: true,
|
|
11
|
+
message: "Hello, AgentScript!"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import memory Notes from "file://./.agentscript/tutorial-memory.jsonl"
|
|
2
|
+
|
|
3
|
+
main agent MemoryDemo {
|
|
4
|
+
main func(input {
|
|
5
|
+
topic string
|
|
6
|
+
}) {
|
|
7
|
+
Notes.add({
|
|
8
|
+
kind: "note"
|
|
9
|
+
text: input.topic
|
|
10
|
+
topic: input.topic
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return Notes.query({
|
|
14
|
+
kind: "note"
|
|
15
|
+
text: input.topic
|
|
16
|
+
limit: 3
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import llm Qwen from "ollama://localhost:11434/qwen3.6"
|
|
2
|
+
import tool Search from "mcp://tools/search"
|
|
3
|
+
|
|
4
|
+
main agent PlanAndExecute {
|
|
5
|
+
model Qwen
|
|
6
|
+
role "Controller"
|
|
7
|
+
description "Coordinate planning, execution, verification, and final synthesis."
|
|
8
|
+
|
|
9
|
+
main func(input {
|
|
10
|
+
goal string
|
|
11
|
+
}) {
|
|
12
|
+
plan = Planner({
|
|
13
|
+
goal: input.goal,
|
|
14
|
+
problem: "",
|
|
15
|
+
previous: []
|
|
16
|
+
})
|
|
17
|
+
results = []
|
|
18
|
+
|
|
19
|
+
steps = [
|
|
20
|
+
{
|
|
21
|
+
id: "step-1",
|
|
22
|
+
task: plan.step1
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "step-2",
|
|
26
|
+
task: plan.step2
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "step-3",
|
|
30
|
+
task: plan.step3
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
for step in steps < 6 {
|
|
35
|
+
outcome = run_step(input.goal, step, results)
|
|
36
|
+
results.add(outcome.result)
|
|
37
|
+
|
|
38
|
+
if not outcome.ok {
|
|
39
|
+
plan = Planner({
|
|
40
|
+
goal: input.goal,
|
|
41
|
+
problem: outcome.reason,
|
|
42
|
+
previous: results.summary
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return finish(input.goal, results)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func run_step(goal, step, previous) {
|
|
51
|
+
result = Executor({
|
|
52
|
+
goal: goal,
|
|
53
|
+
step: step,
|
|
54
|
+
previous: previous.summary
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
verdict = Verifier({
|
|
58
|
+
goal: goal,
|
|
59
|
+
step: step,
|
|
60
|
+
result: result
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
ok: verdict.ok,
|
|
65
|
+
reason: verdict.reason,
|
|
66
|
+
result: {
|
|
67
|
+
step: step.id,
|
|
68
|
+
task: step.task,
|
|
69
|
+
output: result.output
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func finish(goal, results) {
|
|
75
|
+
use goal
|
|
76
|
+
use results.summary < 2k
|
|
77
|
+
|
|
78
|
+
return generate({ input: "Create the final answer from executed steps", limit: 800 }) {
|
|
79
|
+
return {
|
|
80
|
+
ok boolean
|
|
81
|
+
text string
|
|
82
|
+
error string
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
agent Planner {
|
|
89
|
+
model Qwen
|
|
90
|
+
role "Planner"
|
|
91
|
+
description "Create or revise a short executable plan."
|
|
92
|
+
|
|
93
|
+
main func(input) {
|
|
94
|
+
use input.goal
|
|
95
|
+
use input.problem
|
|
96
|
+
use input.previous < 1k
|
|
97
|
+
|
|
98
|
+
return generate({ input: "Create a three step plan", limit: 600 }) {
|
|
99
|
+
return {
|
|
100
|
+
step1 string
|
|
101
|
+
step2 string
|
|
102
|
+
step3 string
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
agent Executor {
|
|
109
|
+
model Qwen
|
|
110
|
+
role "Executor"
|
|
111
|
+
description "Execute one plan step with available tools."
|
|
112
|
+
|
|
113
|
+
main func(input) {
|
|
114
|
+
use input.goal
|
|
115
|
+
use input.step
|
|
116
|
+
use input.previous < 1k
|
|
117
|
+
|
|
118
|
+
query = Search.query(input.goal, input.step, input.previous)
|
|
119
|
+
raw = Search.search(query)
|
|
120
|
+
|
|
121
|
+
observation = {
|
|
122
|
+
summary: raw.summary,
|
|
123
|
+
source: raw.source
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
use observation
|
|
127
|
+
|
|
128
|
+
return generate({ input: "Report the result of this step", limit: 500 }) {
|
|
129
|
+
return {
|
|
130
|
+
ok boolean
|
|
131
|
+
output json
|
|
132
|
+
error string
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
agent Verifier {
|
|
139
|
+
model Qwen
|
|
140
|
+
role "Verifier"
|
|
141
|
+
description "Check whether one executed step satisfies the plan."
|
|
142
|
+
|
|
143
|
+
main func(input) {
|
|
144
|
+
use input.goal
|
|
145
|
+
use input.step
|
|
146
|
+
use input.result
|
|
147
|
+
|
|
148
|
+
return generate({ input: "Verify this step result", limit: 300 }) {
|
|
149
|
+
return {
|
|
150
|
+
ok boolean
|
|
151
|
+
reason string
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import llm Qwen from "ollama://localhost:11434/qwen3.6"
|
|
2
|
+
import tool Search from "mcp://tools/search"
|
|
3
|
+
|
|
4
|
+
main agent ResearchAgent {
|
|
5
|
+
model Qwen
|
|
6
|
+
role "Researcher"
|
|
7
|
+
description "Answer questions with a small reason-act-observe loop."
|
|
8
|
+
|
|
9
|
+
main func(input {
|
|
10
|
+
question string
|
|
11
|
+
}) {
|
|
12
|
+
use input.question
|
|
13
|
+
|
|
14
|
+
scratch = []
|
|
15
|
+
use scratch.summary < 2k
|
|
16
|
+
|
|
17
|
+
done = false
|
|
18
|
+
|
|
19
|
+
loop until done < 4 {
|
|
20
|
+
thought = reason(input.question, scratch)
|
|
21
|
+
action = act(input.question, thought)
|
|
22
|
+
observation = observe(action)
|
|
23
|
+
|
|
24
|
+
scratch.add(observation)
|
|
25
|
+
done = enough(input.question, scratch)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return answer(input.question, scratch)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func reason(question, scratch) {
|
|
32
|
+
use question
|
|
33
|
+
use scratch.summary < 1k
|
|
34
|
+
|
|
35
|
+
return generate({ input: "Choose the next search focus", limit: 300 }) {
|
|
36
|
+
return {
|
|
37
|
+
focus string
|
|
38
|
+
why string
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func act(question, thought) {
|
|
44
|
+
raw_query = Search.query(question, thought)
|
|
45
|
+
raw_result = Search.search(raw_query)
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
query: raw_query.summary,
|
|
49
|
+
result: {
|
|
50
|
+
summary: raw_result.summary,
|
|
51
|
+
source: raw_result.source
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
func observe(action) {
|
|
57
|
+
raw = {
|
|
58
|
+
query: action.query,
|
|
59
|
+
summary: action.result.summary,
|
|
60
|
+
source: action.result.source
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
use raw
|
|
64
|
+
|
|
65
|
+
return generate({ input: "Summarize the useful observation", limit: 400 }) {
|
|
66
|
+
return {
|
|
67
|
+
facts list[string]
|
|
68
|
+
source string
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
func enough(question, scratch) {
|
|
74
|
+
use question
|
|
75
|
+
use scratch.summary < 1k
|
|
76
|
+
|
|
77
|
+
verdict = generate({ input: "Decide whether the observations are enough", limit: 200 }) {
|
|
78
|
+
return {
|
|
79
|
+
done boolean
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return verdict.done
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func answer(question, scratch) {
|
|
87
|
+
use question
|
|
88
|
+
use scratch.summary < 2k
|
|
89
|
+
|
|
90
|
+
return generate({ input: "Answer using only the observations", limit: 800 }) {
|
|
91
|
+
return {
|
|
92
|
+
ok boolean
|
|
93
|
+
text string
|
|
94
|
+
error string
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
main agent ReplGuide {
|
|
2
|
+
role "REPL Guide"
|
|
3
|
+
description "Show a small AgentScript program that can be loaded and run in the REPL."
|
|
4
|
+
|
|
5
|
+
main func(input {}) {
|
|
6
|
+
commands = [
|
|
7
|
+
{
|
|
8
|
+
command: ":load examples/repl.as",
|
|
9
|
+
purpose: "Load this teaching agent into the REPL session."
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
command: ":check",
|
|
13
|
+
purpose: "Parse and semantically check the current REPL program."
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
command: ":run {}",
|
|
17
|
+
purpose: "Run the main agent with an empty JSON input."
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
command: ":trace pretty",
|
|
21
|
+
purpose: "Print the latest run trace in a readable form."
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
ok: true,
|
|
27
|
+
title: "AgentScript REPL quick start",
|
|
28
|
+
commands: commands
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import llm Qwen from "ollama://localhost:11434/qwen3.6"
|
|
2
|
+
import memory Lessons from "file://./.agentscript/self-improve-lessons.jsonl"
|
|
3
|
+
|
|
4
|
+
main agent SelfImprover {
|
|
5
|
+
model Qwen
|
|
6
|
+
role "Self-improving assistant"
|
|
7
|
+
description "Read relevant lessons, answer the goal, then store a new lesson."
|
|
8
|
+
|
|
9
|
+
main func(input {
|
|
10
|
+
goal string
|
|
11
|
+
}) {
|
|
12
|
+
past = Lessons.query({
|
|
13
|
+
kind: "lesson"
|
|
14
|
+
text: input.goal
|
|
15
|
+
limit: 5
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
use input.goal
|
|
19
|
+
use past < 2k
|
|
20
|
+
|
|
21
|
+
result = generate({
|
|
22
|
+
input: "Answer the goal using any relevant lessons.",
|
|
23
|
+
attempts: 3
|
|
24
|
+
}) {
|
|
25
|
+
return {
|
|
26
|
+
ok boolean
|
|
27
|
+
answer string
|
|
28
|
+
reason string
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
lesson = reflect({
|
|
33
|
+
goal: input.goal
|
|
34
|
+
result: result
|
|
35
|
+
past: past
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
Lessons.add({
|
|
39
|
+
kind: "lesson"
|
|
40
|
+
text: lesson.insight
|
|
41
|
+
goal: input.goal
|
|
42
|
+
ok: result.ok
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return result
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func reflect(run) {
|
|
49
|
+
use run
|
|
50
|
+
|
|
51
|
+
return generate({
|
|
52
|
+
input: "Extract one durable lesson that could improve a future run.",
|
|
53
|
+
attempts: 3
|
|
54
|
+
}) {
|
|
55
|
+
return {
|
|
56
|
+
insight string
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|