@aigne/agent-runtime 1.12.0-beta.5
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/LICENSE.md +26 -0
- package/README.md +79 -0
- package/dist/agent-runners/ai-runner.cjs +133 -0
- package/dist/agent-runners/ai-runner.d.cts +33 -0
- package/dist/agent-runners/ai-runner.d.cts.map +1 -0
- package/dist/agent-runners/ai-runner.d.mts +33 -0
- package/dist/agent-runners/ai-runner.d.mts.map +1 -0
- package/dist/agent-runners/ai-runner.mjs +134 -0
- package/dist/agent-runners/ai-runner.mjs.map +1 -0
- package/dist/agent-runners/ash-runner.cjs +272 -0
- package/dist/agent-runners/ash-runner.d.cts +30 -0
- package/dist/agent-runners/ash-runner.d.cts.map +1 -0
- package/dist/agent-runners/ash-runner.d.mts +30 -0
- package/dist/agent-runners/ash-runner.d.mts.map +1 -0
- package/dist/agent-runners/ash-runner.mjs +273 -0
- package/dist/agent-runners/ash-runner.mjs.map +1 -0
- package/dist/agent-runners/budget.cjs +71 -0
- package/dist/agent-runners/budget.d.cts +40 -0
- package/dist/agent-runners/budget.d.cts.map +1 -0
- package/dist/agent-runners/budget.d.mts +40 -0
- package/dist/agent-runners/budget.d.mts.map +1 -0
- package/dist/agent-runners/budget.mjs +67 -0
- package/dist/agent-runners/budget.mjs.map +1 -0
- package/dist/agent-runners/code-runner.cjs +61 -0
- package/dist/agent-runners/code-runner.mjs +61 -0
- package/dist/agent-runners/code-runner.mjs.map +1 -0
- package/dist/agent-runners/env-whitelist.cjs +36 -0
- package/dist/agent-runners/env-whitelist.d.cts +5 -0
- package/dist/agent-runners/env-whitelist.d.cts.map +1 -0
- package/dist/agent-runners/env-whitelist.d.mts +5 -0
- package/dist/agent-runners/env-whitelist.d.mts.map +1 -0
- package/dist/agent-runners/env-whitelist.mjs +36 -0
- package/dist/agent-runners/env-whitelist.mjs.map +1 -0
- package/dist/agent-runners/guide-rails.cjs +47 -0
- package/dist/agent-runners/guide-rails.d.cts +16 -0
- package/dist/agent-runners/guide-rails.d.cts.map +1 -0
- package/dist/agent-runners/guide-rails.d.mts +16 -0
- package/dist/agent-runners/guide-rails.d.mts.map +1 -0
- package/dist/agent-runners/guide-rails.mjs +48 -0
- package/dist/agent-runners/guide-rails.mjs.map +1 -0
- package/dist/agent-runners/hook-channel.cjs +55 -0
- package/dist/agent-runners/hook-channel.d.cts +38 -0
- package/dist/agent-runners/hook-channel.d.cts.map +1 -0
- package/dist/agent-runners/hook-channel.d.mts +38 -0
- package/dist/agent-runners/hook-channel.d.mts.map +1 -0
- package/dist/agent-runners/hook-channel.mjs +55 -0
- package/dist/agent-runners/hook-channel.mjs.map +1 -0
- package/dist/agent-runners/hooks.cjs +107 -0
- package/dist/agent-runners/hooks.d.cts +41 -0
- package/dist/agent-runners/hooks.d.cts.map +1 -0
- package/dist/agent-runners/hooks.d.mts +41 -0
- package/dist/agent-runners/hooks.d.mts.map +1 -0
- package/dist/agent-runners/hooks.mjs +107 -0
- package/dist/agent-runners/hooks.mjs.map +1 -0
- package/dist/agent-runners/memory-afs.cjs +342 -0
- package/dist/agent-runners/memory-afs.d.cts +221 -0
- package/dist/agent-runners/memory-afs.d.cts.map +1 -0
- package/dist/agent-runners/memory-afs.d.mts +221 -0
- package/dist/agent-runners/memory-afs.d.mts.map +1 -0
- package/dist/agent-runners/memory-afs.mjs +326 -0
- package/dist/agent-runners/memory-afs.mjs.map +1 -0
- package/dist/agent-runners/memory-archive.cjs +263 -0
- package/dist/agent-runners/memory-archive.d.cts +47 -0
- package/dist/agent-runners/memory-archive.d.cts.map +1 -0
- package/dist/agent-runners/memory-archive.d.mts +47 -0
- package/dist/agent-runners/memory-archive.d.mts.map +1 -0
- package/dist/agent-runners/memory-archive.mjs +257 -0
- package/dist/agent-runners/memory-archive.mjs.map +1 -0
- package/dist/agent-runners/orchestrator-runner.cjs +302 -0
- package/dist/agent-runners/orchestrator-runner.d.cts +23 -0
- package/dist/agent-runners/orchestrator-runner.d.cts.map +1 -0
- package/dist/agent-runners/orchestrator-runner.d.mts +23 -0
- package/dist/agent-runners/orchestrator-runner.d.mts.map +1 -0
- package/dist/agent-runners/orchestrator-runner.mjs +303 -0
- package/dist/agent-runners/orchestrator-runner.mjs.map +1 -0
- package/dist/agent-runners/orchestrator-state.cjs +68 -0
- package/dist/agent-runners/orchestrator-state.d.cts +23 -0
- package/dist/agent-runners/orchestrator-state.d.cts.map +1 -0
- package/dist/agent-runners/orchestrator-state.d.mts +23 -0
- package/dist/agent-runners/orchestrator-state.d.mts.map +1 -0
- package/dist/agent-runners/orchestrator-state.mjs +65 -0
- package/dist/agent-runners/orchestrator-state.mjs.map +1 -0
- package/dist/agent-runners/retry.cjs +30 -0
- package/dist/agent-runners/retry.d.cts +13 -0
- package/dist/agent-runners/retry.d.cts.map +1 -0
- package/dist/agent-runners/retry.d.mts +13 -0
- package/dist/agent-runners/retry.d.mts.map +1 -0
- package/dist/agent-runners/retry.mjs +30 -0
- package/dist/agent-runners/retry.mjs.map +1 -0
- package/dist/agent-runners/scratchpad-afs.cjs +276 -0
- package/dist/agent-runners/scratchpad-afs.d.cts +103 -0
- package/dist/agent-runners/scratchpad-afs.d.cts.map +1 -0
- package/dist/agent-runners/scratchpad-afs.d.mts +103 -0
- package/dist/agent-runners/scratchpad-afs.d.mts.map +1 -0
- package/dist/agent-runners/scratchpad-afs.mjs +271 -0
- package/dist/agent-runners/scratchpad-afs.mjs.map +1 -0
- package/dist/agent-runners/stream-router.cjs +72 -0
- package/dist/agent-runners/stream-router.d.cts +22 -0
- package/dist/agent-runners/stream-router.d.cts.map +1 -0
- package/dist/agent-runners/stream-router.d.mts +22 -0
- package/dist/agent-runners/stream-router.d.mts.map +1 -0
- package/dist/agent-runners/stream-router.mjs +72 -0
- package/dist/agent-runners/stream-router.mjs.map +1 -0
- package/dist/agent-runners/system-prompt.cjs +35 -0
- package/dist/agent-runners/system-prompt.d.cts +17 -0
- package/dist/agent-runners/system-prompt.d.cts.map +1 -0
- package/dist/agent-runners/system-prompt.d.mts +17 -0
- package/dist/agent-runners/system-prompt.d.mts.map +1 -0
- package/dist/agent-runners/system-prompt.mjs +34 -0
- package/dist/agent-runners/system-prompt.mjs.map +1 -0
- package/dist/agent-runners/team-modes/aggregates.cjs +36 -0
- package/dist/agent-runners/team-modes/aggregates.mjs +35 -0
- package/dist/agent-runners/team-modes/aggregates.mjs.map +1 -0
- package/dist/agent-runners/team-modes/iterate.cjs +46 -0
- package/dist/agent-runners/team-modes/iterate.mjs +47 -0
- package/dist/agent-runners/team-modes/iterate.mjs.map +1 -0
- package/dist/agent-runners/team-modes/parallel.cjs +59 -0
- package/dist/agent-runners/team-modes/parallel.mjs +60 -0
- package/dist/agent-runners/team-modes/parallel.mjs.map +1 -0
- package/dist/agent-runners/team-modes/reflection.cjs +155 -0
- package/dist/agent-runners/team-modes/reflection.mjs +156 -0
- package/dist/agent-runners/team-modes/reflection.mjs.map +1 -0
- package/dist/agent-runners/team-modes/sequential.cjs +63 -0
- package/dist/agent-runners/team-modes/sequential.mjs +64 -0
- package/dist/agent-runners/team-modes/sequential.mjs.map +1 -0
- package/dist/agent-runners/team-modes/utils.cjs +39 -0
- package/dist/agent-runners/team-modes/utils.mjs +36 -0
- package/dist/agent-runners/team-modes/utils.mjs.map +1 -0
- package/dist/agent-runners/team-runner.cjs +277 -0
- package/dist/agent-runners/team-runner.d.cts +34 -0
- package/dist/agent-runners/team-runner.d.cts.map +1 -0
- package/dist/agent-runners/team-runner.d.mts +34 -0
- package/dist/agent-runners/team-runner.d.mts.map +1 -0
- package/dist/agent-runners/team-runner.mjs +278 -0
- package/dist/agent-runners/team-runner.mjs.map +1 -0
- package/dist/agent-runners/template-context.cjs +32 -0
- package/dist/agent-runners/template-context.d.cts +43 -0
- package/dist/agent-runners/template-context.d.cts.map +1 -0
- package/dist/agent-runners/template-context.d.mts +43 -0
- package/dist/agent-runners/template-context.d.mts.map +1 -0
- package/dist/agent-runners/template-context.mjs +33 -0
- package/dist/agent-runners/template-context.mjs.map +1 -0
- package/dist/index.cjs +123 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.mts +29 -0
- package/dist/index.mjs +29 -0
- package/dist/program/agent-action.cjs +496 -0
- package/dist/program/agent-action.d.cts +42 -0
- package/dist/program/agent-action.d.cts.map +1 -0
- package/dist/program/agent-action.d.mts +42 -0
- package/dist/program/agent-action.d.mts.map +1 -0
- package/dist/program/agent-action.mjs +497 -0
- package/dist/program/agent-action.mjs.map +1 -0
- package/dist/program/agent-messages-tools.cjs +137 -0
- package/dist/program/agent-messages-tools.d.cts +59 -0
- package/dist/program/agent-messages-tools.d.cts.map +1 -0
- package/dist/program/agent-messages-tools.d.mts +59 -0
- package/dist/program/agent-messages-tools.d.mts.map +1 -0
- package/dist/program/agent-messages-tools.mjs +130 -0
- package/dist/program/agent-messages-tools.mjs.map +1 -0
- package/dist/program/agent-runner-registry.cjs +314 -0
- package/dist/program/agent-runner-registry.d.cts +52 -0
- package/dist/program/agent-runner-registry.d.cts.map +1 -0
- package/dist/program/agent-runner-registry.d.mts +52 -0
- package/dist/program/agent-runner-registry.d.mts.map +1 -0
- package/dist/program/agent-runner-registry.mjs +313 -0
- package/dist/program/agent-runner-registry.mjs.map +1 -0
- package/dist/program/agent-subscribe.cjs +72 -0
- package/dist/program/agent-subscribe.d.cts +18 -0
- package/dist/program/agent-subscribe.d.cts.map +1 -0
- package/dist/program/agent-subscribe.d.mts +18 -0
- package/dist/program/agent-subscribe.d.mts.map +1 -0
- package/dist/program/agent-subscribe.mjs +73 -0
- package/dist/program/agent-subscribe.mjs.map +1 -0
- package/dist/program/agent-tools.cjs +135 -0
- package/dist/program/agent-tools.d.cts +35 -0
- package/dist/program/agent-tools.d.cts.map +1 -0
- package/dist/program/agent-tools.d.mts +35 -0
- package/dist/program/agent-tools.d.mts.map +1 -0
- package/dist/program/agent-tools.mjs +136 -0
- package/dist/program/agent-tools.mjs.map +1 -0
- package/dist/program/manifest-nesting.cjs +57 -0
- package/dist/program/manifest-nesting.d.cts +13 -0
- package/dist/program/manifest-nesting.d.cts.map +1 -0
- package/dist/program/manifest-nesting.d.mts +13 -0
- package/dist/program/manifest-nesting.d.mts.map +1 -0
- package/dist/program/manifest-nesting.mjs +57 -0
- package/dist/program/manifest-nesting.mjs.map +1 -0
- package/dist/program/result-contract.cjs +55 -0
- package/dist/program/result-contract.d.cts +23 -0
- package/dist/program/result-contract.d.cts.map +1 -0
- package/dist/program/result-contract.d.mts +23 -0
- package/dist/program/result-contract.d.mts.map +1 -0
- package/dist/program/result-contract.mjs +51 -0
- package/dist/program/result-contract.mjs.map +1 -0
- package/dist/program/runner-error.cjs +71 -0
- package/dist/program/runner-error.d.cts +25 -0
- package/dist/program/runner-error.d.cts.map +1 -0
- package/dist/program/runner-error.d.mts +25 -0
- package/dist/program/runner-error.d.mts.map +1 -0
- package/dist/program/runner-error.mjs +72 -0
- package/dist/program/runner-error.mjs.map +1 -0
- package/dist/program/scoped-afs.cjs +538 -0
- package/dist/program/scoped-afs.d.cts +245 -0
- package/dist/program/scoped-afs.d.cts.map +1 -0
- package/dist/program/scoped-afs.d.mts +245 -0
- package/dist/program/scoped-afs.d.mts.map +1 -0
- package/dist/program/scoped-afs.mjs +531 -0
- package/dist/program/scoped-afs.mjs.map +1 -0
- package/dist/program/session-hierarchy.cjs +1 -0
- package/dist/program/session-hierarchy.d.cts +2 -0
- package/dist/program/session-hierarchy.d.mts +2 -0
- package/dist/program/session-hierarchy.mjs +3 -0
- package/dist/program/tool-discovery/ash-frontmatter.cjs +83 -0
- package/dist/program/tool-discovery/ash-frontmatter.d.cts +21 -0
- package/dist/program/tool-discovery/ash-frontmatter.d.cts.map +1 -0
- package/dist/program/tool-discovery/ash-frontmatter.d.mts +21 -0
- package/dist/program/tool-discovery/ash-frontmatter.d.mts.map +1 -0
- package/dist/program/tool-discovery/ash-frontmatter.mjs +84 -0
- package/dist/program/tool-discovery/ash-frontmatter.mjs.map +1 -0
- package/dist/program/tool-discovery/dot-path-resolver.cjs +60 -0
- package/dist/program/tool-discovery/dot-path-resolver.mjs +61 -0
- package/dist/program/tool-discovery/dot-path-resolver.mjs.map +1 -0
- package/dist/program/tool-discovery/skill-gate.cjs +36 -0
- package/dist/program/tool-discovery/skill-gate.d.cts +10 -0
- package/dist/program/tool-discovery/skill-gate.d.cts.map +1 -0
- package/dist/program/tool-discovery/skill-gate.d.mts +10 -0
- package/dist/program/tool-discovery/skill-gate.d.mts.map +1 -0
- package/dist/program/tool-discovery/skill-gate.mjs +35 -0
- package/dist/program/tool-discovery/skill-gate.mjs.map +1 -0
- package/dist/providers/basic/ash/dist/index.cjs +1809 -0
- package/dist/providers/basic/ash/dist/index.mjs +1807 -0
- package/dist/providers/basic/ash/dist/index.mjs.map +1 -0
- package/package.json +67 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are proprietary
|
|
6
|
+
and confidential. Unauthorized copying, modification, distribution, or use of
|
|
7
|
+
this Software, via any medium, is strictly prohibited.
|
|
8
|
+
|
|
9
|
+
The Software is provided for internal use only within ArcBlock, Inc. and its
|
|
10
|
+
authorized affiliates.
|
|
11
|
+
|
|
12
|
+
## No License Granted
|
|
13
|
+
|
|
14
|
+
No license, express or implied, is granted to any party for any purpose.
|
|
15
|
+
All rights are reserved by ArcBlock, Inc.
|
|
16
|
+
|
|
17
|
+
## Public Artifact Distribution
|
|
18
|
+
|
|
19
|
+
Portions of this Software may be released publicly under separate open-source
|
|
20
|
+
licenses (such as MIT License) through designated public repositories. Such
|
|
21
|
+
public releases are governed by their respective licenses and do not affect
|
|
22
|
+
the proprietary nature of this repository.
|
|
23
|
+
|
|
24
|
+
## Contact
|
|
25
|
+
|
|
26
|
+
For licensing inquiries, contact: legal@arcblock.io
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @aigne/agent-runtime
|
|
2
|
+
|
|
3
|
+
Agent dispatch and runner layer for the AFS stack. Extracted from `@aigne/arc-cli` so the same runtime can back non-Node hosts (Cloudflare Workers, future edge runtimes) without pulling in the CLI shell.
|
|
4
|
+
|
|
5
|
+
## What this package owns
|
|
6
|
+
|
|
7
|
+
Every agent execution path:
|
|
8
|
+
|
|
9
|
+
| Agent type | What it does | Entry point |
|
|
10
|
+
|------------|--------------|-------------|
|
|
11
|
+
| `ai` | LLM inference + tool loop | `runAIAgent` |
|
|
12
|
+
| `ash` | Agentic Shell DSL (plan → execute) | `runAshAgent` |
|
|
13
|
+
| `team` | Sequential / parallel / reflection / iterate modes | `runTeamAgent` |
|
|
14
|
+
| `orchestrator` | Planner → worker → completer multi-round loop | `runOrchestratorAgent` |
|
|
15
|
+
|
|
16
|
+
Plus the cross-cutting machinery those runners share:
|
|
17
|
+
|
|
18
|
+
- **Budget** (`BudgetTracker`, `resolveBudget`, rounds + tokens hard caps)
|
|
19
|
+
- **Hooks** (`HookDispatcher`, `HookChannel`, skill-start / skill-end / tool-start / tool-end events)
|
|
20
|
+
- **Memory binding** (`resolveMemoryBinding` — exposes `/modules/memory/.actions/*` as LLM tools)
|
|
21
|
+
- **Scratchpad** (`provisionScratchViaAFS` — per-run scratch directory under `/modules/memory/`)
|
|
22
|
+
- **Guide rails** (`runGuideRails` — pre-run validation)
|
|
23
|
+
- **Stream router** (`onChunk` handling for UI-visible AI streams)
|
|
24
|
+
- **Messaging** (`handlePostMessage`, `handleReadMessages` — `/proc/messaging/tools/*` tools, backed by `/proc/messaging/agents/<id>/msg/`)
|
|
25
|
+
- **Result contract** (`_meta.env`, `_meta.scratchPath` sanitization; sub-agent envelope stripping)
|
|
26
|
+
- **Session hierarchy** (spawn-depth gating + child session derivation)
|
|
27
|
+
|
|
28
|
+
## How it fits in
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
┌─────────────────────────────────┐
|
|
32
|
+
│ @aigne/arc-cli (Node CLI) │
|
|
33
|
+
│ - blocklet-manager │
|
|
34
|
+
│ - daemon │
|
|
35
|
+
│ - messaging-provider │
|
|
36
|
+
└──────────────┬──────────────────┘
|
|
37
|
+
│ registerAgentActions / registerAgentSubscribes
|
|
38
|
+
▼
|
|
39
|
+
┌─────────────────────────────────┐
|
|
40
|
+
│ @aigne/agent-runtime │
|
|
41
|
+
│ - agent-runners/* │
|
|
42
|
+
│ - program/ │
|
|
43
|
+
│ · agent-action │
|
|
44
|
+
│ · agent-subscribe │
|
|
45
|
+
│ · agent-tools │
|
|
46
|
+
│ · agent-runner-registry │
|
|
47
|
+
│ · result-contract │
|
|
48
|
+
└──────────────┬──────────────────┘
|
|
49
|
+
│ afs.read / afs.write / afs.exec
|
|
50
|
+
▼
|
|
51
|
+
┌───────────┐
|
|
52
|
+
│ @aigne/afs│
|
|
53
|
+
└───────────┘
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Consumers wire it up through:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { registerAgentActions, registerAgentSubscribes } from "@aigne/agent-runtime";
|
|
60
|
+
|
|
61
|
+
registerAgentActions({ afs, manifest, /* ... */ });
|
|
62
|
+
registerAgentSubscribes({ afs, manifest, /* ... */ });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Runner-level helpers (`runAIAgent`, `runAshAgent`, ...) are exported too, for tests and tooling that need to bypass dispatch.
|
|
66
|
+
|
|
67
|
+
## Principles
|
|
68
|
+
|
|
69
|
+
1. **AFS-Only I/O** — every read / write / exec goes through `@aigne/afs`. No direct filesystem or network calls.
|
|
70
|
+
2. **Runtime-agnostic** — no Node-specific imports. Runs under Bun, Node, and workerd.
|
|
71
|
+
3. **Deterministic** — all state (budget, scratch, hooks) is derived from the AFS path; nothing lives in process memory past a single agent invocation.
|
|
72
|
+
|
|
73
|
+
## Scripts
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm build # tsdown bundle (ESM + CJS + dts)
|
|
77
|
+
pnpm check-types # tsc --noEmit
|
|
78
|
+
pnpm test # bun test (tests live under test/)
|
|
79
|
+
```
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const require_agent_tools = require('../program/agent-tools.cjs');
|
|
2
|
+
const require_budget = require('./budget.cjs');
|
|
3
|
+
const require_memory_archive = require('./memory-archive.cjs');
|
|
4
|
+
const require_template_context = require('./template-context.cjs');
|
|
5
|
+
let _aigne_afs_agent = require("@aigne/afs-agent");
|
|
6
|
+
let ufo = require("ufo");
|
|
7
|
+
|
|
8
|
+
//#region src/agent-runners/ai-runner.ts
|
|
9
|
+
const TEMPLATE_MODULE = "@aigne/ash/src/prompt/template.ts";
|
|
10
|
+
async function loadRenderTemplate() {
|
|
11
|
+
return (await import(TEMPLATE_MODULE)).renderTemplate;
|
|
12
|
+
}
|
|
13
|
+
async function runAIAgent(opts) {
|
|
14
|
+
const { afs, manifest, input, session, parentSession, chain, parentAgentInfo, mountPath, memoryBasePath } = opts;
|
|
15
|
+
const inputKey = manifest.inputKey ?? "message";
|
|
16
|
+
manifest.outputKey;
|
|
17
|
+
const task = String(input[inputKey] ?? "");
|
|
18
|
+
const runId = crypto.randomUUID();
|
|
19
|
+
const scratch = manifest.scratch && memoryBasePath && session ? (0, _aigne_afs_agent.allocateScratch)(memoryBasePath, session, runId) : null;
|
|
20
|
+
try {
|
|
21
|
+
const tools = (manifest.tools ?? []).map((t) => {
|
|
22
|
+
if (typeof t === "string") return t;
|
|
23
|
+
return t;
|
|
24
|
+
});
|
|
25
|
+
let catalogResult = null;
|
|
26
|
+
if (tools.length > 0) catalogResult = await require_agent_tools.compileToolCatalog(afs, {
|
|
27
|
+
tools,
|
|
28
|
+
blockletRoot: mountPath,
|
|
29
|
+
skillPaths: manifest.skillPaths,
|
|
30
|
+
mountPath
|
|
31
|
+
});
|
|
32
|
+
let instructionsTemplate = "";
|
|
33
|
+
if (manifest.instructions) {
|
|
34
|
+
const candidates = [(0, ufo.joinURL)(mountPath, manifest.instructions), (0, ufo.joinURL)("/packages", manifest.instructions)];
|
|
35
|
+
let lastTried = candidates[0];
|
|
36
|
+
let found = false;
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
lastTried = candidate;
|
|
39
|
+
try {
|
|
40
|
+
const readResult = await afs.read(candidate);
|
|
41
|
+
instructionsTemplate = typeof readResult === "string" ? readResult : (readResult?.data)?.content ?? String(readResult?.data ?? "");
|
|
42
|
+
if (instructionsTemplate) {
|
|
43
|
+
found = true;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
} catch {}
|
|
47
|
+
}
|
|
48
|
+
if (!found) throw new Error(`INSTRUCTIONS_NOT_FOUND: cannot read "${manifest.instructions}" at ${lastTried}`);
|
|
49
|
+
}
|
|
50
|
+
const templateCtx = require_template_context.buildTemplateContext({
|
|
51
|
+
input,
|
|
52
|
+
manifest,
|
|
53
|
+
session,
|
|
54
|
+
parentInfo: parentAgentInfo ?? null,
|
|
55
|
+
envWhitelist: manifest.envVars,
|
|
56
|
+
scratch,
|
|
57
|
+
catalogResult
|
|
58
|
+
});
|
|
59
|
+
let renderedSystem;
|
|
60
|
+
if (instructionsTemplate) renderedSystem = await (await loadRenderTemplate())(instructionsTemplate, templateCtx, {
|
|
61
|
+
blockletRoot: mountPath,
|
|
62
|
+
afs
|
|
63
|
+
});
|
|
64
|
+
if (opts.systemAppend) renderedSystem = renderedSystem ? `${renderedSystem}\n\n${opts.systemAppend}` : opts.systemAppend;
|
|
65
|
+
else if (require_memory_archive.isHandoffReadThroughEnabled(manifest.memory)) {
|
|
66
|
+
const scopeDomain = afs?.scope?.memoryDomain;
|
|
67
|
+
const manifestDomain = manifest.memory && typeof manifest.memory === "object" ? manifest.memory.domain : void 0;
|
|
68
|
+
const domain = scopeDomain ?? manifestDomain;
|
|
69
|
+
if (domain) {
|
|
70
|
+
const appendix = require_memory_archive.formatRecallForPrompt(await require_memory_archive.recallForHandoff({
|
|
71
|
+
afs,
|
|
72
|
+
domain
|
|
73
|
+
}));
|
|
74
|
+
if (appendix) renderedSystem = renderedSystem ? `${renderedSystem}\n\n${appendix}` : appendix;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const model = typeof manifest.model === "string" ? manifest.model : manifest.model ? `${manifest.model.provider}/${manifest.model.name}` : "/dev/ai/.actions/chat";
|
|
78
|
+
const toolEntries = (manifest.tools ?? []).map((t) => {
|
|
79
|
+
if (typeof t === "string") return { path: t };
|
|
80
|
+
return t;
|
|
81
|
+
});
|
|
82
|
+
if (manifest.memory) {
|
|
83
|
+
if (!toolEntries.some((t) => t.path === "/memory/**" || t.path === "/memory" || t.path.startsWith("/memory/"))) toolEntries.push({
|
|
84
|
+
path: "/memory/**",
|
|
85
|
+
ops: [
|
|
86
|
+
"read",
|
|
87
|
+
"list",
|
|
88
|
+
"exec"
|
|
89
|
+
]
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const resolved = require_budget.resolveBudget({ manifest: manifest.budget });
|
|
93
|
+
const tracker = require_budget.createBudgetTracker(resolved);
|
|
94
|
+
const execArgs = {
|
|
95
|
+
task,
|
|
96
|
+
model,
|
|
97
|
+
tools: toolEntries,
|
|
98
|
+
budget: {
|
|
99
|
+
max_rounds: resolved.maxRounds,
|
|
100
|
+
total_tokens: resolved.totalTokens
|
|
101
|
+
},
|
|
102
|
+
session: session ? `/instance/.sessions/agent/${session}` : void 0,
|
|
103
|
+
system: renderedSystem,
|
|
104
|
+
skill_paths: manifest.skillPaths,
|
|
105
|
+
_parent_session: parentSession,
|
|
106
|
+
_chain: [...chain ?? [], session ?? "root"],
|
|
107
|
+
_abort_signal: tracker.signal,
|
|
108
|
+
parentAgentInfo: parentAgentInfo ?? void 0
|
|
109
|
+
};
|
|
110
|
+
if (typeof input._ui_session === "string") execArgs._ui_session = input._ui_session;
|
|
111
|
+
const userProgress = input._on_tool_progress;
|
|
112
|
+
if (require_memory_archive.isMemoryArchiveEnabled(manifest.memory)) execArgs._on_tool_progress = require_memory_archive.wrapToolProgress(userProgress, {
|
|
113
|
+
afs,
|
|
114
|
+
session: session ?? "default"
|
|
115
|
+
});
|
|
116
|
+
else if (userProgress) execArgs._on_tool_progress = userProgress;
|
|
117
|
+
const result = await afs.exec("/dev/agent/.actions/run", execArgs, {});
|
|
118
|
+
const finalResult = {
|
|
119
|
+
success: result.success,
|
|
120
|
+
data: result.data
|
|
121
|
+
};
|
|
122
|
+
finalResult._meta = {
|
|
123
|
+
render: { template_vars: Object.keys(templateCtx) },
|
|
124
|
+
context: { system: renderedSystem ?? "" }
|
|
125
|
+
};
|
|
126
|
+
return finalResult;
|
|
127
|
+
} finally {
|
|
128
|
+
if (scratch && memoryBasePath && session) (0, _aigne_afs_agent.teardownSession)(memoryBasePath, session, manifest.scratchRetention ?? "session");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
exports.runAIAgent = runAIAgent;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ParentAgentInfo } from "./template-context.cjs";
|
|
2
|
+
import { AFSRoot, AgentManifest } from "@aigne/afs";
|
|
3
|
+
|
|
4
|
+
//#region src/agent-runners/ai-runner.d.ts
|
|
5
|
+
interface AIRunnerInput {
|
|
6
|
+
afs: AFSRoot;
|
|
7
|
+
manifest: AgentManifest;
|
|
8
|
+
input: Record<string, unknown>;
|
|
9
|
+
session?: string;
|
|
10
|
+
parentSession?: string;
|
|
11
|
+
chain?: string[];
|
|
12
|
+
parentAgentInfo?: ParentAgentInfo;
|
|
13
|
+
mountPath: string;
|
|
14
|
+
memoryBasePath?: string;
|
|
15
|
+
systemAppend?: string;
|
|
16
|
+
}
|
|
17
|
+
interface AIRunnerResult {
|
|
18
|
+
success: boolean;
|
|
19
|
+
data?: Record<string, unknown>;
|
|
20
|
+
result?: Record<string, unknown>;
|
|
21
|
+
_meta?: {
|
|
22
|
+
render?: {
|
|
23
|
+
template_vars: string[];
|
|
24
|
+
};
|
|
25
|
+
context?: {
|
|
26
|
+
system: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
declare function runAIAgent(opts: AIRunnerInput): Promise<AIRunnerResult>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AIRunnerInput, AIRunnerResult, runAIAgent };
|
|
33
|
+
//# sourceMappingURL=ai-runner.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-runner.d.cts","names":[],"sources":["../../src/agent-runners/ai-runner.ts"],"mappings":";;;;UAeiB,aAAA;EACf,GAAA,EAAK,OAAA;EACL,QAAA,EAAU,aAAA;EACV,KAAA,EAAO,MAAA;EACP,OAAA;EACA,aAAA;EACA,KAAA;EACA,eAAA,GAAkB,eAAA;EAClB,SAAA;EACA,cAAA;EACA,YAAA;AAAA;AAAA,UAGe,cAAA;EACf,OAAA;EACA,IAAA,GAAO,MAAA;EACP,MAAA,GAAS,MAAA;EACT,KAAA;IACE,MAAA;MAAW,aAAA;IAAA;IACX,OAAA;MAAY,MAAA;IAAA;EAAA;AAAA;AAAA,iBAiBM,UAAA,CAAW,IAAA,EAAM,aAAA,GAAgB,OAAA,CAAQ,cAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ParentAgentInfo } from "./template-context.mjs";
|
|
2
|
+
import { AFSRoot, AgentManifest } from "@aigne/afs";
|
|
3
|
+
|
|
4
|
+
//#region src/agent-runners/ai-runner.d.ts
|
|
5
|
+
interface AIRunnerInput {
|
|
6
|
+
afs: AFSRoot;
|
|
7
|
+
manifest: AgentManifest;
|
|
8
|
+
input: Record<string, unknown>;
|
|
9
|
+
session?: string;
|
|
10
|
+
parentSession?: string;
|
|
11
|
+
chain?: string[];
|
|
12
|
+
parentAgentInfo?: ParentAgentInfo;
|
|
13
|
+
mountPath: string;
|
|
14
|
+
memoryBasePath?: string;
|
|
15
|
+
systemAppend?: string;
|
|
16
|
+
}
|
|
17
|
+
interface AIRunnerResult {
|
|
18
|
+
success: boolean;
|
|
19
|
+
data?: Record<string, unknown>;
|
|
20
|
+
result?: Record<string, unknown>;
|
|
21
|
+
_meta?: {
|
|
22
|
+
render?: {
|
|
23
|
+
template_vars: string[];
|
|
24
|
+
};
|
|
25
|
+
context?: {
|
|
26
|
+
system: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
declare function runAIAgent(opts: AIRunnerInput): Promise<AIRunnerResult>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AIRunnerInput, AIRunnerResult, runAIAgent };
|
|
33
|
+
//# sourceMappingURL=ai-runner.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-runner.d.mts","names":[],"sources":["../../src/agent-runners/ai-runner.ts"],"mappings":";;;;UAeiB,aAAA;EACf,GAAA,EAAK,OAAA;EACL,QAAA,EAAU,aAAA;EACV,KAAA,EAAO,MAAA;EACP,OAAA;EACA,aAAA;EACA,KAAA;EACA,eAAA,GAAkB,eAAA;EAClB,SAAA;EACA,cAAA;EACA,YAAA;AAAA;AAAA,UAGe,cAAA;EACf,OAAA;EACA,IAAA,GAAO,MAAA;EACP,MAAA,GAAS,MAAA;EACT,KAAA;IACE,MAAA;MAAW,aAAA;IAAA;IACX,OAAA;MAAY,MAAA;IAAA;EAAA;AAAA;AAAA,iBAiBM,UAAA,CAAW,IAAA,EAAM,aAAA,GAAgB,OAAA,CAAQ,cAAA"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { compileToolCatalog } from "../program/agent-tools.mjs";
|
|
2
|
+
import { createBudgetTracker, resolveBudget } from "./budget.mjs";
|
|
3
|
+
import { formatRecallForPrompt, isHandoffReadThroughEnabled, isMemoryArchiveEnabled, recallForHandoff, wrapToolProgress } from "./memory-archive.mjs";
|
|
4
|
+
import { buildTemplateContext } from "./template-context.mjs";
|
|
5
|
+
import { allocateScratch, teardownSession } from "@aigne/afs-agent";
|
|
6
|
+
import { joinURL } from "ufo";
|
|
7
|
+
|
|
8
|
+
//#region src/agent-runners/ai-runner.ts
|
|
9
|
+
const TEMPLATE_MODULE = "@aigne/ash/src/prompt/template.ts";
|
|
10
|
+
async function loadRenderTemplate() {
|
|
11
|
+
return (await import(TEMPLATE_MODULE)).renderTemplate;
|
|
12
|
+
}
|
|
13
|
+
async function runAIAgent(opts) {
|
|
14
|
+
const { afs, manifest, input, session, parentSession, chain, parentAgentInfo, mountPath, memoryBasePath } = opts;
|
|
15
|
+
const inputKey = manifest.inputKey ?? "message";
|
|
16
|
+
manifest.outputKey;
|
|
17
|
+
const task = String(input[inputKey] ?? "");
|
|
18
|
+
const runId = crypto.randomUUID();
|
|
19
|
+
const scratch = manifest.scratch && memoryBasePath && session ? allocateScratch(memoryBasePath, session, runId) : null;
|
|
20
|
+
try {
|
|
21
|
+
const tools = (manifest.tools ?? []).map((t) => {
|
|
22
|
+
if (typeof t === "string") return t;
|
|
23
|
+
return t;
|
|
24
|
+
});
|
|
25
|
+
let catalogResult = null;
|
|
26
|
+
if (tools.length > 0) catalogResult = await compileToolCatalog(afs, {
|
|
27
|
+
tools,
|
|
28
|
+
blockletRoot: mountPath,
|
|
29
|
+
skillPaths: manifest.skillPaths,
|
|
30
|
+
mountPath
|
|
31
|
+
});
|
|
32
|
+
let instructionsTemplate = "";
|
|
33
|
+
if (manifest.instructions) {
|
|
34
|
+
const candidates = [joinURL(mountPath, manifest.instructions), joinURL("/packages", manifest.instructions)];
|
|
35
|
+
let lastTried = candidates[0];
|
|
36
|
+
let found = false;
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
lastTried = candidate;
|
|
39
|
+
try {
|
|
40
|
+
const readResult = await afs.read(candidate);
|
|
41
|
+
instructionsTemplate = typeof readResult === "string" ? readResult : (readResult?.data)?.content ?? String(readResult?.data ?? "");
|
|
42
|
+
if (instructionsTemplate) {
|
|
43
|
+
found = true;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
} catch {}
|
|
47
|
+
}
|
|
48
|
+
if (!found) throw new Error(`INSTRUCTIONS_NOT_FOUND: cannot read "${manifest.instructions}" at ${lastTried}`);
|
|
49
|
+
}
|
|
50
|
+
const templateCtx = buildTemplateContext({
|
|
51
|
+
input,
|
|
52
|
+
manifest,
|
|
53
|
+
session,
|
|
54
|
+
parentInfo: parentAgentInfo ?? null,
|
|
55
|
+
envWhitelist: manifest.envVars,
|
|
56
|
+
scratch,
|
|
57
|
+
catalogResult
|
|
58
|
+
});
|
|
59
|
+
let renderedSystem;
|
|
60
|
+
if (instructionsTemplate) renderedSystem = await (await loadRenderTemplate())(instructionsTemplate, templateCtx, {
|
|
61
|
+
blockletRoot: mountPath,
|
|
62
|
+
afs
|
|
63
|
+
});
|
|
64
|
+
if (opts.systemAppend) renderedSystem = renderedSystem ? `${renderedSystem}\n\n${opts.systemAppend}` : opts.systemAppend;
|
|
65
|
+
else if (isHandoffReadThroughEnabled(manifest.memory)) {
|
|
66
|
+
const scopeDomain = afs?.scope?.memoryDomain;
|
|
67
|
+
const manifestDomain = manifest.memory && typeof manifest.memory === "object" ? manifest.memory.domain : void 0;
|
|
68
|
+
const domain = scopeDomain ?? manifestDomain;
|
|
69
|
+
if (domain) {
|
|
70
|
+
const appendix = formatRecallForPrompt(await recallForHandoff({
|
|
71
|
+
afs,
|
|
72
|
+
domain
|
|
73
|
+
}));
|
|
74
|
+
if (appendix) renderedSystem = renderedSystem ? `${renderedSystem}\n\n${appendix}` : appendix;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const model = typeof manifest.model === "string" ? manifest.model : manifest.model ? `${manifest.model.provider}/${manifest.model.name}` : "/dev/ai/.actions/chat";
|
|
78
|
+
const toolEntries = (manifest.tools ?? []).map((t) => {
|
|
79
|
+
if (typeof t === "string") return { path: t };
|
|
80
|
+
return t;
|
|
81
|
+
});
|
|
82
|
+
if (manifest.memory) {
|
|
83
|
+
if (!toolEntries.some((t) => t.path === "/memory/**" || t.path === "/memory" || t.path.startsWith("/memory/"))) toolEntries.push({
|
|
84
|
+
path: "/memory/**",
|
|
85
|
+
ops: [
|
|
86
|
+
"read",
|
|
87
|
+
"list",
|
|
88
|
+
"exec"
|
|
89
|
+
]
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const resolved = resolveBudget({ manifest: manifest.budget });
|
|
93
|
+
const tracker = createBudgetTracker(resolved);
|
|
94
|
+
const execArgs = {
|
|
95
|
+
task,
|
|
96
|
+
model,
|
|
97
|
+
tools: toolEntries,
|
|
98
|
+
budget: {
|
|
99
|
+
max_rounds: resolved.maxRounds,
|
|
100
|
+
total_tokens: resolved.totalTokens
|
|
101
|
+
},
|
|
102
|
+
session: session ? `/instance/.sessions/agent/${session}` : void 0,
|
|
103
|
+
system: renderedSystem,
|
|
104
|
+
skill_paths: manifest.skillPaths,
|
|
105
|
+
_parent_session: parentSession,
|
|
106
|
+
_chain: [...chain ?? [], session ?? "root"],
|
|
107
|
+
_abort_signal: tracker.signal,
|
|
108
|
+
parentAgentInfo: parentAgentInfo ?? void 0
|
|
109
|
+
};
|
|
110
|
+
if (typeof input._ui_session === "string") execArgs._ui_session = input._ui_session;
|
|
111
|
+
const userProgress = input._on_tool_progress;
|
|
112
|
+
if (isMemoryArchiveEnabled(manifest.memory)) execArgs._on_tool_progress = wrapToolProgress(userProgress, {
|
|
113
|
+
afs,
|
|
114
|
+
session: session ?? "default"
|
|
115
|
+
});
|
|
116
|
+
else if (userProgress) execArgs._on_tool_progress = userProgress;
|
|
117
|
+
const result = await afs.exec("/dev/agent/.actions/run", execArgs, {});
|
|
118
|
+
const finalResult = {
|
|
119
|
+
success: result.success,
|
|
120
|
+
data: result.data
|
|
121
|
+
};
|
|
122
|
+
finalResult._meta = {
|
|
123
|
+
render: { template_vars: Object.keys(templateCtx) },
|
|
124
|
+
context: { system: renderedSystem ?? "" }
|
|
125
|
+
};
|
|
126
|
+
return finalResult;
|
|
127
|
+
} finally {
|
|
128
|
+
if (scratch && memoryBasePath && session) teardownSession(memoryBasePath, session, manifest.scratchRetention ?? "session");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
export { runAIAgent };
|
|
134
|
+
//# sourceMappingURL=ai-runner.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-runner.mjs","names":[],"sources":["../../src/agent-runners/ai-runner.ts"],"sourcesContent":["import type { AFSRoot, AgentManifest } from \"@aigne/afs\";\nimport { allocateScratch, teardownSession } from \"@aigne/afs-agent\";\nimport { joinURL } from \"ufo\";\nimport { type CatalogResult, compileToolCatalog } from \"../program/agent-tools.js\";\nimport { createBudgetTracker, resolveBudget } from \"./budget.js\";\nimport {\n formatRecallForPrompt,\n isHandoffReadThroughEnabled,\n isMemoryArchiveEnabled,\n recallForHandoff,\n type ToolProgressEvent,\n wrapToolProgress,\n} from \"./memory-archive.js\";\nimport { buildTemplateContext, type ParentAgentInfo } from \"./template-context.js\";\n\nexport interface AIRunnerInput {\n afs: AFSRoot;\n manifest: AgentManifest;\n input: Record<string, unknown>;\n session?: string;\n parentSession?: string;\n chain?: string[];\n parentAgentInfo?: ParentAgentInfo;\n mountPath: string;\n memoryBasePath?: string;\n systemAppend?: string;\n}\n\nexport interface AIRunnerResult {\n success: boolean;\n data?: Record<string, unknown>;\n result?: Record<string, unknown>;\n _meta?: {\n render?: { template_vars: string[] };\n context?: { system: string };\n };\n}\n\nconst TEMPLATE_MODULE = \"@aigne/ash/src/prompt/template.ts\";\n\nasync function loadRenderTemplate(): Promise<\n (\n template: string,\n vars: Record<string, unknown>,\n opts?: { blockletRoot?: string; afs?: any },\n ) => Promise<string>\n> {\n const mod = await import(TEMPLATE_MODULE);\n return mod.renderTemplate;\n}\n\nexport async function runAIAgent(opts: AIRunnerInput): Promise<AIRunnerResult> {\n const {\n afs,\n manifest,\n input,\n session,\n parentSession,\n chain,\n parentAgentInfo,\n mountPath,\n memoryBasePath,\n } = opts;\n\n const inputKey = manifest.inputKey ?? \"message\";\n const _outputKey = manifest.outputKey;\n const task = String(input[inputKey] ?? \"\");\n\n const runId = crypto.randomUUID();\n const scratch =\n manifest.scratch && memoryBasePath && session\n ? allocateScratch(memoryBasePath, session, runId)\n : null;\n\n try {\n const tools = (manifest.tools ?? []).map((t) => {\n if (typeof t === \"string\") return t;\n return t;\n });\n\n let catalogResult: CatalogResult | null = null;\n if (tools.length > 0) {\n catalogResult = await compileToolCatalog(afs as any, {\n tools,\n blockletRoot: mountPath,\n skillPaths: manifest.skillPaths,\n mountPath,\n });\n }\n\n let instructionsTemplate = \"\";\n if (manifest.instructions) {\n // B12: Runtime AFS projects the blocklet directory at /packages; the\n // external mountPath isn't a valid internal path after activation.\n // Try mountPath first (works in tests + pre-activation), fall back to\n // /packages (production post-activation).\n const candidates = [\n joinURL(mountPath, manifest.instructions),\n joinURL(\"/packages\", manifest.instructions),\n ];\n let lastTried = candidates[0]!;\n let found = false;\n for (const candidate of candidates) {\n lastTried = candidate;\n try {\n const readResult = await afs.read!(candidate);\n instructionsTemplate =\n typeof readResult === \"string\"\n ? readResult\n : ((readResult?.data as any)?.content ?? String(readResult?.data ?? \"\"));\n if (instructionsTemplate) {\n found = true;\n break;\n }\n } catch {\n // Try next candidate\n }\n }\n if (!found) {\n throw new Error(\n `INSTRUCTIONS_NOT_FOUND: cannot read \"${manifest.instructions}\" at ${lastTried}`,\n );\n }\n }\n\n const templateCtx = buildTemplateContext({\n input,\n manifest,\n session,\n parentInfo: parentAgentInfo ?? null,\n envWhitelist: manifest.envVars,\n scratch,\n catalogResult,\n });\n\n let renderedSystem: string | undefined;\n if (instructionsTemplate) {\n const renderTemplate = await loadRenderTemplate();\n renderedSystem = await renderTemplate(\n instructionsTemplate,\n templateCtx as unknown as Record<string, unknown>,\n { blockletRoot: mountPath, afs: afs as any },\n );\n }\n\n if (opts.systemAppend) {\n renderedSystem = renderedSystem\n ? `${renderedSystem}\\n\\n${opts.systemAppend}`\n : opts.systemAppend;\n } else if (isHandoffReadThroughEnabled(manifest.memory)) {\n // Top-level single-agent recall. When `opts.systemAppend` is unset,\n // there's no parent team that already paid the recall cost — this\n // run owns the read-through. The team-runner does the same step at\n // its own layer (see `team-runner.ts:230`); doing it here closes\n // the gap so a `type: ai` agent with `memory.handoffReadThrough` can\n // surface prior observations across sessions without needing a\n // dummy team wrapper.\n const scopeDomain = (afs as { scope?: { memoryDomain?: string } } | undefined)?.scope\n ?.memoryDomain;\n const manifestDomain =\n manifest.memory && typeof manifest.memory === \"object\"\n ? (manifest.memory as { domain?: string }).domain\n : undefined;\n const domain = scopeDomain ?? manifestDomain;\n if (domain) {\n const recalled = await recallForHandoff({ afs, domain });\n const appendix = formatRecallForPrompt(recalled);\n if (appendix) {\n renderedSystem = renderedSystem ? `${renderedSystem}\\n\\n${appendix}` : appendix;\n }\n }\n }\n\n const model =\n typeof manifest.model === \"string\"\n ? manifest.model\n : manifest.model\n ? `${manifest.model.provider}/${manifest.model.name}`\n : \"/dev/ai/.actions/chat\";\n\n const toolEntries = (manifest.tools ?? []).map((t) => {\n if (typeof t === \"string\") return { path: t };\n return t;\n });\n\n // AFS conformance: top-level AI agents with `manifest.memory` enabled\n // get standard read/list/exec on `/memory/**` so the agent can both\n // observe (`afs_list /memory/<domain>`) and operate (`recall`,\n // `remember`) the memory store. For child scopes, `projectForChild`\n // (scoped-afs.ts → ensureMemoryTool) does the same.\n if (manifest.memory) {\n const hasMemoryTool = toolEntries.some(\n (t: { path: string }) =>\n t.path === \"/memory/**\" || t.path === \"/memory\" || t.path.startsWith(\"/memory/\"),\n );\n if (!hasMemoryTool) {\n toolEntries.push({ path: \"/memory/**\", ops: [\"read\", \"list\", \"exec\"] });\n }\n }\n\n const resolved = resolveBudget({ manifest: manifest.budget });\n const tracker = createBudgetTracker(resolved);\n\n const execArgs: Record<string, unknown> = {\n task,\n model,\n tools: toolEntries,\n budget: {\n max_rounds: resolved.maxRounds,\n total_tokens: resolved.totalTokens,\n },\n session: session ? `/instance/.sessions/agent/${session}` : undefined,\n system: renderedSystem,\n skill_paths: manifest.skillPaths,\n _parent_session: parentSession,\n _chain: [...(chain ?? []), session ?? \"root\"],\n _abort_signal: tracker.signal,\n parentAgentInfo: parentAgentInfo ?? undefined,\n };\n\n // Forward the UI surface id (ask_user routing) — `session` above is the\n // agent's history session, distinct from the originating UI sessionId.\n if (typeof input._ui_session === \"string\") {\n execArgs._ui_session = input._ui_session;\n }\n\n const userProgress = input._on_tool_progress as\n | ((event: ToolProgressEvent) => void)\n | undefined;\n if (isMemoryArchiveEnabled(manifest.memory)) {\n execArgs._on_tool_progress = wrapToolProgress(userProgress, {\n afs,\n session: session ?? \"default\",\n });\n } else if (userProgress) {\n execArgs._on_tool_progress = userProgress;\n }\n\n const result = (await afs.exec!(\"/dev/agent/.actions/run\", execArgs, {})) as any;\n\n const finalResult: AIRunnerResult = {\n success: result.success,\n data: result.data,\n };\n\n finalResult._meta = {\n render: {\n template_vars: Object.keys(templateCtx),\n },\n context: {\n system: renderedSystem ?? \"\",\n },\n };\n\n return finalResult;\n } finally {\n if (scratch && memoryBasePath && session) {\n const retention = (manifest as any).scratchRetention ?? \"session\";\n teardownSession(memoryBasePath, session, retention);\n }\n }\n}\n"],"mappings":"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"}
|