@amalgm/agents 0.1.2 → 0.2.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 (73) hide show
  1. package/PURPOSE.md +29 -22
  2. package/README.md +36 -46
  3. package/dist/agents.d.ts +4 -26
  4. package/dist/agents.js +4 -87
  5. package/dist/bin/mcp.js +1 -1
  6. package/dist/bundles/create.d.ts +13 -0
  7. package/dist/bundles/create.js +125 -0
  8. package/dist/bundles/graph-records.d.ts +10 -0
  9. package/dist/bundles/graph-records.js +61 -0
  10. package/dist/bundles/graph.d.ts +6 -0
  11. package/dist/bundles/graph.js +121 -0
  12. package/dist/bundles/install.d.ts +6 -0
  13. package/dist/bundles/install.js +64 -0
  14. package/dist/bundles/types.d.ts +97 -0
  15. package/dist/bundles/types.js +1 -0
  16. package/dist/bundles/util.d.ts +14 -0
  17. package/dist/bundles/util.js +56 -0
  18. package/dist/bundles/validate.d.ts +2 -0
  19. package/dist/bundles/validate.js +92 -0
  20. package/dist/cli/help.d.ts +1 -1
  21. package/dist/cli/help.js +2 -13
  22. package/dist/cli/open.d.ts +1 -1
  23. package/dist/cli/open.js +1 -5
  24. package/dist/cli/run.js +3 -8
  25. package/dist/errors.d.ts +1 -1
  26. package/dist/errors.js +0 -2
  27. package/dist/http/bundle-routes.d.ts +2 -0
  28. package/dist/http/bundle-routes.js +67 -0
  29. package/dist/http/server.js +4 -8
  30. package/dist/http-types.d.ts +3 -0
  31. package/dist/index.d.ts +7 -2
  32. package/dist/index.js +5 -2
  33. package/dist/mcp/agent-tools.js +1 -1
  34. package/dist/mcp/server.js +1 -1
  35. package/dist/mcp/tools.js +1 -2
  36. package/dist/rows.d.ts +1 -4
  37. package/dist/rows.js +0 -39
  38. package/dist/schema.js +53 -101
  39. package/dist/types.d.ts +0 -106
  40. package/docs/ARCHITECTURE.md +21 -33
  41. package/docs/CLI.md +3 -43
  42. package/docs/DATA_MODEL.md +7 -46
  43. package/docs/DEFINITIONS.md +4 -4
  44. package/docs/ENGINE_INTEGRATION.md +22 -67
  45. package/docs/MCP.md +3 -19
  46. package/docs/REST.md +14 -85
  47. package/docs/SDK.md +12 -61
  48. package/docs/SECURITY.md +6 -35
  49. package/examples/basic.ts +8 -22
  50. package/package.json +2 -2
  51. package/skills/amalgm-agents/SKILL.md +3 -12
  52. package/skills/amalgm-agents/agents/openai.yaml +2 -2
  53. package/dist/cli/session-commands.d.ts +0 -4
  54. package/dist/cli/session-commands.js +0 -54
  55. package/dist/drivers.d.ts +0 -4
  56. package/dist/drivers.js +0 -25
  57. package/dist/event-store.d.ts +0 -13
  58. package/dist/event-store.js +0 -50
  59. package/dist/http/session-routes.d.ts +0 -2
  60. package/dist/http/session-routes.js +0 -67
  61. package/dist/http/stream.d.ts +0 -3
  62. package/dist/http/stream.js +0 -30
  63. package/dist/mcp/session-tools.d.ts +0 -3
  64. package/dist/mcp/session-tools.js +0 -81
  65. package/dist/messages.d.ts +0 -3
  66. package/dist/messages.js +0 -56
  67. package/dist/runtime.d.ts +0 -29
  68. package/dist/runtime.js +0 -176
  69. package/dist/session-store.d.ts +0 -15
  70. package/dist/session-store.js +0 -83
  71. package/dist/turn-store.d.ts +0 -31
  72. package/dist/turn-store.js +0 -164
  73. package/docs/DRIVERS.md +0 -72
@@ -2,11 +2,10 @@ import http from 'node:http';
2
2
  import { Agents } from '../agents.js';
3
3
  import { asAgentError } from '../errors.js';
4
4
  import { routeAgentConfig } from './config-routes.js';
5
+ import { routeAgentBundles } from './bundle-routes.js';
5
6
  import { routeAgents } from './agent-routes.js';
6
7
  import { guardRequest, readJson, sendJson } from './request.js';
7
- import { routeSessions } from './session-routes.js';
8
8
  import { routeSkills } from './skill-routes.js';
9
- import { streamEvents } from './stream.js';
10
9
  export function createRestServer(options = {}) {
11
10
  const agents = options.agents || new Agents(options);
12
11
  const owned = !options.agents;
@@ -46,20 +45,17 @@ export function createRestServer(options = {}) {
46
45
  url,
47
46
  skillRoots: options.skillRoots || {},
48
47
  ...(options.nativeHomeDir ? { nativeHomeDir: options.nativeHomeDir } : {}),
48
+ ...(options.bundlePort ? { bundlePort: options.bundlePort } : {}),
49
49
  body: () => readJson(request, bodyLimit),
50
50
  json: (status, value) => sendJson(response, status, value),
51
51
  };
52
- if (await routeAgentConfig(context) || await routeSkills(context))
52
+ if (await routeAgentBundles(context) || await routeAgentConfig(context) || await routeSkills(context))
53
53
  return;
54
54
  if (path.shift() !== 'v1') {
55
55
  sendJson(response, 404, { error: { code: 'not_found', message: 'Route not found.' } });
56
56
  return;
57
57
  }
58
- if (path[0] === 'sessions' && path[2] === 'events' && path[3] === 'stream' && request.method === 'GET') {
59
- streamEvents(agents, path[1] || '', request, response, Number(url.searchParams.get('after') || 0));
60
- return;
61
- }
62
- if (await routeAgents(context) || await routeSessions(context))
58
+ if (await routeAgents(context))
63
59
  return;
64
60
  sendJson(response, 404, { error: { code: 'not_found', message: 'Route not found.' } });
65
61
  }
@@ -3,12 +3,14 @@ import type { AddressInfo } from 'node:net';
3
3
  import type { Agents } from './agents.js';
4
4
  import type { AgentsOptions } from './types.js';
5
5
  import type { SkillRootOptions } from './skills/roots.js';
6
+ import type { AgentBundlePort } from './bundles/types.js';
6
7
  export interface RestServerOptions extends AgentsOptions {
7
8
  agents?: Agents;
8
9
  token?: string;
9
10
  bodyLimitBytes?: number;
10
11
  skillRoots?: SkillRootOptions;
11
12
  nativeHomeDir?: string;
13
+ bundlePort?: AgentBundlePort;
12
14
  }
13
15
  export interface RestServer {
14
16
  agents: Agents;
@@ -23,6 +25,7 @@ export interface RouteContext {
23
25
  url: URL;
24
26
  skillRoots: SkillRootOptions;
25
27
  nativeHomeDir?: string;
28
+ bundlePort?: AgentBundlePort;
26
29
  body(): Promise<Record<string, unknown>>;
27
30
  json(status: number, value: unknown): void;
28
31
  }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  export { Agents } from './agents.js';
2
2
  export { AgentError, asAgentError } from './errors.js';
3
- export { defineDriver, driverSpecifiers, loadDriverModules } from './drivers.js';
4
3
  export { definitionHash, normalizeDefinition, patchDefinition } from './definition.js';
5
- export { messageText, normalizeMessage } from './messages.js';
6
4
  export type * from './types.js';
7
5
  export { buildCanonicalSkillRoots, classifySkillRoot } from './skills/roots.js';
8
6
  export type { SkillRootClassification, SkillRootOptions } from './skills/roots.js';
@@ -13,3 +11,10 @@ export { configFromAgent, listAgentConfigs, updateAgentConfig } from './config/s
13
11
  export { importAgentConfig } from './config/import.js';
14
12
  export { importNativeConfig } from './config/native.js';
15
13
  export type * from './config/types.js';
14
+ export { createAgentBundle } from './bundles/create.js';
15
+ export type { CreateBundleOptions } from './bundles/create.js';
16
+ export { installAgentBundle } from './bundles/install.js';
17
+ export { buildBundleGraph } from './bundles/graph.js';
18
+ export { validateAgentBundle } from './bundles/validate.js';
19
+ export { BUNDLE_KIND, BUNDLE_SCHEMA_VERSION } from './bundles/util.js';
20
+ export type * from './bundles/types.js';
package/dist/index.js CHANGED
@@ -1,11 +1,14 @@
1
1
  export { Agents } from './agents.js';
2
2
  export { AgentError, asAgentError } from './errors.js';
3
- export { defineDriver, driverSpecifiers, loadDriverModules } from './drivers.js';
4
3
  export { definitionHash, normalizeDefinition, patchDefinition } from './definition.js';
5
- export { messageText, normalizeMessage } from './messages.js';
6
4
  export { buildCanonicalSkillRoots, classifySkillRoot } from './skills/roots.js';
7
5
  export { parseSkillFrontmatter, scanInstalledSkills } from './skills/scanner.js';
8
6
  export { normalizeAgentConfig, stableConfigId } from './config/schema.js';
9
7
  export { configFromAgent, listAgentConfigs, updateAgentConfig } from './config/store.js';
10
8
  export { importAgentConfig } from './config/import.js';
11
9
  export { importNativeConfig } from './config/native.js';
10
+ export { createAgentBundle } from './bundles/create.js';
11
+ export { installAgentBundle } from './bundles/install.js';
12
+ export { buildBundleGraph } from './bundles/graph.js';
13
+ export { validateAgentBundle } from './bundles/validate.js';
14
+ export { BUNDLE_KIND, BUNDLE_SCHEMA_VERSION } from './bundles/util.js';
@@ -41,7 +41,7 @@ export function agentTools(agents) {
41
41
  },
42
42
  {
43
43
  name: 'agents_delete',
44
- description: 'Delete an agent while retaining immutable session history.',
44
+ description: 'Tombstone an agent identity while retaining its immutable revisions.',
45
45
  inputSchema: objectSchema({ agent_id: string }, ['agent_id']),
46
46
  handler(input) {
47
47
  return toolResult({ agent: agents.deleteAgent(stringArg(input, 'agent_id')) });
@@ -16,7 +16,7 @@ export function createMcpServer(options = {}) {
16
16
  return {
17
17
  protocolVersion: message.params?.protocolVersion || '2024-11-05',
18
18
  capabilities: { tools: { listChanged: false } },
19
- serverInfo: { name: 'amalgm-agents', version: '0.1.2' },
19
+ serverInfo: { name: 'amalgm-agents', version: '0.1.3' },
20
20
  };
21
21
  }
22
22
  if (message.method === 'ping')
package/dist/mcp/tools.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { agentTools } from './agent-tools.js';
2
- import { sessionTools } from './session-tools.js';
3
2
  export function createMcpTools(agents) {
4
- return [...agentTools(agents), ...sessionTools(agents)];
3
+ return agentTools(agents);
5
4
  }
package/dist/rows.d.ts CHANGED
@@ -1,7 +1,4 @@
1
- import type { AgentRecord, AgentRevision, AgentSession, AgentTurn, SessionEvent } from './types.js';
1
+ import type { AgentRecord, AgentRevision } from './types.js';
2
2
  export type Row = Record<string, unknown>;
3
3
  export declare function revisionFromRow(row: Row): AgentRevision;
4
4
  export declare function agentFromRow(row: Row): AgentRecord;
5
- export declare function sessionFromRow(row: Row): AgentSession;
6
- export declare function turnFromRow(row: Row): AgentTurn;
7
- export declare function eventFromRow(row: Row): SessionEvent;
package/dist/rows.js CHANGED
@@ -24,42 +24,3 @@ export function agentFromRow(row) {
24
24
  deletedAt: nullable(row.deleted_at),
25
25
  };
26
26
  }
27
- export function sessionFromRow(row) {
28
- return {
29
- id: String(row.id),
30
- agentId: String(row.agent_id),
31
- agentRevisionId: String(row.agent_revision_id),
32
- agentRevision: Number(row.agent_revision_number),
33
- status: String(row.status),
34
- driverSessionId: nullable(row.driver_session_id),
35
- metadata: parseObject(String(row.metadata_json)),
36
- createdAt: String(row.created_at),
37
- updatedAt: String(row.updated_at),
38
- archivedAt: nullable(row.archived_at),
39
- };
40
- }
41
- export function turnFromRow(row) {
42
- return {
43
- id: String(row.id),
44
- sessionId: String(row.session_id),
45
- idempotencyKey: String(row.idempotency_key),
46
- status: String(row.status),
47
- input: JSON.parse(String(row.input_json)),
48
- result: row.result_json ? parseObject(String(row.result_json)) : null,
49
- error: row.error_json ? parseObject(String(row.error_json)) : null,
50
- createdAt: String(row.created_at),
51
- startedAt: nullable(row.started_at),
52
- completedAt: nullable(row.completed_at),
53
- };
54
- }
55
- export function eventFromRow(row) {
56
- return {
57
- id: String(row.id),
58
- sessionId: String(row.session_id),
59
- turnId: nullable(row.turn_id),
60
- sequence: Number(row.sequence),
61
- type: String(row.type),
62
- data: parseObject(String(row.data_json)),
63
- createdAt: String(row.created_at),
64
- };
65
- }
package/dist/schema.js CHANGED
@@ -1,31 +1,56 @@
1
- const SCHEMA_VERSION = 2;
2
- function migrateRevisionHashes(database) {
1
+ const SCHEMA_VERSION = 3;
2
+ const REGISTRY_SCHEMA = `
3
+ CREATE TABLE agents (
4
+ id TEXT PRIMARY KEY,
5
+ current_revision_id TEXT,
6
+ current_revision_number INTEGER NOT NULL DEFAULT 0,
7
+ created_at TEXT NOT NULL,
8
+ updated_at TEXT NOT NULL,
9
+ deleted_at TEXT
10
+ );
11
+
12
+ CREATE TABLE agent_revisions (
13
+ id TEXT PRIMARY KEY,
14
+ agent_id TEXT NOT NULL REFERENCES agents(id),
15
+ revision_number INTEGER NOT NULL,
16
+ definition_hash TEXT NOT NULL,
17
+ definition_json TEXT NOT NULL,
18
+ created_at TEXT NOT NULL,
19
+ UNIQUE(agent_id, revision_number)
20
+ );
21
+
22
+ CREATE INDEX agent_revisions_agent_idx
23
+ ON agent_revisions(agent_id, revision_number DESC);
24
+ `;
25
+ function upgradeRegistry(database, current) {
3
26
  database.pragma('foreign_keys = OFF');
4
27
  try {
28
+ database.exec('BEGIN IMMEDIATE');
29
+ if (current === 1) {
30
+ database.exec(`
31
+ CREATE TABLE agent_revisions_next (
32
+ id TEXT PRIMARY KEY,
33
+ agent_id TEXT NOT NULL REFERENCES agents(id),
34
+ revision_number INTEGER NOT NULL,
35
+ definition_hash TEXT NOT NULL,
36
+ definition_json TEXT NOT NULL,
37
+ created_at TEXT NOT NULL,
38
+ UNIQUE(agent_id, revision_number)
39
+ );
40
+ INSERT INTO agent_revisions_next
41
+ (id, agent_id, revision_number, definition_hash, definition_json, created_at)
42
+ SELECT id, agent_id, revision_number, definition_hash, definition_json, created_at
43
+ FROM agent_revisions;
44
+ DROP TABLE agent_revisions;
45
+ ALTER TABLE agent_revisions_next RENAME TO agent_revisions;
46
+ CREATE INDEX agent_revisions_agent_idx
47
+ ON agent_revisions(agent_id, revision_number DESC);
48
+ `);
49
+ }
5
50
  database.exec(`
6
- BEGIN IMMEDIATE;
7
-
8
- CREATE TABLE agent_revisions_next (
9
- id TEXT PRIMARY KEY,
10
- agent_id TEXT NOT NULL REFERENCES agents(id),
11
- revision_number INTEGER NOT NULL,
12
- definition_hash TEXT NOT NULL,
13
- definition_json TEXT NOT NULL,
14
- created_at TEXT NOT NULL,
15
- UNIQUE(agent_id, revision_number)
16
- );
17
-
18
- INSERT INTO agent_revisions_next
19
- (id, agent_id, revision_number, definition_hash, definition_json, created_at)
20
- SELECT id, agent_id, revision_number, definition_hash, definition_json, created_at
21
- FROM agent_revisions;
22
-
23
- DROP TABLE agent_revisions;
24
- ALTER TABLE agent_revisions_next RENAME TO agent_revisions;
25
-
26
- CREATE INDEX agent_revisions_agent_idx
27
- ON agent_revisions(agent_id, revision_number DESC);
28
-
51
+ DROP TABLE IF EXISTS session_events;
52
+ DROP TABLE IF EXISTS turns;
53
+ DROP TABLE IF EXISTS sessions;
29
54
  PRAGMA user_version = ${SCHEMA_VERSION};
30
55
  COMMIT;
31
56
  `);
@@ -46,82 +71,9 @@ export function migrate(database) {
46
71
  }
47
72
  if (current === SCHEMA_VERSION)
48
73
  return;
49
- if (current === 1) {
50
- migrateRevisionHashes(database);
74
+ if (current > 0) {
75
+ upgradeRegistry(database, current);
51
76
  return;
52
77
  }
53
- database.exec(`
54
- CREATE TABLE agents (
55
- id TEXT PRIMARY KEY,
56
- current_revision_id TEXT,
57
- current_revision_number INTEGER NOT NULL DEFAULT 0,
58
- created_at TEXT NOT NULL,
59
- updated_at TEXT NOT NULL,
60
- deleted_at TEXT
61
- );
62
-
63
- CREATE TABLE agent_revisions (
64
- id TEXT PRIMARY KEY,
65
- agent_id TEXT NOT NULL REFERENCES agents(id),
66
- revision_number INTEGER NOT NULL,
67
- definition_hash TEXT NOT NULL,
68
- definition_json TEXT NOT NULL,
69
- created_at TEXT NOT NULL,
70
- UNIQUE(agent_id, revision_number)
71
- );
72
-
73
- CREATE TABLE sessions (
74
- id TEXT PRIMARY KEY,
75
- agent_id TEXT NOT NULL REFERENCES agents(id),
76
- agent_revision_id TEXT NOT NULL REFERENCES agent_revisions(id),
77
- agent_revision_number INTEGER NOT NULL,
78
- status TEXT NOT NULL CHECK(status IN ('active', 'archived')),
79
- driver_session_id TEXT,
80
- metadata_json TEXT NOT NULL,
81
- created_at TEXT NOT NULL,
82
- updated_at TEXT NOT NULL,
83
- archived_at TEXT
84
- );
85
-
86
- CREATE TABLE turns (
87
- id TEXT PRIMARY KEY,
88
- session_id TEXT NOT NULL REFERENCES sessions(id),
89
- idempotency_key TEXT NOT NULL,
90
- status TEXT NOT NULL CHECK(status IN (
91
- 'queued', 'running', 'cancelling', 'completed', 'failed', 'cancelled', 'interrupted'
92
- )),
93
- input_json TEXT NOT NULL,
94
- result_json TEXT,
95
- error_json TEXT,
96
- created_at TEXT NOT NULL,
97
- started_at TEXT,
98
- completed_at TEXT,
99
- UNIQUE(session_id, idempotency_key)
100
- );
101
-
102
- CREATE TABLE session_events (
103
- id TEXT PRIMARY KEY,
104
- session_id TEXT NOT NULL REFERENCES sessions(id),
105
- turn_id TEXT REFERENCES turns(id),
106
- sequence INTEGER NOT NULL,
107
- type TEXT NOT NULL,
108
- data_json TEXT NOT NULL,
109
- created_at TEXT NOT NULL,
110
- UNIQUE(session_id, sequence)
111
- );
112
-
113
- CREATE INDEX agent_revisions_agent_idx
114
- ON agent_revisions(agent_id, revision_number DESC);
115
- CREATE INDEX sessions_agent_idx
116
- ON sessions(agent_id, updated_at DESC);
117
- CREATE INDEX turns_session_idx
118
- ON turns(session_id, created_at ASC);
119
- CREATE UNIQUE INDEX turns_one_active_per_session_idx
120
- ON turns(session_id)
121
- WHERE status IN ('queued', 'running', 'cancelling');
122
- CREATE INDEX session_events_session_idx
123
- ON session_events(session_id, sequence ASC);
124
-
125
- PRAGMA user_version = ${SCHEMA_VERSION};
126
- `);
78
+ database.exec(`${REGISTRY_SCHEMA}\nPRAGMA user_version = ${SCHEMA_VERSION};`);
127
79
  }
package/dist/types.d.ts CHANGED
@@ -63,114 +63,8 @@ export interface AgentRecord {
63
63
  updatedAt: string;
64
64
  deletedAt: string | null;
65
65
  }
66
- export type SessionStatus = 'active' | 'archived';
67
- export type TurnStatus = 'queued' | 'running' | 'cancelling' | 'completed' | 'failed' | 'cancelled' | 'interrupted';
68
- export interface TextPart {
69
- type: 'text';
70
- text: string;
71
- }
72
- export interface ReferencePart {
73
- type: 'reference';
74
- uri: string;
75
- name: string | null;
76
- mediaType: string | null;
77
- }
78
- export interface DataPart {
79
- type: 'data';
80
- name: string;
81
- data: JsonValue;
82
- }
83
- export type AgentPart = TextPart | ReferencePart | DataPart;
84
- export type MessageRole = 'user' | 'assistant' | 'system';
85
- export interface AgentMessage {
86
- role: MessageRole;
87
- parts: AgentPart[];
88
- }
89
- export interface AgentSession {
90
- id: string;
91
- agentId: string;
92
- agentRevisionId: string;
93
- agentRevision: number;
94
- status: SessionStatus;
95
- driverSessionId: string | null;
96
- metadata: JsonObject;
97
- createdAt: string;
98
- updatedAt: string;
99
- archivedAt: string | null;
100
- }
101
- export interface AgentTurn {
102
- id: string;
103
- sessionId: string;
104
- idempotencyKey: string;
105
- status: TurnStatus;
106
- input: AgentMessage;
107
- result: JsonObject | null;
108
- error: AgentFailure | null;
109
- createdAt: string;
110
- startedAt: string | null;
111
- completedAt: string | null;
112
- }
113
- export interface AgentFailure {
114
- code: string;
115
- message: string;
116
- details: JsonObject;
117
- }
118
- export interface SessionEvent {
119
- id: string;
120
- sessionId: string;
121
- turnId: string | null;
122
- sequence: number;
123
- type: string;
124
- data: JsonObject;
125
- createdAt: string;
126
- }
127
- export interface DriverEvent {
128
- type: string;
129
- data: JsonObject;
130
- }
131
- export interface DriverRunRequest {
132
- agent: AgentRevision;
133
- session: AgentSession;
134
- turn: AgentTurn;
135
- history: AgentMessage[];
136
- input: AgentMessage;
137
- driverSessionId: string | null;
138
- }
139
- export interface DriverRunResult {
140
- message?: AgentMessage;
141
- driverSessionId?: string;
142
- metadata?: JsonObject;
143
- }
144
- export interface DriverRunContext {
145
- signal: AbortSignal;
146
- emit(event: DriverEvent): SessionEvent;
147
- }
148
- export interface AgentDriver {
149
- id: string;
150
- run(request: DriverRunRequest, context: DriverRunContext): Promise<DriverRunResult | void>;
151
- }
152
66
  export interface AgentsOptions {
153
67
  stateDir?: string;
154
68
  databasePath?: string;
155
- drivers?: AgentDriver[];
156
- maxInputBytes?: number;
157
- maxEventBytes?: number;
158
- turnTimeoutMs?: number;
159
69
  now?: () => string;
160
70
  }
161
- export interface StartSessionInput {
162
- agentId: string;
163
- revisionId?: string;
164
- sessionId?: string;
165
- metadata?: JsonObject;
166
- }
167
- export interface SendInput {
168
- message: string | AgentMessage;
169
- idempotencyKey?: string;
170
- }
171
- export interface EnqueuedTurn {
172
- turn: AgentTurn;
173
- completion: Promise<AgentTurn>;
174
- duplicate: boolean;
175
- }
176
- export type EventListener = (event: SessionEvent) => void;
@@ -2,27 +2,22 @@
2
2
 
3
3
  ## Ownership
4
4
 
5
- The Agents service owns four facts:
5
+ The Agents service owns three facts:
6
6
 
7
7
  1. which agent identities exist;
8
- 2. the immutable revisions of each identity;
9
- 3. which revision each session uses; and
10
- 4. the ordered turns and events inside each session.
8
+ 2. the immutable revisions of each identity; and
9
+ 3. which installed agents and Agent Home descriptors are available locally.
11
10
 
12
11
  Everything else crosses an adapter boundary.
13
12
 
14
13
  ```text
15
14
  SDK
16
15
 
17
- CLI ───┐ │ ┌─── REST + SSE
16
+ CLI ───┐ │ ┌─── REST
18
17
  ├── Agents ───┤
19
18
  MCP ───┘ │ └─── Engine adapter
20
19
 
21
- SQLite ledger
22
-
23
- AgentDriver
24
- ┌──────┼──────┐
25
- Codex Claude custom
20
+ SQLite registry
26
21
  ```
27
22
 
28
23
  CLI, MCP, REST, and Engine never write SQLite directly. `Agents` is the
@@ -32,15 +27,17 @@ public service; the stores below it are implementation details.
32
27
 
33
28
  | Product | Owns | Agents keeps |
34
29
  |---|---|---|
35
- | Chat | presentation, titles, participants, read state | no Chat record |
30
+ | Chat | conversations, prepared execution, turns, streams, persistence, reconnect, usage, interrupt | exact agent revision selection |
36
31
  | Tools | tools, actions, drivers, loadouts | opaque tool/action ids |
37
32
  | Skills | skill content and installation | opaque skill ids |
38
33
  | Credentials | secret material and authorization | opaque `authRef` |
39
- | Engine | native harness processes, cloud routing, composition | injected drivers |
40
- | Agents | definitions, revisions, sessions, turns, events | canonical records |
34
+ | Shell | native harness processes, auth, machine effects, exact SDK composition | resolved revision projection |
35
+ | Agents | identities, installations, Agent Home descriptors, immutable revisions | canonical registry records |
41
36
 
42
- An Agents session is executable history. A Chat conversation is a presentation
43
- object. A Chat may point to a session; the reverse dependency is forbidden.
37
+ A Chat conversation is executable history. It names one Agents installation
38
+ and the exact immutable revision used by each prepared execution. Agents never
39
+ imports Chat and Chat never imports the Agents store; Shell composes their
40
+ public capabilities through an explicit resolver.
44
41
 
45
42
  ## Mutation path
46
43
 
@@ -49,25 +46,16 @@ merges a typed patch into the current definition and compares its canonical
49
46
  hash with the current revision. Equal content is idempotent; changed content
50
47
  appends a revision and moves the identity's current pointer.
51
48
 
52
- Deleting an agent sets `deleted_at`. It does not delete revisions or sessions.
49
+ Deleting an agent sets `deleted_at`. It does not delete immutable revisions or
50
+ Chat conversations that already name them.
53
51
  The id cannot be recreated accidentally.
54
52
 
55
- ## Execution path
56
-
57
- 1. A caller starts a session; the current revision id is copied onto it.
58
- 2. A turn and its input event commit in one transaction.
59
- 3. The turn becomes `running` before its driver is invoked.
60
- 4. Driver events commit to the ordered event ledger before subscribers see them.
61
- 5. The driver returns a message, opaque native session id, and metadata.
62
- 6. The turn reaches exactly one terminal state.
63
-
64
- One session serializes turns. Different sessions can execute concurrently.
53
+ ## Resolution path
65
54
 
66
- ## Why drivers are injected
55
+ 1. A caller selects an installed agent identity.
56
+ 2. Agents returns the requested immutable revision, or the current revision
57
+ when no revision was requested.
58
+ 3. Shell projects that revision into Chat's execution-preparation resolver.
59
+ 4. Chat freezes the resolved facts before accepting a turn.
67
60
 
68
- Native agent runtimes have different authentication, installation, process,
69
- streaming, and resume rules. Baking them into storage would couple every user
70
- of the SDK to Engine. `AgentDriver` receives a complete immutable revision and
71
- ordered history, then emits durable events. Engine can reuse its current
72
- chat-core adapters behind this interface; standalone users can provide their
73
- own drivers.
61
+ Agents ends at this resolution result. Chat is the only execution path.
package/docs/CLI.md CHANGED
@@ -3,18 +3,6 @@
3
3
  The CLI prints JSON to stdout and errors to stderr. It shares the SDK database;
4
4
  there is no CLI-specific registry.
5
5
 
6
- ## Global options
7
-
8
- | Option | Meaning |
9
- |---|---|
10
- | `--state-dir <path>` | Override the Agents state directory |
11
- | `--drivers <a.js,b.js>` | Load compiled driver modules |
12
- | `--help` | Print command help |
13
-
14
- `AMALGM_AGENT_DRIVERS` supplies the same comma-separated driver list.
15
-
16
- ## Agent commands
17
-
18
6
  ```bash
19
7
  amalgm-agents agent list [--include-deleted]
20
8
  amalgm-agents agent show <id> [--include-deleted]
@@ -23,39 +11,11 @@ amalgm-agents agent update <id> <patch.json>
23
11
  amalgm-agents agent delete <id>
24
12
  ```
25
13
 
26
- `create` requires an unused id. `update` uses the nested PATCH rules in
27
- [Definitions](./DEFINITIONS.md).
14
+ Global options are `--state-dir <path>` and `--help`.
28
15
 
29
- ## Session commands
30
-
31
- ```bash
32
- amalgm-agents session list [--agent <id>] [--include-archived]
33
- amalgm-agents session start <agent-id> [--id <id>] [--revision <revision-id>]
34
- amalgm-agents session show <id>
35
- amalgm-agents session events <id> [--after <sequence>]
36
- amalgm-agents session send <id> <message> [--key <idempotency-key>]
37
- amalgm-agents session cancel <id>
38
- amalgm-agents session archive <id>
39
- ```
40
-
41
- `session show` returns the session, turns, and event ledger together.
42
-
43
- ## Talk shortcut
44
-
45
- ```bash
46
- amalgm-agents talk <agent-id> <message> \
47
- [--session <session-id>] [--key <idempotency-key>] [--background]
48
- ```
49
-
50
- Without `--session`, the command starts one. Foreground waits for a terminal
51
- turn; background returns the accepted turn immediately.
52
-
53
- ## Servers
16
+ The REST CLI binds loopback by default:
54
17
 
55
18
  ```bash
56
19
  amalgm-agents-rest --host 127.0.0.1 --port 4317 --token "$TOKEN"
57
- amalgm-agents-mcp --state-dir ./state --drivers ./dist/driver.js
20
+ amalgm-agents-mcp --state-dir ./state
58
21
  ```
59
-
60
- The REST CLI binds loopback by default. Use a bearer token before deliberately
61
- binding to any shared interface.