@a5c-ai/agent-core 0.1.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.
Files changed (2) hide show
  1. package/README.md +217 -0
  2. package/package.json +49 -0
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ # @a5c-ai/agent-core
2
+
3
+ Built-in programmatic session wrapper and agentic tool surface for Babysitter runtime consumers.
4
+
5
+ <!-- docs-status:start -->
6
+ > Status: Public advanced/runtime package.
7
+ > Canonical docs home: [Package and Plugin Docs Map](../../docs/package-and-plugin-map.md).
8
+ > This README defines the package contract for runtime consumers and published dependents such as `@a5c-ai/babysitter-agent`.
9
+ <!-- docs-status:end -->
10
+
11
+ ## Package role
12
+
13
+ `@a5c-ai/agent-core` sits between `@a5c-ai/babysitter-agent`, `@a5c-ai/agent-mux`, and `@a5c-ai/babysitter-sdk`:
14
+
15
+ - `createAgentCoreSession()` wraps an `@a5c-ai/agent-mux` client for in-process prompt execution.
16
+ - `createAgentCoreToolDefinitions()` assembles the built-in Babysitter-flavored tool surface that host runtimes can inject into planning, resume, or delegated-task flows.
17
+ - `@a5c-ai/babysitter-agent` re-exports these APIs from `src/harness/index.ts`, uses `createAgentCoreSession()` for direct `agent-core` harness invocation in `src/harness/invoker.ts`, and injects tool definitions into plan-process and resume-run flows.
18
+ - `@a5c-ai/babysitter-sdk` still owns run directories, journals, task/effect lifecycle, and config defaults. `agent-core` does not replace the SDK orchestration layer.
19
+
20
+ This package is published as a runtime dependency surface for higher-level Babysitter runtimes. It is still an advanced/operator-facing building block rather than the primary entrypoint for new users.
21
+
22
+ ## Root exports
23
+
24
+ The package root exports the runtime surface assembled from `src/index.ts` and `src/tools.ts`:
25
+
26
+ ```ts
27
+ import {
28
+ AGENT_CORE_TOOL_NAMES,
29
+ AgentCoreSessionHandle,
30
+ DeferredToolRegistry,
31
+ createAgentCoreSession,
32
+ createAgentCoreToolDefinitions,
33
+ disposeAgentCoreToolDefinitions,
34
+ extractTextFromHtml,
35
+ filterByRelevance,
36
+ parseSearchResults,
37
+ resetRunScopedConfig,
38
+ stripHtmlTags,
39
+ type AgentCoreEventListener,
40
+ type AgentCorePromptResult,
41
+ type AgentCoreSessionEvent,
42
+ type AgentCoreSessionOptions,
43
+ type AgentCoreToolOptions,
44
+ type CustomToolDefinition,
45
+ type ToolResult,
46
+ } from "@a5c-ai/agent-core";
47
+ ```
48
+
49
+ Key exports:
50
+
51
+ - `createAgentCoreSession(options)` / `AgentCoreSessionHandle`: programmatic session API backed by `@a5c-ai/agent-mux`.
52
+ - `createAgentCoreToolDefinitions(options)` / `disposeAgentCoreToolDefinitions(definitions)`: built-in tool-definition assembly and teardown.
53
+ - `DeferredToolRegistry`: lazy registry for searchable/fetchable external tool schemas.
54
+ - `AGENT_CORE_TOOL_NAMES`: canonical bundled tool name list.
55
+ - `AgenticToolOptions` and `AGENTIC_TOOL_NAMES`: compatibility aliases for older host integrations.
56
+ - `resetRunScopedConfig()`: clears run-scoped state used by the `config` tool.
57
+ - `parseSearchResults()`, `stripHtmlTags()`, `extractTextFromHtml()`, `filterByRelevance()`: helper exports used by web/search integrations.
58
+
59
+ ## Session API
60
+
61
+ `createAgentCoreSession()` returns an `AgentCoreSessionHandle` that wraps a shared `@a5c-ai/agent-mux` client with built-in adapters registered once per process.
62
+
63
+ Core handle methods:
64
+
65
+ - `initialize()`: currently a no-op placeholder for compatibility.
66
+ - `prompt(text, timeout?)`: starts a run, streams events to subscribers, and returns `{ output, duration, success, exitCode }`.
67
+ - `steer(text)`: sends immediate steering text while a prompt is active, or queues it for the next prompt.
68
+ - `followUp(text)`: queues a post-response follow-up when streaming, or appends it to the next prompt when idle.
69
+ - `subscribe(listener)`: receives normalized `AgentCoreSessionEvent` payloads, including `session_start`.
70
+ - `abort()`: aborts the active run if one is in progress.
71
+ - `dispose()`: aborts the active run, clears listeners, and drops queued follow-ups.
72
+ - `executeCommand()` / `executeBash()`: local shell helpers scoped to `options.workspace`.
73
+ - `sessionId` / `isStreaming`: getters for the active continued session id and current streaming state.
74
+
75
+ Session behavior that matters to host integrations:
76
+
77
+ - Agent-core reuses the `sessionId` learned from prior runs, so later prompts continue the same agent-mux session when the backend supports it.
78
+ - Concurrent `prompt()` calls on the same handle are rejected.
79
+ - Event payloads are normalized before subscribers see them. Non-object payloads become `{ type: "unknown", value }`.
80
+ - Approval mode is `prompt` only when `uiContext` is present; otherwise agent-core uses `yolo`.
81
+
82
+ ### Supported runtime options
83
+
84
+ | Option | Runtime effect |
85
+ | --- | --- |
86
+ | `workspace` | Forwarded to agent-mux as `cwd`. |
87
+ | `model` | Forwarded to agent-mux as `model`. |
88
+ | `timeout` | Forwarded to agent-mux as `timeout`. |
89
+ | `thinkingLevel` | Translated to agent-mux `thinkingEffort` (`minimal`/`low` -> `low`, `medium` -> `medium`, `high` -> `high`, `xhigh` -> `max`). |
90
+ | `systemPrompt` | Used as the base `systemPrompt`. |
91
+ | `appendSystemPrompt` | Appended to the final `systemPrompt` before dispatch. |
92
+ | `uiContext` | Switches run approval mode to `prompt`; when omitted, agent-core uses `yolo`. |
93
+ | `backend` | Selects the agent-mux adapter/backend forwarded as `agent`. |
94
+
95
+ ### Deprecated compatibility fields
96
+
97
+ These fields remain on `AgentCoreSessionOptions` for compatibility, but the current runtime ignores them:
98
+
99
+ | Option | Status | Migration note |
100
+ | --- | --- | --- |
101
+ | `toolsMode` | Deprecated, ignored by agent-core | Use backend-native configuration, or the PI wrapper in `@a5c-ai/babysitter-agent`, if you still need tool-surface control. |
102
+ | `customTools` | Deprecated, ignored by agent-core | Register host-side tools with `createAgentCoreToolDefinitions()` or use the PI wrapper for runtime custom-tool injection. |
103
+ | `isolated` | Deprecated, ignored by agent-core | Use the PI wrapper if you still need extension/skills isolation controls. |
104
+ | `ephemeral` | Deprecated, ignored by agent-core | Session persistence is determined by the selected agent-mux backend. |
105
+ | `bashSandbox` | Deprecated, ignored by agent-core | Sandbox behavior belongs to the selected backend. |
106
+ | `enableCompaction` | Deprecated, ignored by agent-core | Compaction behavior belongs to the selected backend/runtime. |
107
+ | `agentDir` | Deprecated, ignored by agent-core | Configure agent directories through the target backend instead. |
108
+
109
+ If you still need the PI-era controls above, use the PI wrapper exposed from `@a5c-ai/babysitter-agent` rather than `@a5c-ai/agent-core`.
110
+
111
+ ## Tool-definition API
112
+
113
+ `createAgentCoreToolDefinitions(options)` returns a wrapped `CustomToolDefinition[]` assembled from:
114
+
115
+ - file-system tools: `read`, `write`, `edit`, `grep`, `find`
116
+ - execution tools: `bash`, `python`, `ssh`, `fetch`
117
+ - browser/config tools: `browser`, `config`
118
+ - delegation tools: `AskUserQuestion`, `task`, `skill`
119
+ - code tools: `calc`, `ast_grep`, `ast_edit`, `render_mermaid`, `notebook`
120
+ - background/discovery/web tools: `background_status`, `background_list`, `tool_search`, `tool_fetch`, `web_search`, `fetch_process`
121
+
122
+ `AgentCoreToolOptions` controls how those definitions are wired into a host runtime:
123
+
124
+ - `workspace`: base directory for filesystem and execution tools.
125
+ - `interactive`: gates interactive tool behavior.
126
+ - `askUserQuestionHandler`, `taskHandler`, `skillHandler`: host-owned handlers for delegated tool calls.
127
+ - `onToolUse`: observer callback fired after tool wrapping.
128
+ - `onBackgroundComplete`, `maxBackgroundProcesses`, `backgroundRegistry`: background-process lifecycle hooks and limits.
129
+ - `deferredToolRegistry`: enables `tool_search` and `tool_fetch`.
130
+
131
+ ### Interactive and cancellation contract
132
+
133
+ - `interactive: false` disables `AskUserQuestion` even if `askUserQuestionHandler` is supplied. Both simple and structured calls return `Error: AskUserQuestion is unavailable when interactive=false.` and the handler is never invoked.
134
+ - `CustomToolDefinition.execute()` does not receive a shared `AbortSignal`. Long-running tools must own their own timeout/cancellation behavior.
135
+ - Synchronous throws and rejected promises are normalized into `Error: ...` tool results.
136
+ - Timeout-driven aborts are normalized to `Error: Tool execution was cancelled.`
137
+
138
+ ### Background-task lifecycle caveats
139
+
140
+ Background tasks are scoped to the returned tool-definition array, not to a module-global singleton.
141
+
142
+ - `background_list` and `background_status` only expose tasks started by that same definition set.
143
+ - `maxBackgroundProcesses` is enforced per scoped registry.
144
+ - `disposeAgentCoreToolDefinitions(definitions)` kills still-running background tasks and clears retained stdout/stderr/task records for that definition set.
145
+ - If you inject a custom `backgroundRegistry`, ownership moves to the caller and you must dispose it yourself.
146
+
147
+ ### Config tool state
148
+
149
+ The `config` tool reads Babysitter defaults from `@a5c-ai/babysitter-sdk` and also supports run-scoped in-memory overrides plus selected global env-var writes.
150
+
151
+ Call `resetRunScopedConfig()` between independent runs if your host process reuses the same agent-core module instance and you do not want config overrides to leak across runs.
152
+
153
+ ## DeferredToolRegistry API
154
+
155
+ `DeferredToolRegistry` is the package's lazy schema registry for non-bundled tools.
156
+
157
+ Typical flow:
158
+
159
+ 1. Register tier-1 entries with `registerTools()`.
160
+ 2. Register per-source loaders with `registerLoader()`.
161
+ 3. Use `tool_search` or `searchTools()` for lightweight discovery by name/description.
162
+ 4. Use `tool_fetch` or `fetchSchema()` to lazily load and cache a full schema.
163
+
164
+ Useful methods:
165
+
166
+ - `registerTools(entries)`
167
+ - `registerLoader(source, loader)`
168
+ - `getAllEntries()`
169
+ - `getEntriesBySource(source, sourceQualifier?)`
170
+ - `searchTools(query, maxResults?)`
171
+ - `fetchSchema(toolName, source?, sourceQualifier?)`
172
+ - `removeToolsBySource(source, sourceQualifier?)`
173
+ - `clear()`
174
+ - `size` / `loadedSchemaCount`
175
+
176
+ Source disambiguation uses `(source, sourceQualifier, name)`, so duplicate tool names from different MCP servers or plugins can coexist safely.
177
+
178
+ ## Integration points
179
+
180
+ Current downstream integration boundaries in this repo:
181
+
182
+ - `@a5c-ai/babysitter-agent`
183
+ - re-exports the session/tool APIs from `src/harness/index.ts`
184
+ - uses `createAgentCoreSession()` for the direct `agent-core` harness path in `src/harness/invoker.ts`
185
+ - injects `createAgentCoreToolDefinitions()` into plan-process and delegated-task flows in `src/harness/internal/createRun/planProcess/*`
186
+ - uses both session and tool-definition APIs in `src/cli/commands/harness/resumeRun.ts` to inspect and resume existing runs
187
+ - `@a5c-ai/agent-mux`
188
+ - provides the actual client, built-in adapters, session continuation, approval mode, and backend selection that agent-core forwards into
189
+ - `@a5c-ai/babysitter-sdk`
190
+ - provides config defaults/env wiring used by the `config` tool and remains the owner of orchestration/run-state semantics outside this package
191
+
192
+ In practice, use `agent-core` when you need an in-process runtime wrapper or bundled tool surface. Use `babysitter-agent` when you need the higher-level harness CLI/runtime entrypoints.
193
+
194
+ ## Build, test, and CI
195
+
196
+ From the repo root:
197
+
198
+ ```bash
199
+ npm run build --workspace=@a5c-ai/agent-core
200
+ npm run test --workspace=@a5c-ai/agent-core
201
+ ```
202
+
203
+ The package `build` script invokes the root `build:runtime:agent-core-deps` entrypoint before `tsc --build`, so fresh-checkout builds do not depend on prebuilt upstream `dist/` output.
204
+
205
+ Package-local `test` runs `vitest` against:
206
+
207
+ - `src/session.test.ts` for session option/event/continuation behavior
208
+ - `src/tools.test.ts` for tool-surface behavior, background-task scoping, AskUserQuestion gating, and helper exports
209
+ - `src/deferredToolRegistry.test.ts` for registry search, fetch, cache, and removal behavior
210
+
211
+ For the shared runtime chain used by release-oriented workflows, run:
212
+
213
+ ```bash
214
+ npm run build:runtime
215
+ ```
216
+
217
+ Per [Workspace Validation Map](../../docs/workspace-validation.md), `packages/agent-core` is a public advanced/runtime package validated by `.github/workflows/ci.yml` job `test` and by the release/staging workflows. Keep README claims aligned with those validation paths rather than inventing package-specific CI jobs that do not exist.
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@a5c-ai/agent-core",
3
+ "version": "0.1.0",
4
+ "description": "Built-in agent-core runtime and tool surface for Babysitter.",
5
+ "license": "MIT",
6
+ "type": "commonjs",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "require": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist/",
19
+ "README.md"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "scripts": {
25
+ "build": "npm run build:runtime:agent-core-deps --prefix ../.. && tsc --build --force tsconfig.json",
26
+ "clean": "rimraf dist tsconfig.tsbuildinfo",
27
+ "test": "vitest run --config vitest.config.ts"
28
+ },
29
+ "dependencies": {
30
+ "@a5c-ai/agent-mux": "^0.4.9",
31
+ "@a5c-ai/babysitter-sdk": "5.0.0",
32
+ "@sinclair/typebox": "^0.34.48"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^20.11.30",
36
+ "rimraf": "^5.0.5",
37
+ "typescript": "^5.4.2",
38
+ "vitest": "^4.0.18"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/a5c-ai/babysitter.git",
43
+ "directory": "packages/agent-core"
44
+ },
45
+ "homepage": "https://github.com/a5c-ai/babysitter/tree/main/packages/agent-core#readme",
46
+ "bugs": {
47
+ "url": "https://github.com/a5c-ai/babysitter/issues"
48
+ }
49
+ }