@misterscan/sesi 1.2.3 → 1.3.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/.agents/rules/sesi-must-read.md +116 -0
- package/.agents/workflows/create-sesi-script.md +44 -0
- package/.agents/workflows/fix-sesi-script.md +14 -0
- package/.github/prompts/MakeInSesi.prompt.md +79 -0
- package/README.md +163 -51
- package/bin/sesi.js +196 -38
- package/chatbot/chatbot.html +488 -0
- package/{main → chatbot}/chatbot.sesi +1 -2
- package/chatbot/chatbot_server.py +105 -0
- package/chatbot/sesi_db_chatbot.sesi +278 -0
- package/dist/ai-runtime.js +2 -2
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +199 -5
- package/dist/builtins.js.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -6
- package/dist/index.js.map +1 -1
- package/dist/interpreter.d.ts +21 -2
- package/dist/interpreter.d.ts.map +1 -1
- package/dist/interpreter.js +201 -92
- package/dist/interpreter.js.map +1 -1
- package/dist/lexer.d.ts.map +1 -1
- package/dist/lexer.js +8 -4
- package/dist/lexer.js.map +1 -1
- package/dist/parser.d.ts +1 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +21 -12
- package/dist/parser.js.map +1 -1
- package/dist/sesi.bundled.js +2526 -1487
- package/dist/types.d.ts +14 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +33 -1
- package/dist/types.js.map +1 -1
- package/docs/ARCHITECTURE.md +21 -13
- package/docs/BUILTINS.md +136 -19
- package/docs/CLI.md +200 -0
- package/docs/COMPARISON.md +16 -13
- package/docs/IMAGE_GENERATION.md +13 -14
- package/docs/IMPLEMENTATION_SUMMARY.md +174 -110
- package/docs/QUICKSTART.md +173 -39
- package/docs/README.md +202 -54
- package/docs/{SYSTEMS_REASONING.md → REASONING.md} +115 -120
- package/docs/ROADMAP.md +51 -47
- package/docs/SKILLS.md +73 -98
- package/docs/SPECIFICATION.md +59 -40
- package/examples/03_functions.sesi +30 -1
- package/examples/07_prompts.sesi +27 -3
- package/examples/08_model_call.sesi +6 -4
- package/examples/09_structured_output.sesi +19 -3
- package/examples/10_code_generation.sesi +6 -4
- package/examples/11_memory_conversation.sesi +47 -15
- package/examples/12_classification.sesi +62 -7
- package/examples/13_data_pipeline.sesi +55 -28
- package/examples/14_folder_explainer.sesi +52 -51
- package/examples/15_image_generation.sesi +15 -14
- package/examples/16_modules.sesi +27 -27
- package/examples/19_search_web.sesi +18 -2
- package/examples/20_model_aliases.sesi +22 -0
- package/examples/21_custom_tools.sesi +27 -0
- package/examples/22_reasoning_plus_custom_tools.sesi +19 -0
- package/main/tests/test-args.sesi +7 -0
- package/main/tests/test_args.sesi +7 -0
- package/main/tests/test_general_modules.sesi +127 -0
- package/main/tests/test_grounding.sesi +2 -0
- package/package.json +26 -22
- package/docs/DISTRIBUTED_SYSTEMS.md +0 -71
- package/docs/sesi_ai_chronicles.md +0 -209
- package/main/conversational_classifier_weights.json +0 -45
- package/main/conversational_sentences.json +0 -304
- package/main/epochs.sesi +0 -94
- package/main/gpu_orchestrator.sesi +0 -36
- package/main/hardware_diagnostics.sesi +0 -118
- package/main/inference.sesi +0 -54
- package/main/native_chatbot.sesi +0 -180
- package/main/native_synthesizer.sesi +0 -83
- package/main/nn_personas_trainer.sesi +0 -302
- package/main/nn_responses_trainer.sesi +0 -269
- package/main/nn_sentences_trainer.sesi +0 -330
- package/main/orchestrator.sesi +0 -15
- package/main/personas.json +0 -124
- package/main/personas_classifier_weights.json +0 -45
- package/main/playground.sesi +0 -3
- package/main/predictive_typing.sesi +0 -127
- package/main/query_brain.sesi +0 -45
- package/main/response_classifier_weights.json +0 -45
- package/main/retro_chat.html +0 -239
- package/main/retro_chat_generator.sesi +0 -745
- package/main/sesi_ai.sesi +0 -158
- package/main/sesi_db_chatbot.sesi +0 -280
- package/main/setup_swarm.sesi +0 -5
- package/main/start.sesi +0 -13
- package/main/terminal.log +0 -56
- package/main/terminal_chat.py +0 -385
- package/main/unified_sesi_ai.sesi +0 -334
- package/main/varied_responses.json +0 -304
|
@@ -1,69 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Reasoning & Simple Logic
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
In Sesi, Reasoning is used to evaluate state, make logical decisions, and handle complex patterns. This guide covers how to leverage Sesi's built-in Reasoning functions (`model`, `image`, `workflow`) to build scripts for your designated needs.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 1. Prompting
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
The core of Sesi's power lies in its ability to manage distributed execution. Using the `spawn()` builtin, you can launch multiple concurrent Sesi processes that coordinate via shared state or the filesystem.
|
|
12
|
-
|
|
13
|
-
A master script can launch concurrent processes and poll for their completion.
|
|
14
|
-
|
|
15
|
-
```sesi
|
|
16
|
-
spawn("atm_deposit.sesi")
|
|
17
|
-
spawn("atm_withdraw.sesi")
|
|
18
|
-
let finished = false
|
|
19
|
-
while !finished {
|
|
20
|
-
try {
|
|
21
|
-
if read_file("bank/done_count.txt") == "2" {
|
|
22
|
-
finished = true
|
|
23
|
-
}
|
|
24
|
-
} catch (e) {
|
|
25
|
-
// Wait on I/O contention
|
|
26
|
-
let i = 0 while i < 1000 { i = i + 1 }
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
print "Swarm task completed."
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Coordination & Distributed Locking
|
|
33
|
-
|
|
34
|
-
When multiple processes access shared resources, use Sesi's `try/catch`, `time()`, and `random()` builtins to implement mutual exclusion (locking) via the **Double-Check Write** pattern.
|
|
35
|
-
|
|
36
|
-
```sesi
|
|
37
|
-
let id = "With_" + str(time()) + "_" + str(random())
|
|
38
|
-
let locked = true
|
|
39
|
-
while locked {
|
|
40
|
-
let status = "error"
|
|
41
|
-
try {
|
|
42
|
-
status = read_file("bank/lock.txt")
|
|
43
|
-
} catch (e) {
|
|
44
|
-
status = "error"
|
|
45
|
-
}
|
|
46
|
-
if status == "unlocked" {
|
|
47
|
-
try {
|
|
48
|
-
write_file("bank/lock.txt", id)
|
|
49
|
-
let i = 0 while i < 500 { i = i + 1 }
|
|
50
|
-
if read_file("bank/lock.txt") == id {
|
|
51
|
-
locked = false
|
|
52
|
-
}
|
|
53
|
-
} catch (e) {
|
|
54
|
-
status = "error"
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
let j = 0 while j < 1000 { j = j + 1 }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
|
-
## 2. AI as a Reasoning Primitive
|
|
65
|
-
|
|
66
|
-
In an orchestrated system, AI is used to make decisions that would be too complex for static logic.
|
|
9
|
+
In Sesi, calling a reasoning model is as simple as defining a string and executing it.
|
|
67
10
|
|
|
68
11
|
Prompts are **composable message templates** that evaluate to strings.
|
|
69
12
|
|
|
@@ -102,7 +45,7 @@ print translatePrompt(text, language)
|
|
|
102
45
|
|
|
103
46
|
## 2. Model Calls
|
|
104
47
|
|
|
105
|
-
Call
|
|
48
|
+
Call a Reasoning model with a prompt and get back text.
|
|
106
49
|
|
|
107
50
|
### Basic Model Call
|
|
108
51
|
|
|
@@ -119,16 +62,17 @@ print creative
|
|
|
119
62
|
|
|
120
63
|
// Config options:
|
|
121
64
|
// - thinkingLevel: "minimal", "low", "medium", "high" (natively configures Gemini's reasoning budget)
|
|
122
|
-
// - max_tokens: max length of response (OPTIONAL: if not specified, will use the model's default max tokens=
|
|
123
|
-
// - temperature
|
|
65
|
+
// - max_tokens: max length of response (OPTIONAL: if not specified, will use the model's default max tokens=4096)
|
|
66
|
+
// - temperature: creative variation (OPTIONAL: defaults to 0.1 for high-fidelity reasoning precision)
|
|
67
|
+
// - top_k / top_p: parameter options for specialized sampling configurations
|
|
124
68
|
```
|
|
125
69
|
|
|
126
70
|
### Model Selection
|
|
127
71
|
|
|
128
72
|
```sesi
|
|
129
73
|
// Fast model for simple tasks
|
|
130
|
-
let text = "
|
|
131
|
-
let quick = model("gemini-3.1-flash-lite") {"Summarize this in one sentence:" text}
|
|
74
|
+
let text = "Coding with Reasoning programming language is fun!"
|
|
75
|
+
let quick = model("gemini-3.1-flash-lite") {"Summarize this in one sentence: " text}
|
|
132
76
|
|
|
133
77
|
// Powerful model for complex reasoning
|
|
134
78
|
let code = "def calculate_sum(n):
|
|
@@ -136,25 +80,25 @@ let code = "def calculate_sum(n):
|
|
|
136
80
|
for i in range(1, n):
|
|
137
81
|
total += i
|
|
138
82
|
return total"
|
|
139
|
-
let smart = model("gemini-3.1-pro-preview") {"Analyze this code for bugs:" code}
|
|
83
|
+
let smart = model("gemini-3.1-pro-preview") {"Analyze this code for bugs: " code}
|
|
140
84
|
|
|
141
85
|
// Efficient model for many calls
|
|
142
|
-
let item = "
|
|
143
|
-
let cheap = model("gemini-3.5-flash") {thinkingLevel: "minimal"} {"Classify:" item}
|
|
86
|
+
let item = "Programming Languages"
|
|
87
|
+
let cheap = model("gemini-3.5-flash") {thinkingLevel: "minimal"} {"Classify: " item}
|
|
144
88
|
|
|
145
89
|
print quick
|
|
146
90
|
print smart
|
|
147
91
|
print cheap
|
|
148
92
|
```
|
|
149
93
|
|
|
150
|
-
### Available Models (v1.
|
|
94
|
+
### Available Models (v1.3)
|
|
151
95
|
|
|
152
96
|
- `gemini-2.5-flash` - Legacy, but supported. 1M tokens.
|
|
153
97
|
- `gemini-2.5-pro` - Legacy, but supported. 1M tokens.
|
|
154
98
|
- `gemini-2.5-flash-image` - Standard image model. (No `512` image size support for this model. Only `1K` is supported.)
|
|
155
|
-
- `gemini-3-flash-preview` - Fast, balanced
|
|
99
|
+
- `gemini-3-flash-preview` - Fast, most balanced model for coding and minimal tasks.
|
|
156
100
|
- `gemini-3.1-flash-lite` - Fastest, most cost-efficient.
|
|
157
|
-
- `gemini-3.5-flash` -
|
|
101
|
+
- `gemini-3.5-flash` - Newest GA model. Balanced, but token hungry (USE WISELY) supports all native thinking effort levels (`minimal`, `low`, `medium`, `high`).
|
|
158
102
|
- `gemini-3.1-pro-preview` - Most powerful reasoning model, doesn't support `minimal` thinking (falls back to `low`).
|
|
159
103
|
- `gemini-3.1-flash-image-preview` - Cost efficient image generation model.
|
|
160
104
|
- `gemini-3-pro-image-preview` - High quality image generation model. (No `512` image size support for this model.)
|
|
@@ -183,7 +127,7 @@ print diff
|
|
|
183
127
|
|
|
184
128
|
// Mixed with other config keys
|
|
185
129
|
let scannedDocument = "doc_scan.jpg"
|
|
186
|
-
let result = model("gemini-3.5-flash") {images: scannedDocument, thinkingLevel: "low", max_tokens:
|
|
130
|
+
let result = model("gemini-3.5-flash") {images: scannedDocument, thinkingLevel: "low", max_tokens: 4096} {"Transcribe all text visible in this scan."}
|
|
187
131
|
write_file("transcript.txt", result)
|
|
188
132
|
```
|
|
189
133
|
|
|
@@ -196,8 +140,7 @@ Get typed responses from Reasoning with field validation.
|
|
|
196
140
|
### Basic Structured Output
|
|
197
141
|
|
|
198
142
|
```sesi
|
|
199
|
-
let analysis = structured_output({sentiment: string, confidence: number, summary: string})
|
|
200
|
-
(model("gemini-3-flash-preview") {"Analyze sentiment of: " text "Return JSON with sentiment, confidence (0-1), and summary"})
|
|
143
|
+
let analysis = structured_output({sentiment: string, confidence: number, summary: string})(model("gemini-3-flash-preview") {"Analyze sentiment of: " text "Return JSON with sentiment, confidence (0-1), and summary"})
|
|
201
144
|
print analysis["sentiment"] // "positive"
|
|
202
145
|
print analysis["confidence"] // 0.85
|
|
203
146
|
print analysis["summary"] // "..."
|
|
@@ -216,12 +159,12 @@ print bookInfo["title"]
|
|
|
216
159
|
|
|
217
160
|
- Always include instructions for JSON format
|
|
218
161
|
- Specify the exact schema in the prompt
|
|
219
|
-
- Use "thinkingLevel": "
|
|
162
|
+
- Use "thinkingLevel": "minimal" for fast, consistent parsing
|
|
220
163
|
- Validate output structure in code
|
|
221
164
|
|
|
222
165
|
```sesi
|
|
223
166
|
let listText = "eggs, milk, bread, cheese, fruit, vegetables"
|
|
224
|
-
let output = structured_output({items: string})(model("gemini-3.5-flash") {thinkingLevel: "minimal"}{"Return JSON with items array containing: " listText})
|
|
167
|
+
let output = structured_output({items: string})(model("gemini-3.5-flash") {thinkingLevel: "minimal"} {"Return JSON with items array containing: " listText})
|
|
225
168
|
|
|
226
169
|
// Validate
|
|
227
170
|
if type(output["items"]) == "array" {print "Got" str(len(output["items"])) "items"} // Got 6 items
|
|
@@ -236,12 +179,12 @@ Let Reasoning call functions in your program.
|
|
|
236
179
|
```sesi
|
|
237
180
|
let city = "New York"
|
|
238
181
|
fn getWeather(city: string) -> string
|
|
239
|
-
{let weather = model("gemini-3.1-flash-lite"){"What is the weather like in " city}
|
|
182
|
+
{let weather = model("gemini-3.1-flash-lite") {"What is the weather like in " city}
|
|
183
|
+
return weather}
|
|
240
184
|
let result = getWeather(city)
|
|
241
185
|
print result
|
|
242
186
|
|
|
243
187
|
// When defined inside a function, local variables MUST be defined on new lines.
|
|
244
|
-
// (A current limitation of the parser).
|
|
245
188
|
fn calculateTax(amount: number, rate: number) -> number
|
|
246
189
|
{let amount = 100
|
|
247
190
|
let rate = 0.08
|
|
@@ -289,11 +232,11 @@ print response2 // Has context from turn 1
|
|
|
289
232
|
```sesi
|
|
290
233
|
memory conversation {"Chat history: "}
|
|
291
234
|
fn chat(userMessage: string) -> string
|
|
292
|
-
{let fullPrompt = conversation + "User:" + userMessage
|
|
235
|
+
{let fullPrompt = conversation + "User: " + userMessage
|
|
293
236
|
let response = model("gemini-3-flash-preview") {fullPrompt}
|
|
294
237
|
|
|
295
238
|
// Append to memory
|
|
296
|
-
conversation = conversation + "User:" + userMessage + "Assistant:" + response
|
|
239
|
+
conversation = conversation + "User: " + userMessage + "Assistant: " + response
|
|
297
240
|
return response}
|
|
298
241
|
let msg = "What is the capital of France? "
|
|
299
242
|
print "User:" msg
|
|
@@ -313,7 +256,7 @@ print "Updated Memory!"
|
|
|
313
256
|
memory conversation {"User: Hello! Assistant: Hi there! User: How are you? Assistant: I'm great!"}
|
|
314
257
|
fn summarizeMemory()
|
|
315
258
|
{let oldConversation = conversation
|
|
316
|
-
let summary = model("gemini-3.1-flash-lite") {"Summarize this conversation concisely:" oldConversation}
|
|
259
|
+
let summary = model("gemini-3.1-flash-lite") {"Summarize this conversation concisely: " oldConversation}
|
|
317
260
|
conversation = "Previous summary:" + summary + "Recent messages: " + oldConversation}
|
|
318
261
|
print "Original Memory:" conversation
|
|
319
262
|
summarizeMemory()
|
|
@@ -329,8 +272,7 @@ print conversation
|
|
|
329
272
|
let categories = "fruit, vegetable, grain"
|
|
330
273
|
let item = "banana"
|
|
331
274
|
fn classify(item: string, categories: string) -> string
|
|
332
|
-
{return model("gemini-3.5-flash") {thinkingLevel: "minimal"}
|
|
333
|
-
{"Classify this item into one category. Categories: " categories " Item: " item " Return only the category name."}}
|
|
275
|
+
{return model("gemini-3.5-flash") {thinkingLevel: "minimal"} {"Classify this item into one category. Categories: " categories " Item: " item " Return only the category name."}}
|
|
334
276
|
print "Item: " item //banana
|
|
335
277
|
print "Category: " classify(item, categories) //fruit
|
|
336
278
|
```
|
|
@@ -340,8 +282,7 @@ print "Category: " classify(item, categories) //fruit
|
|
|
340
282
|
```sesi
|
|
341
283
|
let text = "Elon Musk is the CEO of Tesla and SpaceX."
|
|
342
284
|
fn extractEntities(text: string) -> object
|
|
343
|
-
{let result = structured_output({people: string, places: string, organizations: string})
|
|
344
|
-
(model("gemini-3.5-flash") {thinkingLevel: "minimal"}{"Extract named entities from:" text})
|
|
285
|
+
{let result = structured_output({people: string, places: string, organizations: string})(model("gemini-3.5-flash") {thinkingLevel: "minimal"} {"Extract named entities from: " text})
|
|
345
286
|
print "Name(s) found: result"
|
|
346
287
|
return result}
|
|
347
288
|
print extractEntities(text)
|
|
@@ -354,9 +295,8 @@ print extractEntities(text)
|
|
|
354
295
|
let text = "Hello, world!"
|
|
355
296
|
let language = "Spanish"
|
|
356
297
|
fn translate(text: string, language: string) -> string
|
|
357
|
-
{return model("gemini-3-flash-preview") {"Translate to" language ":" text}}
|
|
358
|
-
print "Translation:"
|
|
359
|
-
print translate(text, language)
|
|
298
|
+
{return model("gemini-3-flash-preview") {"Translate to " language ": " text}}
|
|
299
|
+
print "Translation:" translate(text, language)
|
|
360
300
|
```
|
|
361
301
|
|
|
362
302
|
### Web Search Grounding
|
|
@@ -364,7 +304,8 @@ print translate(text, language)
|
|
|
364
304
|
Access real-time information by enabling the `search` shorthand configuration natively.
|
|
365
305
|
|
|
366
306
|
```sesi
|
|
367
|
-
let response = model("gemini-3.1-flash-lite") {search, max_tokens:
|
|
307
|
+
let response = model("gemini-3.1-flash-lite") {search, max_tokens: 200} {"What is the weather in Tokyo right now?"}
|
|
308
|
+
print response
|
|
368
309
|
```
|
|
369
310
|
|
|
370
311
|
### Image Generation
|
|
@@ -384,7 +325,7 @@ print "Image generated!"
|
|
|
384
325
|
```sesi
|
|
385
326
|
let requirement = "Write a function that reverses a string."
|
|
386
327
|
fn generateCode(requirement: string) -> string
|
|
387
|
-
{return model("gemini-3.5-flash") {thinkingLevel: "low"} {"Generate JavaScript code for:" requirement "Only provide code, no explanation."}}
|
|
328
|
+
{return model("gemini-3.5-flash") {thinkingLevel: "low"} {"Generate JavaScript code for: " requirement " Only provide code, no explanation."}}
|
|
388
329
|
print "Code generation:"
|
|
389
330
|
print generateCode(requirement)
|
|
390
331
|
```
|
|
@@ -394,8 +335,7 @@ print generateCode(requirement)
|
|
|
394
335
|
```sesi
|
|
395
336
|
let text = "I love Sesi!"
|
|
396
337
|
fn analyzeSentiment(text: string) -> object
|
|
397
|
-
{return structured_output({sentiment: string, score: number, explanation: string})
|
|
398
|
-
(model("gemini-3-flash-preview") {"Analyze sentiment of:" text})}
|
|
338
|
+
{return structured_output({sentiment: string, score: number, explanation: string})(model("gemini-3-flash-preview") {"Analyze sentiment of: " text})}
|
|
399
339
|
print "Sentiment analysis:"
|
|
400
340
|
print analyzeSentiment(text)
|
|
401
341
|
```
|
|
@@ -404,11 +344,11 @@ print analyzeSentiment(text)
|
|
|
404
344
|
|
|
405
345
|
Reasoning operations can fail. Handle gracefully.
|
|
406
346
|
|
|
407
|
-
### Try/Catch (v1.
|
|
347
|
+
### Try/Catch (v1.3)
|
|
408
348
|
|
|
409
349
|
```sesi
|
|
410
350
|
try
|
|
411
|
-
{let response = model("gemini-3-flash-preview") {"Analyze" text}
|
|
351
|
+
{let response = model("gemini-3-flash-preview") {"Analyze " text}
|
|
412
352
|
print response}
|
|
413
353
|
catch (e) {print "Reasoning call failed"
|
|
414
354
|
print e}
|
|
@@ -426,14 +366,13 @@ print e}
|
|
|
426
366
|
let text = "Coding is evolving rapidly!"
|
|
427
367
|
fn safeAnalyze(text: string) {
|
|
428
368
|
try
|
|
429
|
-
{let result = structured_output({sentiment: string, score: number})(model("gemini-3.1-flash-lite") {"Analyze sentiment and return JSON for:" text})
|
|
369
|
+
{let result = structured_output({sentiment: string, score: number})(model("gemini-3.1-flash-lite") {"Analyze sentiment, score, and return JSON for: " text})
|
|
430
370
|
if len(keys(result)) == 0 {print "Structured parsing failed"
|
|
431
371
|
return null}
|
|
432
|
-
return result
|
|
433
|
-
catch (e)
|
|
434
|
-
{print e
|
|
372
|
+
return result
|
|
373
|
+
} catch (e) {print e
|
|
435
374
|
return null}}
|
|
436
|
-
print "Analysis Result:
|
|
375
|
+
print "Analysis Result:" safeAnalyze(text)
|
|
437
376
|
```
|
|
438
377
|
|
|
439
378
|
## 8. Performance Tips
|
|
@@ -443,11 +382,11 @@ print "Analysis Result: " safeAnalyze(text)
|
|
|
443
382
|
```sesi
|
|
444
383
|
// Bad: Calls API 3 times
|
|
445
384
|
for item in items
|
|
446
|
-
{let analysis = model("gemini-3.1-flash-lite") {"Analyze:" item}}
|
|
385
|
+
{let analysis = model("gemini-3.1-flash-lite") {"Analyze: " item}}
|
|
447
386
|
print analysis
|
|
448
387
|
|
|
449
388
|
// Better: Batch into one call (v2: parallel calls)
|
|
450
|
-
let analyses = model("gemini-3.1-flash-lite") {"Analyze each:" join(items, " ")}
|
|
389
|
+
let analyses = model("gemini-3.1-flash-lite") {"Analyze each: " join(items, " ")}
|
|
451
390
|
print analyses
|
|
452
391
|
```
|
|
453
392
|
|
|
@@ -455,11 +394,11 @@ print analyses
|
|
|
455
394
|
|
|
456
395
|
```sesi
|
|
457
396
|
// Simple classification → flash-lite
|
|
458
|
-
let category = model("gemini-3.1-flash-lite") {"Classify:" item}
|
|
397
|
+
let category = model("gemini-3.1-flash-lite") {"Classify: " item}
|
|
459
398
|
print category
|
|
460
399
|
|
|
461
400
|
// Complex reasoning → pro
|
|
462
|
-
let analysis = model("gemini-3.1-pro-preview") {"Deep analysis of:" complex_problem}
|
|
401
|
+
let analysis = model("gemini-3.1-pro-preview") {"Deep analysis of: " complex_problem}
|
|
463
402
|
print analysis
|
|
464
403
|
```
|
|
465
404
|
|
|
@@ -468,7 +407,7 @@ print analysis
|
|
|
468
407
|
```sesi
|
|
469
408
|
// Long prompts waste tokens
|
|
470
409
|
// Bad:
|
|
471
|
-
let response = model("gemini-3-flash-preview") {"Here is a very long system prompt that repeats itself...
|
|
410
|
+
let response = model("gemini-3-flash-preview") {"Here is a very long system prompt that repeats itself... Please analyze the following text very carefully..." text}
|
|
472
411
|
print response
|
|
473
412
|
|
|
474
413
|
// Better:
|
|
@@ -480,14 +419,17 @@ print response
|
|
|
480
419
|
|
|
481
420
|
```sesi
|
|
482
421
|
// Bad: Same analysis done multiple times
|
|
483
|
-
for person in people
|
|
422
|
+
for person in people
|
|
423
|
+
{let assessment = model("gemini-3.1-flash-lite") {"Assess based on criteria A, B, C: " person}}
|
|
484
424
|
print assessment
|
|
485
425
|
|
|
486
426
|
|
|
487
427
|
// Better: Reuse cached prompt
|
|
488
428
|
let people = ["Elon Musk", "Bill Gates", "Steve Jobs"]
|
|
489
|
-
fn assessPerson(person: string) -> string
|
|
490
|
-
|
|
429
|
+
fn assessPerson(person: string) -> string
|
|
430
|
+
{return model("gemini-3.1-flash-lite") {"Assess on A, B, C: " person}}
|
|
431
|
+
for person in people
|
|
432
|
+
{print assessPerson(person)}
|
|
491
433
|
```
|
|
492
434
|
|
|
493
435
|
## 9. Token Counting (Future)
|
|
@@ -502,7 +444,7 @@ print "This costs " str(tokens * PRICE_PER_TOKEN) " cents"
|
|
|
502
444
|
// Plan memory size
|
|
503
445
|
let remaining = MAX_TOKENS - count_tokens(memory, model)
|
|
504
446
|
if remaining < 500 {summarizeMemory()}
|
|
505
|
-
print "Memory size:
|
|
447
|
+
print "Memory size:" count_tokens(memory, model)
|
|
506
448
|
```
|
|
507
449
|
|
|
508
450
|
## 10. Advanced: Custom Reasoning Workflows
|
|
@@ -515,20 +457,21 @@ fn smartSummarize(text: string) -> string
|
|
|
515
457
|
|
|
516
458
|
// Chain multiple Reasoning operations
|
|
517
459
|
// Step 1: Extract key points
|
|
518
|
-
{let keyPoints = model("gemini-3.1-pro-preview") {thinkingLevel: "low"} {"Extract 5 key points from:" text}
|
|
460
|
+
{let keyPoints = model("gemini-3.1-pro-preview") {thinkingLevel: "low"} {"Extract 5 key points from: " text}
|
|
519
461
|
|
|
520
462
|
// Step 2: Analyze topics
|
|
521
|
-
let topics = structured_output({
|
|
463
|
+
let topics = structured_output({topics: string})(model("gemini-3.5-flash") {thinkingLevel: "low"} {"Identify topics in: " keyPoints})
|
|
522
464
|
|
|
523
465
|
// Step 3: Generate summary
|
|
524
|
-
let summary = model("gemini-3-flash-preview") {"Summarize with topics " topics ":" keyPoints}
|
|
466
|
+
let summary = model("gemini-3-flash-preview") {"Summarize with topics " topics ": " keyPoints}
|
|
467
|
+
return summary}
|
|
525
468
|
print "Summary:" smartSummarize(text)
|
|
526
469
|
```
|
|
527
470
|
|
|
528
471
|
### Reasoning Pattern
|
|
529
472
|
|
|
530
473
|
```sesi
|
|
531
|
-
let analysis = model("gemini-3.5-flash") {thinkingLevel: "medium", max_tokens: 8192} {"Reason carefully about:" problem}
|
|
474
|
+
let analysis = model("gemini-3.5-flash") {thinkingLevel: "medium", max_tokens: 8192} {"Reason carefully about: " problem}
|
|
532
475
|
print analysis
|
|
533
476
|
```
|
|
534
477
|
|
|
@@ -537,18 +480,70 @@ print analysis
|
|
|
537
480
|
```sesi
|
|
538
481
|
let text = "banana"
|
|
539
482
|
fn classifyWithExamples(text: string) -> string
|
|
540
|
-
{return model("gemini-3.5-flash") {thinkingLevel: "minimal"} {"Classify as A, B, or C
|
|
483
|
+
{return model("gemini-3.5-flash") {thinkingLevel: "minimal"} {"Classify as A, B, or C. Examples: 'apple' -> A , 'dog' -> B , 'happy' -> C. Classify: " text}}
|
|
541
484
|
print "Classification:" classifyWithExamples(text)
|
|
542
485
|
```
|
|
543
486
|
|
|
544
487
|
---
|
|
545
488
|
|
|
489
|
+
## 11. Built-in Tools
|
|
490
|
+
|
|
491
|
+
### Built-in Workflows
|
|
492
|
+
|
|
493
|
+
Sesi provides a native `workflow` function to easily chain reasoning steps:
|
|
494
|
+
|
|
495
|
+
```sesi
|
|
496
|
+
let steps = [
|
|
497
|
+
{"prompt": "Summarize:"},
|
|
498
|
+
{"prompt": "Critique:"},
|
|
499
|
+
{"prompt": "Finalize:"}
|
|
500
|
+
]
|
|
501
|
+
let result = workflow(steps, "Design a landing page brief")
|
|
502
|
+
print result["final"]
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### Model Aliases
|
|
506
|
+
|
|
507
|
+
You can define custom names for models using `set_alias`:
|
|
508
|
+
|
|
509
|
+
```sesi
|
|
510
|
+
set_alias("fast", "gemini-3.1-flash-lite")
|
|
511
|
+
let answer = model("fast") {"Summarize this paragraph."}
|
|
512
|
+
print answer
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### Custom Tools
|
|
516
|
+
|
|
517
|
+
Sesi allows you to define custom tools that can be invoked during reasoning operations.
|
|
518
|
+
|
|
519
|
+
```sesi
|
|
520
|
+
fn get_weather(city: string, conditions: string) -> string
|
|
521
|
+
{return "It is currently " + conditions + " in " + city}
|
|
522
|
+
// Register the tool
|
|
523
|
+
define_tool("weather", get_weather, "Get weather for a city")
|
|
524
|
+
|
|
525
|
+
// List available tools
|
|
526
|
+
print list_tools()
|
|
527
|
+
|
|
528
|
+
// Call the tool
|
|
529
|
+
let weatherData = structured_output({city: string, conditions: string})(model("gemini-3.1-flash-lite") {search} {"What is the weather like in London? Return JSON with the exact 'conditions' and 'city' name."})
|
|
530
|
+
let result = tool_call(weather)(weatherData["city"], weatherData["conditions"])
|
|
531
|
+
print result
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
546
536
|
## See Also
|
|
547
537
|
|
|
548
|
-
- [
|
|
538
|
+
- [Quick Start Guide](../QUICKSTART.md)
|
|
549
539
|
- [Language Specification](SPECIFICATION.md)
|
|
550
|
-
- [
|
|
551
|
-
- [
|
|
552
|
-
- [
|
|
553
|
-
- [
|
|
554
|
-
- [
|
|
540
|
+
- [Runtime Architecture](ARCHITECTURE.md)
|
|
541
|
+
- [Built-in Functions Reference](BUILTINS.md)
|
|
542
|
+
- [Command Line Interface (CLI) Reference](CLI.md)
|
|
543
|
+
- [Image Generation & Input](IMAGE_GENERATION.md)
|
|
544
|
+
- [Compare to other languages](COMPARISON.md)
|
|
545
|
+
- [Concurrency & Coordination](CONCURRENCY.md)
|
|
546
|
+
- [Reasoning & Simple Logic](REASONING.md)
|
|
547
|
+
- [Agent-Native Programming Paradigm](agent_native_programming.md)
|
|
548
|
+
- [Historical Stress Test Chronicles](sesi_ai_chronicles.md)
|
|
549
|
+
- [Examples](../examples)
|