@migor/agentia 0.10.3 → 0.10.4
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 +419 -30
- package/LICENSE +1 -1
- package/README.en.md +93 -38
- package/README.md +105 -218
- package/dist/AGENTS.md +143 -20
- package/dist/core/trace-sink.d.ts +8 -0
- package/dist/core/trace-sink.js +24 -0
- package/dist/core/trace-sink.js.map +1 -0
- package/dist/core/trace.d.ts +2 -1
- package/dist/core/trace.js.map +1 -1
- package/dist/engine/loop-result.d.ts +1 -1
- package/dist/engine/loop.js +8 -0
- package/dist/engine/loop.js.map +1 -1
- package/dist/engine/mcp-server.d.ts +2 -2
- package/dist/engine/mcp-server.js +3 -9
- package/dist/engine/mcp-server.js.map +1 -1
- package/dist/engine/types.d.ts +5 -2
- package/dist/engine/types.js +1 -0
- package/dist/engine/types.js.map +1 -1
- package/dist/eval/harvest.d.ts +4 -1
- package/dist/eval/harvest.js +32 -6
- package/dist/eval/harvest.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/file-sink.d.ts +0 -16
- package/dist/integrations/file-sink.js +22 -4
- package/dist/integrations/file-sink.js.map +1 -1
- package/dist/integrations/mcp-stdio.js +63 -42
- package/dist/integrations/mcp-stdio.js.map +1 -1
- package/dist/integrations/metrics-render.js +16 -5
- package/dist/integrations/metrics-render.js.map +1 -1
- package/dist/runtime/run.d.ts +1 -1
- package/dist/runtime/run.js +19 -17
- package/dist/runtime/run.js.map +1 -1
- package/dist/store/store.js +9 -2
- package/dist/store/store.js.map +1 -1
- package/dist/toolkit/discover.js +27 -1
- package/dist/toolkit/discover.js.map +1 -1
- package/dist/toolkit/module.js +105 -49
- package/dist/toolkit/module.js.map +1 -1
- package/dist/toolkit/subagent.d.ts +1 -1
- package/dist/transport/serve.d.ts +92 -0
- package/dist/transport/serve.js +155 -0
- package/dist/transport/serve.js.map +1 -0
- package/package.json +23 -10
package/README.en.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Agentia
|
|
2
2
|
|
|
3
|
-
[](https://github.com/migoric/agentia/actions/workflows/ci.yml) [](https://www.npmjs.com/package/@migor/agentia) [](LICENSE)
|
|
4
4
|
|
|
5
5
|
[中文 README](./README.md) · **English**
|
|
6
6
|
|
|
@@ -8,25 +8,23 @@
|
|
|
8
8
|
with decorators + DI and a main agent orchestrates them; every run yields structured output and an
|
|
9
9
|
observable call tree (trace, cost, metrics).
|
|
10
10
|
|
|
11
|
-
**1 package · ≈2 MB · 0 runtime dependencies · 90+ guards** —
|
|
12
|
-
|
|
13
|
-
`node_modules` and pulls in no vendor SDK. These numbers are recomputed by
|
|
14
|
-
`tests/docs/scoreboard.test.ts` on every run; hand-written figures rot.
|
|
11
|
+
**1 package · ≈2 MB · 0 runtime dependencies · 90+ guards** — recomputed by
|
|
12
|
+
`tests/docs/scoreboard.test.ts` on every run.
|
|
15
13
|
|
|
16
|
-
> This is a **summary
|
|
17
|
-
> pages
|
|
18
|
-
>
|
|
19
|
-
>
|
|
20
|
-
> text is served verbatim at `/llms-full.txt`). We keep this file short on purpose — a hand-maintained
|
|
21
|
-
> full translation drifts.
|
|
14
|
+
> This is a **summary**, kept short on purpose (a hand-maintained full translation drifts). The
|
|
15
|
+
> [website](https://agentia-web.pages.dev/en) is bilingual, but the authoritative long-form
|
|
16
|
+
> documentation is Chinese: [`docs/usage-guide.md`](./docs/usage-guide.md) (also served verbatim at
|
|
17
|
+
> `/llms-full.txt`).
|
|
22
18
|
|
|
23
19
|
## Requirements
|
|
24
20
|
|
|
25
|
-
Node.js **≥ 18** (the only `engines` requirement)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
Node.js **≥ 18** (the only `engines` requirement); CI covers **18 / 20 / 24**. Designed and tested on
|
|
22
|
+
Node; **Bun and Deno are verified runnable** (four-step check — import → assemble → HTTP → side
|
|
23
|
+
effects — plus minimal mounting code per host and the measured versions, in
|
|
24
|
+
[`docs/frameworks.md`](./docs/frameworks.md); the front page deliberately carries no version numbers —
|
|
25
|
+
they rot); **edge runtimes remain unverified**.
|
|
26
|
+
`SqliteTaskStore` needs Node ≥ 22.5 (`node:sqlite`) and fails with a
|
|
27
|
+
readable error at construction — importing the package still works.
|
|
30
28
|
|
|
31
29
|
## Install
|
|
32
30
|
|
|
@@ -34,26 +32,34 @@ importing the package.
|
|
|
34
32
|
npm i @migor/agentia # the framework
|
|
35
33
|
npm i -g @migor/cli # CLI: scaffold / generate / dev inspector
|
|
36
34
|
|
|
37
|
-
agentia create my-app
|
|
38
|
-
|
|
35
|
+
agentia create my-app --minimal # single entry file + a bare tool; ships .env / .env.example
|
|
36
|
+
cd my-app && npm install
|
|
37
|
+
$EDITOR .env # put ANTHROPIC_API_KEY here (export works too — real env wins)
|
|
38
|
+
npm run dev -- "your question" # tsx src/main.ts: one run, then exit
|
|
39
39
|
# optional: ANTHROPIC_BASE_URL (compatible gateways), AGENTIA_MODEL (default claude-opus-5)
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
> The framework does **not** read `.env` on its own: the
|
|
43
|
-
>
|
|
44
|
-
> (CI / docker / command line), unless you pass `loadEnvFile({ override: true })`.
|
|
42
|
+
> The framework does **not** read `.env` on its own: the template entry calls `loadEnvFile()`.
|
|
43
|
+
> Real environment variables win over the file unless you pass `{ override: true }`.
|
|
45
44
|
|
|
46
45
|
## Quick start
|
|
47
46
|
|
|
48
47
|
### A. CLI
|
|
49
48
|
|
|
49
|
+
Start with `--minimal` to exercise the model and a bare tool without learning decorators, DI or the HTTP
|
|
50
|
+
host first. For the inspector, four capability directories and a production service, use the **default
|
|
51
|
+
full template without `--minimal`** (unchanged):
|
|
52
|
+
|
|
50
53
|
```bash
|
|
51
|
-
agentia create my-
|
|
52
|
-
cd my-
|
|
54
|
+
agentia create my-service
|
|
55
|
+
cd my-service && npm install
|
|
53
56
|
agentia g tool weather # create src/tools/weather/index.ts and register it
|
|
54
57
|
agentia dev # local inspector panel (drive a run, pick capabilities/workdir)
|
|
55
58
|
```
|
|
56
59
|
|
|
60
|
+
In the full template, `src/main.ts` starts the HTTP service and `src/batch.ts` is the one-shot
|
|
61
|
+
`npm run start:batch` entry.
|
|
62
|
+
|
|
57
63
|
Four self-describing directories hold capabilities — the directory name **is** the kind:
|
|
58
64
|
`src/tools/` · `src/skills/` · `src/prompts/` · `src/subagents/`; the registry is `src/registry.ts`.
|
|
59
65
|
|
|
@@ -91,6 +97,21 @@ console.log(result.trace); // call tree + per-step tokens/cost (traceId ===
|
|
|
91
97
|
Or point `createApp` at the directories instead of passing providers:
|
|
92
98
|
`createApp({ discover: ['src/tools', 'src/skills', 'src/prompts', 'src/subagents'], system })`.
|
|
93
99
|
|
|
100
|
+
### C. Existing service? Add one endpoint
|
|
101
|
+
|
|
102
|
+
Don't scaffold a new project, and don't rewrite the one you have. Wrap an existing function as a
|
|
103
|
+
`@Tool`, then add **one branch** in your existing `createServer`: business routes first (your code
|
|
104
|
+
stays untouched), everything else goes to `createHttpHandler` (`/run`, `/tasks`, `/healthz`).
|
|
105
|
+
Auth is **the same function** for both, and `drain()` hooks into the SIGTERM flow you already have.
|
|
106
|
+
|
|
107
|
+
Six steps, roughly 30 lines of glue. Runnable example:
|
|
108
|
+
[`examples/agent-endpoint/`](./examples/agent-endpoint/) — an order service that already ships
|
|
109
|
+
`GET /api/orders/:id`, with the agent endpoint added alongside; `src/orders.ts` is unchanged.
|
|
110
|
+
|
|
111
|
+
> Three deliberate calls: **one auth path** (the framework gives you the seam, not the policy);
|
|
112
|
+
> **RAG is your tool** (wrap your own `pg.query` / vector client in a `@Tool` — the framework won't
|
|
113
|
+
> ship one); **no budget knobs = no fuse** (the example sets all three).
|
|
114
|
+
|
|
94
115
|
## The four capability kinds
|
|
95
116
|
|
|
96
117
|
The model picks from one shared "menu" by `description`; the decorator decides **who controls the flow**:
|
|
@@ -133,6 +154,19 @@ One run == one trace (`traceId === runId`), **built in from turn 0** — not a b
|
|
|
133
154
|
- **Models** — `createAnthropicClient()` (default) and `createOpenAIClient()` for any OpenAI-compatible
|
|
134
155
|
endpoint (DeepSeek, **Ollama**, gateways). You never need to touch a vendor SDK: pass
|
|
135
156
|
`createAnthropicClient({ baseURL })` / `createOpenAIClient({ baseURL })`.
|
|
157
|
+
- **Web framework hosts** — `createHttpHandler` returns a plain `(req, res) => void`, so anything that
|
|
158
|
+
can mount a raw node handler can mount it, with no adapter layer:
|
|
159
|
+
|
|
160
|
+
| Host | Minimal mounting | Required config |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| `node:http` | `createServer(createHttpHandler(app, { runner }))` | none |
|
|
163
|
+
| NestJS 12 (CJS / ESM) | `nestApp.use('/agent', handler)` — 3 lines | CJS mode needs Node ≥ 22.12 (or `await import()`) |
|
|
164
|
+
| Egg 4 | middleware + `ctx.respond = false` | two `ignore` entries (CSRF / bodyParser) — the string form crashes the worker at startup |
|
|
165
|
+
| Bun / Deno | identical to `node:http`, zero changes | Deno's `--allow-net/read/write/run` |
|
|
166
|
+
|
|
167
|
+
Under cluster / multi-instance the task store **must** be shared — one in-memory store per worker
|
|
168
|
+
makes polling the same taskId alternate `404 200`. Conclusion table, minimal code and Egg's three
|
|
169
|
+
pitfalls: [`docs/frameworks.md`](./docs/frameworks.md).
|
|
136
170
|
- **MCP** — `createStdioMcpConnector()` / `createStreamableHttpMcpConnector()` ship with the framework
|
|
137
171
|
(stdlib only: `node:child_process` + global `fetch`); `mcpTools()` bridges the server's tools into the
|
|
138
172
|
menu. The framework never imports the MCP SDK, and the `McpClientLike` seam stays open
|
|
@@ -142,12 +176,36 @@ One run == one trace (`traceId === runId`), **built in from turn 0** — not a b
|
|
|
142
176
|
- **Platforms** — send traces to Langfuse / Phoenix / etc. via OTLP or a tiny custom `TraceSink`
|
|
143
177
|
(see [`docs/observability.md`](./docs/observability.md) §2.6)
|
|
144
178
|
|
|
179
|
+
## API at a glance
|
|
180
|
+
|
|
181
|
+
| Export | Purpose |
|
|
182
|
+
|---|---|
|
|
183
|
+
| `createApp` / `discoverProviders` | assemble an app / scan capability directories |
|
|
184
|
+
| `defineModule` | capability package (providers + middleware, distributable) |
|
|
185
|
+
| `Tool` / `Skill` / `SubAgent` / `Prompt` | the four capability decorators |
|
|
186
|
+
| `CapabilityMiddleware` (the `middleware` option) | interceptor chain around capability calls |
|
|
187
|
+
| `asset` | read a text asset inside a capability folder |
|
|
188
|
+
| `SystemPrompt` | compose the system prompt (adds the cache breakpoint) |
|
|
189
|
+
| `RunContext.current()` | blackboard / runId for the current run |
|
|
190
|
+
| `AsyncRunner` / `Scheduler` / `runSync` / `createHttpHandler` | async / scheduled / sync / HTTP triggering |
|
|
191
|
+
| `FileTaskStore` / `SqliteTaskStore` / `RedisTaskStore` / `InMemoryTaskStore` | task record stores |
|
|
192
|
+
| `createBudgetPolicy` | long-context budget guard |
|
|
193
|
+
| `createAnthropicClient` | default ModelClient (Anthropic) |
|
|
194
|
+
| `createOpenAIClient` | any OpenAI-compatible endpoint |
|
|
195
|
+
| `InMemoryMemoryStore` (the `memory` option) | cross-run memory hydration / write-back |
|
|
196
|
+
| `createOtlpExporter` | export traces over OTLP |
|
|
197
|
+
| `traceToMessages` | replay a finished trace as model messages |
|
|
198
|
+
| `fromZod` | zod schema adapter (optional peer) |
|
|
199
|
+
| `runAgent` / `executeRun` | bare engine entry (no assembly) |
|
|
200
|
+
|
|
145
201
|
## Documentation
|
|
146
202
|
|
|
147
203
|
| | |
|
|
148
204
|
|---|---|
|
|
149
205
|
| Usage guide (authoritative, zh) | [`docs/usage-guide.md`](./docs/usage-guide.md) |
|
|
150
206
|
| Production observability recipes | [`docs/observability.md`](./docs/observability.md) |
|
|
207
|
+
| Database integration (inject your pool / implement `TaskStore` for MySQL) | [`docs/database.md`](./docs/database.md) |
|
|
208
|
+
| Framework compatibility (measured: NestJS / Egg / Bun / Deno) | [`docs/frameworks.md`](./docs/frameworks.md) |
|
|
151
209
|
| Examples (complete app / minimal deploy / observability) | [`examples/`](./examples/) |
|
|
152
210
|
| Design spec & roadmap | [`docs/spec.md`](./docs/spec.md) · [`docs/roadmap.md`](./docs/roadmap.md) |
|
|
153
211
|
| Website · Playground | [agentia-web.pages.dev/en](https://agentia-web.pages.dev/en) · [playground](https://agentia-web.pages.dev/en/playground) |
|
|
@@ -163,19 +221,17 @@ stating what **you** have to change.
|
|
|
163
221
|
grep -nE '^#{3,4} .*(迁移|破坏性)' CHANGELOG.md # every "you must act" section
|
|
164
222
|
```
|
|
165
223
|
|
|
166
|
-
>
|
|
167
|
-
>
|
|
168
|
-
> above is a **lower bound**, not the whole set. And this README deliberately prints **no**
|
|
169
|
-
> "N releases / M migrations" count: hand-written counts rot, so we ship the command instead.
|
|
224
|
+
> The command above is a **lower bound**, not the whole set — early versions didn't follow this format.
|
|
225
|
+
> Counts ("N releases / M migrations") are deliberately not printed: they rot.
|
|
170
226
|
|
|
171
|
-
**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
`
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
227
|
+
**Covered by the compatibility promise:** the **named exports** of `@migor/agentia` (`src/index.ts` is
|
|
228
|
+
the source of truth) and the `@migor/cli` command surface, plus the Node range in `engines.node` (CI
|
|
229
|
+
runs the full chain on every version in it). **Not covered:** deep imports (`dist/**`) — sealed by the
|
|
230
|
+
`exports` field in `package.json`, guarded by `package-exports.test.ts` — internal module paths,
|
|
231
|
+
`packages/*`, `examples/*`, edge runtimes, and anything a release doesn't spell out in its
|
|
232
|
+
migration note. Bun / Deno are **verified runnable but outside the `engines` promise**
|
|
233
|
+
([`docs/frameworks.md`](./docs/frameworks.md)). Runtime third-party dependencies are **zero**, enforced by
|
|
234
|
+
`no-runtime-deps.test.ts`, not by promise.
|
|
179
235
|
|
|
180
236
|
**What 1.0 waits for** (all three are checkable): every open item in `docs/spec.md` §11 is either
|
|
181
237
|
shipped or explicitly struck out; `docs/guards.md` §2 ("awaiting a guard") is empty; and the public
|
|
@@ -199,9 +255,8 @@ cost you pay under which condition, and what a different implementation could re
|
|
|
199
255
|
> load; copying them as an SLA will be wrong. What is actually constant is the **shape** (how many
|
|
200
256
|
> times larger, how many round trips, what scales with what).
|
|
201
257
|
>
|
|
202
|
-
> The five benchmarks are **deliberately not in CI** (timing benchmarks only add noise
|
|
203
|
-
>
|
|
204
|
-
> guards the numbers below — re-run the command in the last column.
|
|
258
|
+
> The five benchmarks are **deliberately not in CI** (timing benchmarks only add noise) ⇒ nothing
|
|
259
|
+
> guards these numbers; re-run the command in the last column.
|
|
205
260
|
|
|
206
261
|
## Contributing
|
|
207
262
|
|