@koi-language/koi 1.0.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/QUICKSTART.md +89 -0
- package/README.md +545 -0
- package/examples/actions-demo.koi +177 -0
- package/examples/cache-test.koi +29 -0
- package/examples/calculator.koi +61 -0
- package/examples/clear-registry.js +33 -0
- package/examples/clear-registry.koi +30 -0
- package/examples/code-introspection-test.koi +149 -0
- package/examples/counter.koi +132 -0
- package/examples/delegation-test.koi +52 -0
- package/examples/directory-import-test.koi +84 -0
- package/examples/hello-world-claude.koi +52 -0
- package/examples/hello-world.koi +52 -0
- package/examples/hello.koi +24 -0
- package/examples/mcp-example.koi +70 -0
- package/examples/multi-event-handler-test.koi +144 -0
- package/examples/new-import-test.koi +89 -0
- package/examples/pipeline.koi +162 -0
- package/examples/registry-demo.koi +184 -0
- package/examples/registry-playbook-demo.koi +162 -0
- package/examples/registry-playbook-email-compositor-2.koi +140 -0
- package/examples/registry-playbook-email-compositor.koi +140 -0
- package/examples/sentiment.koi +90 -0
- package/examples/simple.koi +48 -0
- package/examples/skill-import-test.koi +76 -0
- package/examples/skills/advanced/index.koi +95 -0
- package/examples/skills/math-operations.koi +69 -0
- package/examples/skills/string-operations.koi +56 -0
- package/examples/task-chaining-demo.koi +244 -0
- package/examples/test-await.koi +22 -0
- package/examples/test-crypto-sha256.koi +196 -0
- package/examples/test-delegation.koi +41 -0
- package/examples/test-multi-team-routing.koi +258 -0
- package/examples/test-no-handler.koi +35 -0
- package/examples/test-npm-import.koi +67 -0
- package/examples/test-parse.koi +10 -0
- package/examples/test-peers-with-team.koi +59 -0
- package/examples/test-permissions-fail.koi +20 -0
- package/examples/test-permissions.koi +36 -0
- package/examples/test-simple-registry.koi +31 -0
- package/examples/test-typescript-import.koi +64 -0
- package/examples/test-uses-team-syntax.koi +25 -0
- package/examples/test-uses-team.koi +31 -0
- package/examples/utils/calculator.test.ts +144 -0
- package/examples/utils/calculator.ts +56 -0
- package/examples/utils/math-helpers.js +50 -0
- package/examples/utils/math-helpers.ts +55 -0
- package/examples/web-delegation-demo.koi +165 -0
- package/package.json +78 -0
- package/src/cli/koi.js +793 -0
- package/src/compiler/build-optimizer.js +447 -0
- package/src/compiler/cache-manager.js +274 -0
- package/src/compiler/import-resolver.js +369 -0
- package/src/compiler/parser.js +7542 -0
- package/src/compiler/transpiler.js +1105 -0
- package/src/compiler/typescript-transpiler.js +148 -0
- package/src/grammar/koi.pegjs +767 -0
- package/src/runtime/action-registry.js +172 -0
- package/src/runtime/actions/call-skill.js +45 -0
- package/src/runtime/actions/format.js +115 -0
- package/src/runtime/actions/print.js +42 -0
- package/src/runtime/actions/registry-delete.js +37 -0
- package/src/runtime/actions/registry-get.js +37 -0
- package/src/runtime/actions/registry-keys.js +33 -0
- package/src/runtime/actions/registry-search.js +34 -0
- package/src/runtime/actions/registry-set.js +50 -0
- package/src/runtime/actions/return.js +31 -0
- package/src/runtime/actions/send-message.js +58 -0
- package/src/runtime/actions/update-state.js +36 -0
- package/src/runtime/agent.js +1368 -0
- package/src/runtime/cli-logger.js +205 -0
- package/src/runtime/incremental-json-parser.js +201 -0
- package/src/runtime/index.js +33 -0
- package/src/runtime/llm-provider.js +1372 -0
- package/src/runtime/mcp-client.js +1171 -0
- package/src/runtime/planner.js +273 -0
- package/src/runtime/registry-backends/keyv-sqlite.js +215 -0
- package/src/runtime/registry-backends/local.js +260 -0
- package/src/runtime/registry.js +162 -0
- package/src/runtime/role.js +14 -0
- package/src/runtime/router.js +395 -0
- package/src/runtime/runtime.js +113 -0
- package/src/runtime/skill-selector.js +173 -0
- package/src/runtime/skill.js +25 -0
- package/src/runtime/team.js +162 -0
package/QUICKSTART.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Koi Quick Start
|
|
2
|
+
|
|
3
|
+
**Koi** - Agent-first language. Calm orchestration. 🌊
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Clone the repository
|
|
9
|
+
git clone <repo-url>
|
|
10
|
+
cd koi
|
|
11
|
+
|
|
12
|
+
# Install dependencies and build
|
|
13
|
+
npm install
|
|
14
|
+
npm run build:grammar
|
|
15
|
+
|
|
16
|
+
# Install globally (makes 'koi' command available everywhere)
|
|
17
|
+
npm install -g .
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Verify Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
koi version
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
You should see:
|
|
27
|
+
```
|
|
28
|
+
🌊 Koi
|
|
29
|
+
Agent-first language. Calm orchestration.
|
|
30
|
+
|
|
31
|
+
Version: 1.0.0
|
|
32
|
+
Node: vX.X.X
|
|
33
|
+
Platform: ...
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Run Your First Example
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Run a simple example
|
|
40
|
+
koi run examples/simple.koi
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Set Up LLM (Optional)
|
|
44
|
+
|
|
45
|
+
For real LLM execution:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Create .env file with your API key
|
|
49
|
+
echo "OPENAI_API_KEY=your-key-here" > .env
|
|
50
|
+
|
|
51
|
+
# Run with real LLM
|
|
52
|
+
koi run examples/hello-world.koi
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Get API keys:
|
|
56
|
+
- OpenAI: https://platform.openai.com/api-keys
|
|
57
|
+
- Anthropic: https://console.anthropic.com/
|
|
58
|
+
|
|
59
|
+
## Commands
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
koi run <file> # Compile and run
|
|
63
|
+
koi compile <file> # Just compile
|
|
64
|
+
koi init <project> # Create new project
|
|
65
|
+
koi help # Show help
|
|
66
|
+
koi version # Show version
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Examples
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
koi run examples/simple.koi # Basic agent communication
|
|
73
|
+
koi run examples/calculator.koi # Procedural code
|
|
74
|
+
koi run examples/sentiment.koi # LLM skill
|
|
75
|
+
koi run examples/pipeline.koi # Multi-stage workflow
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Next Steps
|
|
79
|
+
|
|
80
|
+
1. Read the full [README.md](README.md)
|
|
81
|
+
2. **Explore the [Complete Documentation](doc/)** - Comprehensive guides on all features
|
|
82
|
+
3. Check [LLM Integration Guide](doc/06-llm-integration.md) for LLM configuration
|
|
83
|
+
4. Explore the [examples/](examples/) directory
|
|
84
|
+
5. See [Complete Examples](doc/14-examples.md) for working code samples
|
|
85
|
+
6. Create your first agent with `koi init my-project`
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
**Koi**: Agent-first language. Calm orchestration. 🌊
|
package/README.md
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="koi.png" alt="KOI Language Logo" width="400"/>
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# Koi
|
|
6
|
+
|
|
7
|
+
**Agent-first language. Calm orchestration.** 🌊
|
|
8
|
+
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://github.com/koi-language/Koi)
|
|
11
|
+
[](vscode-koi-extension/)
|
|
12
|
+
[](LINGUIST.md)
|
|
13
|
+
|
|
14
|
+
Koi is a multi-agent orchestration language with role-based routing.
|
|
15
|
+
|
|
16
|
+
## Quick Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
curl -fsSL https://raw.githubusercontent.com/koi-language/Koi/main/install.sh | bash
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> **🚀 New to Koi?** Check out the [Quick Start Guide](QUICKSTART.md) for a 2-minute setup!
|
|
23
|
+
>
|
|
24
|
+
> **📚 Complete Documentation**: See the [doc/](doc/) directory for comprehensive guides
|
|
25
|
+
|
|
26
|
+
## Architecture
|
|
27
|
+
|
|
28
|
+
### Key Concepts
|
|
29
|
+
|
|
30
|
+
- **Playbook**: Natural language instructions that define agent behavior
|
|
31
|
+
- **Agent**: Autonomous worker with a role, executes playbooks
|
|
32
|
+
- **Role**: Abstract capabilities (can delegate, can execute, can critique)
|
|
33
|
+
- **Team**: Agent composition that enables collaboration
|
|
34
|
+
- **Skill**: Reusable capability with internal logic and agents
|
|
35
|
+
- **Registry**: Shared data store for agent coordination and state persistence
|
|
36
|
+
- **Automatic Routing**: Routes by role+capability, NEVER by agent name
|
|
37
|
+
|
|
38
|
+
### 🆕 Automatic Intelligent Routing + Task Chaining
|
|
39
|
+
|
|
40
|
+
Write agent behavior in **natural language** - the system handles everything else:
|
|
41
|
+
|
|
42
|
+
- **Playbook-driven** - Write WHAT you want in plain language, not HOW to do it
|
|
43
|
+
- **Automatic decomposition** - Complex tasks break into atomic actions automatically
|
|
44
|
+
- **Task chaining** - Output of each action becomes input for the next
|
|
45
|
+
- **Intelligent routing** - Each action finds the right agent via semantic matching
|
|
46
|
+
- **Zero orchestration** - No manual wiring, no hardcoded workflows
|
|
47
|
+
- **Self-organizing** - Agents discover and collaborate automatically
|
|
48
|
+
|
|
49
|
+
See [doc/07-routing.md](doc/07-routing.md) and [doc/08-task-chaining.md](doc/08-task-chaining.md) for details.
|
|
50
|
+
|
|
51
|
+
### Execution Flow
|
|
52
|
+
|
|
53
|
+
1. **Playbook Execution**: Agent receives natural language instructions
|
|
54
|
+
2. **Automatic Planning**: System decomposes complex tasks into atomic actions
|
|
55
|
+
3. **Action Resolution**: For each action, cascading logic determines execution:
|
|
56
|
+
- Can I handle it myself? (check own handlers)
|
|
57
|
+
- Do I have a skill for this? (check local skills)
|
|
58
|
+
- Is it simple enough to execute directly? (direct execution)
|
|
59
|
+
- Can a team member handle it? (intelligent semantic routing)
|
|
60
|
+
4. **Result Chaining**: Output from each action flows to the next automatically
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
**Quick install (recommended):**
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
curl -fsSL https://raw.githubusercontent.com/koi-language/Koi/main/install.sh | bash
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
This will install KOI to `~/.koi` and add the `koi` command to your PATH.
|
|
71
|
+
|
|
72
|
+
**For manual installation, development setup, and troubleshooting:** See the [Installation Guide](doc/00-installation.md).
|
|
73
|
+
|
|
74
|
+
## Editor Support
|
|
75
|
+
|
|
76
|
+
### VS Code & Cursor Extension
|
|
77
|
+
|
|
78
|
+
Get **syntax highlighting** and language support for `.koi` files:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Quick install (from project root)
|
|
82
|
+
cd vscode-koi-extension
|
|
83
|
+
ln -s "$(pwd)" ~/.vscode/extensions/koi-lang # VS Code
|
|
84
|
+
ln -s "$(pwd)" ~/.cursor/extensions/koi-lang # Cursor
|
|
85
|
+
|
|
86
|
+
# Then restart your editor
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Features:**
|
|
90
|
+
- ✨ Full syntax highlighting
|
|
91
|
+
- 🎨 Custom "Koi Dark" theme
|
|
92
|
+
- 🔤 Auto-closing brackets and quotes
|
|
93
|
+
- 📝 Special playbook highlighting
|
|
94
|
+
- 🎯 Semantic token colors
|
|
95
|
+
|
|
96
|
+
See [vscode-koi-extension/README.md](vscode-koi-extension/README.md) for details.
|
|
97
|
+
|
|
98
|
+
## GitHub Syntax Highlighting
|
|
99
|
+
|
|
100
|
+
KOI code blocks in markdown files (README, Issues, PRs) automatically get syntax highlighting on GitHub!
|
|
101
|
+
|
|
102
|
+
````markdown
|
|
103
|
+
```koi
|
|
104
|
+
Agent Hello : Worker {
|
|
105
|
+
on greet(args: Json) {
|
|
106
|
+
console.log("Hello from KOI!")
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
````
|
|
111
|
+
|
|
112
|
+
**Status:**
|
|
113
|
+
- ✅ **Current**: Using JavaScript highlighting (very similar syntax)
|
|
114
|
+
- 🚀 **Soon**: Native KOI highlighting (PR submitted to [github/linguist](https://github.com/github/linguist))
|
|
115
|
+
|
|
116
|
+
Once the PR is merged, GitHub will recognize `.koi` files with:
|
|
117
|
+
- 🎨 Cornflower Blue (#6495ED) in language statistics
|
|
118
|
+
- ✨ Full syntax highlighting for code blocks
|
|
119
|
+
- 📊 Language detection in repositories
|
|
120
|
+
|
|
121
|
+
See [LINGUIST.md](LINGUIST.md) for technical details and contribution status.
|
|
122
|
+
|
|
123
|
+
## Usage
|
|
124
|
+
|
|
125
|
+
### With Global Installation
|
|
126
|
+
|
|
127
|
+
If you installed Koi globally, use the `koi` command directly:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
koi compile examples/simple.koi
|
|
131
|
+
koi run examples/simple.koi
|
|
132
|
+
koi init my-project
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### With Local Development
|
|
136
|
+
|
|
137
|
+
If working on Koi itself, use `node src/cli/koi.js`:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
node src/cli/koi.js compile examples/simple.koi
|
|
141
|
+
node src/cli/koi.js run examples/simple.koi
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Or use npm scripts:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
npm run compile examples/simple.koi
|
|
148
|
+
npm run run examples/simple.koi
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Debugging
|
|
152
|
+
|
|
153
|
+
To run with Node.js inspector:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm run dev examples/simple.koi
|
|
157
|
+
# or
|
|
158
|
+
node --inspect src/cli/koi.js run examples/simple.koi
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Then open Chrome DevTools at `chrome://inspect`.
|
|
162
|
+
|
|
163
|
+
## Syntax
|
|
164
|
+
|
|
165
|
+
### Define Roles
|
|
166
|
+
|
|
167
|
+
```koi
|
|
168
|
+
role Worker { can execute, can propose }
|
|
169
|
+
role Reviewer { can critique, can approve }
|
|
170
|
+
role Lead { can delegate, can decide }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Define Agents
|
|
174
|
+
|
|
175
|
+
Agents describe their behavior in natural language using **playbooks**:
|
|
176
|
+
|
|
177
|
+
```koi
|
|
178
|
+
Agent Analyzer : Worker {
|
|
179
|
+
uses Skill DataAnalysis
|
|
180
|
+
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
181
|
+
|
|
182
|
+
on analyze(args: Json) {
|
|
183
|
+
playbook """
|
|
184
|
+
Analyze the data: ${args.data}
|
|
185
|
+
|
|
186
|
+
Look for patterns, trends, and anomalies.
|
|
187
|
+
Provide actionable insights.
|
|
188
|
+
|
|
189
|
+
Return JSON: { insights: [...], summary: "...", confidence: 0-1 }
|
|
190
|
+
"""
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**For technical operations** (like fetching data), use procedural code:
|
|
196
|
+
```koi
|
|
197
|
+
Agent DataFetcher : Worker {
|
|
198
|
+
on fetch(args: Json) {
|
|
199
|
+
const response = await fetch(args.url)
|
|
200
|
+
const data = await response.json()
|
|
201
|
+
return { data: data }
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Define Teams
|
|
207
|
+
|
|
208
|
+
```koi
|
|
209
|
+
Team Development {
|
|
210
|
+
analyzer = Analyzer
|
|
211
|
+
calculator = Calculator
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Role-based Routing
|
|
216
|
+
|
|
217
|
+
```koi
|
|
218
|
+
Agent Orchestrator : Lead {
|
|
219
|
+
uses Team Development
|
|
220
|
+
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
221
|
+
|
|
222
|
+
on start(args: Json) {
|
|
223
|
+
playbook """
|
|
224
|
+
Task: ${args.task}
|
|
225
|
+
|
|
226
|
+
Work with the development team to complete this task.
|
|
227
|
+
Coordinate with team members based on their capabilities.
|
|
228
|
+
"""
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Agents automatically route to appropriate team members - no hardcoded names needed!
|
|
234
|
+
|
|
235
|
+
### MCP (Model Context Protocol) Support
|
|
236
|
+
|
|
237
|
+
Reference remote agents and services using MCP addresses:
|
|
238
|
+
|
|
239
|
+
```koi
|
|
240
|
+
Team HybridTeam {
|
|
241
|
+
local = LocalAgent
|
|
242
|
+
remote = mcp://agent.local/processor
|
|
243
|
+
skill = mcp://skills.local/sentiment
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
Agent Orchestrator : Worker {
|
|
247
|
+
uses Team HybridTeam
|
|
248
|
+
|
|
249
|
+
on start(args: Json) {
|
|
250
|
+
// Executes on local or remote agent transparently
|
|
251
|
+
const result =
|
|
252
|
+
await send peers.event("process").role(Worker).any()(args)
|
|
253
|
+
return result
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
See [MCP_GUIDE.md](MCP_GUIDE.md) for complete documentation.
|
|
259
|
+
|
|
260
|
+
### Define Skills
|
|
261
|
+
|
|
262
|
+
```koi
|
|
263
|
+
Skill SentimentAnalysis {
|
|
264
|
+
affordance """
|
|
265
|
+
Analyzes text sentiment and returns positive/neutral/negative.
|
|
266
|
+
"""
|
|
267
|
+
|
|
268
|
+
Agent Analyst : Worker {
|
|
269
|
+
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
270
|
+
|
|
271
|
+
on analyze(args: Json) {
|
|
272
|
+
playbook """
|
|
273
|
+
Text: ${args.text}
|
|
274
|
+
|
|
275
|
+
Analyze the sentiment of this text:
|
|
276
|
+
- Determine overall tone (positive, neutral, negative)
|
|
277
|
+
- Rate emotional intensity (0.0 to 1.0)
|
|
278
|
+
- Identify key emotional indicators
|
|
279
|
+
|
|
280
|
+
Return JSON: {
|
|
281
|
+
"sentiment": "positive|neutral|negative",
|
|
282
|
+
"score": 0.0-1.0,
|
|
283
|
+
"keywords": ["word1", "word2", ...],
|
|
284
|
+
"rationale": "brief explanation"
|
|
285
|
+
}
|
|
286
|
+
"""
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
Team Internal {
|
|
291
|
+
analyst = Analyst
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export async function run(input: any): Promise<any> {
|
|
295
|
+
const result = await send Internal.event("analyze").role(Worker).any()(input)
|
|
296
|
+
return result
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Using Skills in Agents
|
|
302
|
+
|
|
303
|
+
Agents can use skills for technical operations while keeping behavior in natural language:
|
|
304
|
+
|
|
305
|
+
```koi
|
|
306
|
+
import "./skills/email-reader.koi" // Skill for IMAP email operations
|
|
307
|
+
|
|
308
|
+
Agent EmailAssistant : Worker {
|
|
309
|
+
uses Skill EmailReader
|
|
310
|
+
llm default = { provider: "openai", model: "gpt-4o-mini" }
|
|
311
|
+
|
|
312
|
+
on processInbox(args: Json) {
|
|
313
|
+
playbook """
|
|
314
|
+
Lee los últimos mensajes de correo y contesta aquellos que
|
|
315
|
+
vengan de proveedores automáticamente.
|
|
316
|
+
|
|
317
|
+
Para cada email de proveedor:
|
|
318
|
+
- Analiza el contenido y el remitente
|
|
319
|
+
- Genera una respuesta profesional apropiada
|
|
320
|
+
- Marca como procesado
|
|
321
|
+
|
|
322
|
+
Ignora emails personales o de clientes.
|
|
323
|
+
"""
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**Skills** = Technical operations (IMAP, databases, APIs)
|
|
329
|
+
**Playbooks** = Natural language behavior
|
|
330
|
+
|
|
331
|
+
### Execute
|
|
332
|
+
|
|
333
|
+
```koi
|
|
334
|
+
run EmailAssistant.processInbox({ email: "user@company.com", since: "2024-01-01" })
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## Examples
|
|
338
|
+
|
|
339
|
+
### 🆕 Task Chaining (Recommended Start)
|
|
340
|
+
|
|
341
|
+
Shows how outputs automatically chain into inputs between tasks:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
koi run examples/task-chaining-demo.koi
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Example: "Translate to French and count words"
|
|
348
|
+
- Action 1: Translate → `{ translated: "bonjour monde" }`
|
|
349
|
+
- Action 2: Count words on `${previousResult.translated}` → `{ wordCount: 2 }`
|
|
350
|
+
|
|
351
|
+
See [TASK_CHAINING_GUIDE.md](TASK_CHAINING_GUIDE.md) for details.
|
|
352
|
+
|
|
353
|
+
### 🆕 Automatic Routing
|
|
354
|
+
|
|
355
|
+
Shows how ANY agent can automatically decompose and delegate tasks:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
koi run examples/auto-routing-demo.koi
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Key concepts:
|
|
362
|
+
- Regular agents receiving complex tasks
|
|
363
|
+
- Automatic decomposition by LLM
|
|
364
|
+
- Cascading resolution (own handlers → skills → team routing)
|
|
365
|
+
- Intelligent semantic matching via embeddings
|
|
366
|
+
|
|
367
|
+
See [AUTO_ROUTING_GUIDE.md](AUTO_ROUTING_GUIDE.md) for explanation.
|
|
368
|
+
|
|
369
|
+
### Simple
|
|
370
|
+
|
|
371
|
+
Minimal example showing agent communication:
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
koi run examples/simple.koi
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Counter
|
|
378
|
+
|
|
379
|
+
Stateful agent with counter operations:
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
koi run examples/counter.koi
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Calculator
|
|
386
|
+
|
|
387
|
+
Basic calculator with multiple operations:
|
|
388
|
+
|
|
389
|
+
```bash
|
|
390
|
+
koi run examples/calculator.koi
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Pipeline
|
|
394
|
+
|
|
395
|
+
Multi-stage data processing pipeline:
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
koi run examples/pipeline.koi
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Sentiment Analysis
|
|
402
|
+
|
|
403
|
+
Sentiment analysis skill with 2 internal agents:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
koi run examples/sentiment.koi
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### MCP Integration
|
|
410
|
+
|
|
411
|
+
Example showing MCP (Model Context Protocol) address support:
|
|
412
|
+
|
|
413
|
+
```bash
|
|
414
|
+
koi run examples/mcp-example.koi
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### Automatic Planning
|
|
418
|
+
|
|
419
|
+
Demonstrates automatic planning system where agents can decompose complex goals:
|
|
420
|
+
|
|
421
|
+
```bash
|
|
422
|
+
koi run examples/planning-demo.koi
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### Planning with Actions
|
|
426
|
+
|
|
427
|
+
Shows how LLM can plan and generate executable actions:
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
koi run examples/planning-with-actions.koi
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
See [PLANNING_GUIDE.md](PLANNING_GUIDE.md) for detailed planning system documentation.
|
|
434
|
+
|
|
435
|
+
## Source Maps
|
|
436
|
+
|
|
437
|
+
Koi generates source maps automatically. Runtime errors show the location in the original `.koi` source, not the generated JavaScript.
|
|
438
|
+
|
|
439
|
+
## Project Structure
|
|
440
|
+
|
|
441
|
+
```
|
|
442
|
+
.
|
|
443
|
+
├── package.json
|
|
444
|
+
├── README.md
|
|
445
|
+
├── src/
|
|
446
|
+
│ ├── grammar/
|
|
447
|
+
│ │ └── koi.pegjs # PEG grammar
|
|
448
|
+
│ ├── compiler/
|
|
449
|
+
│ │ ├── parser.js # Generated parser (auto)
|
|
450
|
+
│ │ └── transpiler.js # Transpiler to JS + source maps
|
|
451
|
+
│ ├── runtime/
|
|
452
|
+
│ │ ├── agent.js # Agent runtime
|
|
453
|
+
│ │ ├── team.js # Team runtime
|
|
454
|
+
│ │ ├── skill.js # Skill runtime
|
|
455
|
+
│ │ ├── role.js # Role runtime
|
|
456
|
+
│ │ ├── runtime.js # Main runtime
|
|
457
|
+
│ │ └── index.js # Exports
|
|
458
|
+
│ └── cli/
|
|
459
|
+
│ └── koi.js # Main CLI
|
|
460
|
+
└── examples/
|
|
461
|
+
├── simple.koi # Simple example
|
|
462
|
+
├── counter.koi # Counter example
|
|
463
|
+
├── calculator.koi # Calculator example
|
|
464
|
+
├── pipeline.koi # Pipeline example
|
|
465
|
+
└── sentiment.koi # Sentiment analysis
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
## Documentation
|
|
469
|
+
|
|
470
|
+
Comprehensive documentation is available in the [doc/](doc/) directory:
|
|
471
|
+
|
|
472
|
+
- **[Installation Guide](doc/00-installation.md)** - Complete installation instructions, manual setup, and troubleshooting
|
|
473
|
+
- **[Getting Started](doc/00-getting-started.md)** - Your first agent and basic workflow
|
|
474
|
+
- **[Core Concepts](doc/01-core-concepts.md)** - Understanding Roles, Agents, Teams, Skills
|
|
475
|
+
- **[Syntax Basics](doc/02-syntax-basics.md)** - Variables, types, control flow
|
|
476
|
+
- **[Agents Guide](doc/03-agents.md)** - Creating and using agents
|
|
477
|
+
- **[Roles & Teams](doc/04-roles-and-teams.md)** - Multi-agent systems
|
|
478
|
+
- **[Skills](doc/05-skills.md)** - Reusable capabilities
|
|
479
|
+
- **[LLM Integration](doc/06-llm-integration.md)** - Using real LLMs with playbooks
|
|
480
|
+
- **[Automatic Routing](doc/07-routing.md)** - Intelligent agent selection
|
|
481
|
+
- **[Task Chaining](doc/08-task-chaining.md)** - Output-to-input chaining
|
|
482
|
+
- **[Planning System](doc/09-planning.md)** - Automatic task decomposition
|
|
483
|
+
- **[MCP Protocol](doc/10-mcp-integration.md)** - Remote agents and services
|
|
484
|
+
- **[TypeScript Imports](doc/11-typescript-imports.md)** - Using npm packages
|
|
485
|
+
- **[Testing](doc/12-testing.md)** - Unit testing with Jest
|
|
486
|
+
- **[Caching](doc/13-caching.md)** - Persistent LLM response caching
|
|
487
|
+
- **[Examples](doc/14-examples.md)** - Complete working examples
|
|
488
|
+
- **[Advanced Topics](doc/15-advanced.md)** - Debugging, performance, production
|
|
489
|
+
- **[Registry](doc/16-registry.md)** - Shared data store for agent coordination
|
|
490
|
+
|
|
491
|
+
## Roadmap
|
|
492
|
+
|
|
493
|
+
- [X] MCP (Model Context Protocol) addresses support
|
|
494
|
+
- [X] Real LLM integration with OpenAI/Anthropic
|
|
495
|
+
- [X] **Full MCP protocol implementation** (WebSocket/HTTP2)
|
|
496
|
+
- [X] Real protocol support (WebSocket & HTTP/2)
|
|
497
|
+
- [X] Authentication and authorization
|
|
498
|
+
- [X] Server discovery
|
|
499
|
+
- [X] Connection pooling and load balancing
|
|
500
|
+
- [X] Retry logic and failover
|
|
501
|
+
- [X] Streaming responses
|
|
502
|
+
- [X] MCP tools integration
|
|
503
|
+
- [X] Automatic planning system for agents
|
|
504
|
+
- [X] LLM-based goal decomposition
|
|
505
|
+
- [X] Sequential step execution
|
|
506
|
+
- [X] Automatic re-planning on failure
|
|
507
|
+
- [X] Context passing between steps
|
|
508
|
+
- [X] Execution tracking and summaries
|
|
509
|
+
- [X] TypeScript/JavaScript import support
|
|
510
|
+
- [X] Unit testing with Jest
|
|
511
|
+
- [X] VSCode/Cursor extension with syntax highlighting
|
|
512
|
+
- [X] GitHub syntax highlighting support
|
|
513
|
+
- [ ] Skills registry and marketplace
|
|
514
|
+
- [ ] Visual debugging
|
|
515
|
+
- [ ] Hot reload in development
|
|
516
|
+
|
|
517
|
+
## Contributing
|
|
518
|
+
|
|
519
|
+
Contributions are welcome! Here are some ways you can help:
|
|
520
|
+
|
|
521
|
+
- 🐛 Report bugs and issues
|
|
522
|
+
- 💡 Suggest new features or improvements
|
|
523
|
+
- 📝 Improve documentation
|
|
524
|
+
- 🎨 Help with GitHub Linguist PR (see [LINGUIST.md](LINGUIST.md))
|
|
525
|
+
- 🔧 Submit pull requests
|
|
526
|
+
|
|
527
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
528
|
+
|
|
529
|
+
## Resources
|
|
530
|
+
|
|
531
|
+
- **Documentation**: [doc/](doc/) - Comprehensive guides
|
|
532
|
+
- **Quick Start**: [QUICKSTART.md](QUICKSTART.md) - 2-minute setup
|
|
533
|
+
- **Examples**: [examples/](examples/) - Working code samples
|
|
534
|
+
- **VSCode Extension**: [vscode-koi-extension/](vscode-koi-extension/)
|
|
535
|
+
- **AI Assistant Guide**: [CLAUDE.md](CLAUDE.md) - Architecture and patterns
|
|
536
|
+
- **Syntax Highlighting**: [LINGUIST.md](LINGUIST.md) - GitHub support status
|
|
537
|
+
|
|
538
|
+
## Community
|
|
539
|
+
|
|
540
|
+
- **Issues**: [github.com/koi-language/Koi/issues](https://github.com/koi-language/Koi/issues)
|
|
541
|
+
- **Discussions**: [github.com/koi-language/Koi/discussions](https://github.com/koi-language/Koi/discussions)
|
|
542
|
+
|
|
543
|
+
## License
|
|
544
|
+
|
|
545
|
+
MIT
|