tinyagents 2.1.0

A recursive language-model (RLM) harness for Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# Expressive Language: Node Kinds, Binding, State, Routes, Examples

Continues from [`README.md`](README.md): node kinds, binding to Rust,
the state model, routes, policies, comments/strings, safety, examples,
formatting, testkit, and implementation milestones.

## Node Kinds

Initial built-in node kinds:

### `agent`

Uses the harness agent loop or one model call depending on config.

Supported fields:

- `model`
- `system`
- `prompt`
- `tools`
- `routes`
- `retry`
- `timeout`

### `model`

Single model invocation. Does not automatically execute tools.

Supported fields:

- `model`
- `system`
- `prompt`
- `routes`
- `retry`
- `timeout`

### `tool_executor`

Executes tool calls already present in state.

Supported fields:

- `tools`
- `next`
- `retry`
- `timeout`

### `router`

Routes based on a named route function provided from Rust.

Supported fields:

- `routes`
- `metadata`

### `subgraph`

Calls another compiled graph.

Supported fields:

- `graph`
- `next`
- `routes`

### `subagent`

Calls a registered harness agent as a graph node.

Supported fields:

- `agent`
- `input`
- `next`
- `routes`
- `retry`
- `timeout`
- `steering`

Example:

```tinyagents
node research {
  kind subagent
  agent "researcher"
  steering {
    parent allow ["add_instruction", "request_status", "cancel"]
    human allow ["add_instruction", "pause", "resume", "cancel"]
    delivery "safe_boundary"
  }
  next synthesize
}
```

Steering policies lower into harness steering policy and graph task policy. They
can narrow a child agent's model/tool/runtime limits but cannot grant
capabilities absent from the registry or parent run policy.

### `repl_agent`

Runs a registered REPL script or model-driven CodeAct loop through the harness
REPL runtime.

Supported fields:

- `model`
- `script`
- `tools`
- `routes`
- `retry`
- `timeout`

### `interrupt`

Emits a resumable human-in-the-loop interrupt.

Supported fields:

- `prompt`
- `options`
- `routes`
- `metadata`

### `join`

Waits for named upstream nodes or barrier channels before continuing.

Supported fields:

- `sources`
- `next`
- `timeout`

## Binding To Rust

The language should not define arbitrary Rust closures. Instead, it should bind
to Rust-provided registries:

```rust
let workflow = LanguageCompiler::new()
    .with_models(models)
    .with_tools(tools)
    .with_node_templates(templates)
    .compile_source("support.rag", source)?;
```

Registries:

- model registry
- tool registry
- agent registry
- node template registry
- route function registry
- reducer registry
- graph registry for subgraphs
- store registry
- middleware registry
- REPL script registry

When a graph is generated by a REPL session, the session may call the compiler
with source text or an AST, but the compiler must use the same registries and
policy checks. Generated source can request capabilities only from the allowed
set attached to the parent run or registry namespace.

This keeps source files declarative and prevents unsafe dynamic execution.

## State Model

Version 1 should keep state Rust-owned. The language can refer to standard
channels by convention and bind them to registered reducers:

- `messages`
- `tool_calls`
- `structured_response`
- `metadata`
- `artifacts`
- `candidates`
- `usage`
- `interrupts`

Example:

```tinyagents
channel messages messages
channel candidates append
channel usage aggregate "usage_delta"
channel review overwrite
```

Future versions may add state schema declarations:

```tinyagents
state SupportState {
  messages: messages append
  customer_id: string overwrite
  ticket_id: string? overwrite
}
```

State schemas should be delayed until reducer-based graph execution exists.

## Routes

Routes are named outcomes.

```tinyagents
routes {
  tool_call -> tools
  final -> END
  escalate -> human_review
}
```

Rules:

- route names are unique per node
- route targets must exist or be `END`
- route names are ASCII identifiers
- a node may use `routes` or `next`, not both
- `END` is reserved

Future typed route support can generate Rust enums from route declarations.

## Policies

Node-level policies:

```tinyagents
node agent {
  timeout 30s
  retry {
    max_attempts: 3
    backoff: "exponential"
  }
}
```

Graph-level defaults:

```tinyagents
graph support_agent {
  defaults {
    timeout 60s
    recursion_limit 50
  }
}
```

Policies lower into graph node policies and harness request policies.

## Comments And Strings

Comments:

```tinyagents
// line comment
```

Strings:

```tinyagents
system "single line"

prompt """
multi-line prompt
"""
```

Multi-line strings should preserve content exactly except for one predictable
dedent rule.

## Safety

The language must be safe to parse and validate from untrusted text.

Safety rules:

- no arbitrary code execution
- no filesystem access from language source
- no network access from language source
- no dynamic provider lookup without registry binding
- no environment variable interpolation in v1
- bounded parser recursion
- bounded source size

## Examples

### Minimal Model Graph

```tinyagents
graph summarize {
  start model

  node model {
    kind model
    model "default"
    system "Summarize the user request."
    next END
  }
}
```

### Agent With Tools

```tinyagents
graph support_agent {
  start agent

  node agent {
    kind agent
    model "default"
    system "Resolve support requests using tools when useful."
    tools ["lookup_user", "create_ticket"]
    routes {
      tool_call -> tools
      final -> END
    }
  }

  node tools {
    kind tool_executor
    next agent
  }
}
```

### Human Review

```tinyagents
graph approval_flow {
  start draft

  node draft {
    kind model
    model "default"
    system "Draft a response."
    next review
  }

  node review {
    kind interrupt
    prompt "Approve this response?"
    routes {
      approved -> send
      rejected -> draft
    }
  }

  node send {
    kind tool_executor
    tools ["send_email"]
    next END
  }
}
```

## Formatting

Formatter goals:

- stable ordering within declarations
- preserve comments
- normalize indentation to two spaces
- one item per line for lists longer than one entry
- avoid rewriting prompt body content

The formatter can come after parser and diagnostics.

## Testkit

`language::testkit` should include:

- parse snapshot helper
- diagnostic snapshot helper
- compile helper with fake registries
- golden source fixtures
- round-trip formatter tests once formatter exists

## Implementation Milestones

### L1: Parser Skeleton

- token model
- spans
- lexer
- parser for graph, start, node, next, routes

### L2: Diagnostics

- structured diagnostics
- duplicate node validation
- unknown route target validation

### L3: Compiler Preview

- compile topology into `GraphBuilder`
- support `kind model`
- support `kind agent`
- bind model names

### L4: Tool Binding

- validate tool names
- compile `tool_executor`
- add agent/tool graph example

### L5: Policies And Subgraphs

- parse timeout and retry
- bind subgraphs
- compile node policies

### L6: Channels, Commands, And Fanout

- parse channel declarations
- bind reducer registry entries
- lower `command` and `sends`
- compile join/barrier nodes

### L7: Agent-Authored Graphs

- compile generated source under parent run policy
- require review gates when policy marks generated graphs as untrusted
- store generated blueprint provenance
- expose graph diff and preview diagnostics

### L8: Formatter

- stable formatting
- golden tests