@amalgm/agents 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 (103) hide show
  1. package/PURPOSE.md +45 -0
  2. package/README.md +110 -0
  3. package/dist/agent-store.d.ts +17 -0
  4. package/dist/agent-store.js +111 -0
  5. package/dist/agents.d.ts +39 -0
  6. package/dist/agents.js +129 -0
  7. package/dist/bin/agents.d.ts +2 -0
  8. package/dist/bin/agents.js +5 -0
  9. package/dist/bin/fatal.d.ts +1 -0
  10. package/dist/bin/fatal.js +5 -0
  11. package/dist/bin/mcp.d.ts +2 -0
  12. package/dist/bin/mcp.js +19 -0
  13. package/dist/bin/rest.d.ts +2 -0
  14. package/dist/bin/rest.js +21 -0
  15. package/dist/cli/agent-commands.d.ts +3 -0
  16. package/dist/cli/agent-commands.js +23 -0
  17. package/dist/cli/args.d.ts +7 -0
  18. package/dist/cli/args.js +31 -0
  19. package/dist/cli/files.d.ts +2 -0
  20. package/dist/cli/files.js +21 -0
  21. package/dist/cli/help.d.ts +1 -0
  22. package/dist/cli/help.js +24 -0
  23. package/dist/cli/open.d.ts +3 -0
  24. package/dist/cli/open.js +12 -0
  25. package/dist/cli/run.d.ts +1 -0
  26. package/dist/cli/run.js +38 -0
  27. package/dist/cli/session-commands.d.ts +4 -0
  28. package/dist/cli/session-commands.js +54 -0
  29. package/dist/cli.d.ts +2 -0
  30. package/dist/cli.js +2 -0
  31. package/dist/database.d.ts +9 -0
  32. package/dist/database.js +35 -0
  33. package/dist/definition.d.ts +4 -0
  34. package/dist/definition.js +93 -0
  35. package/dist/drivers.d.ts +4 -0
  36. package/dist/drivers.js +25 -0
  37. package/dist/errors.d.ts +9 -0
  38. package/dist/errors.js +28 -0
  39. package/dist/event-store.d.ts +13 -0
  40. package/dist/event-store.js +50 -0
  41. package/dist/http/agent-routes.d.ts +2 -0
  42. package/dist/http/agent-routes.js +40 -0
  43. package/dist/http/request.d.ts +5 -0
  44. package/dist/http/request.js +40 -0
  45. package/dist/http/server.d.ts +2 -0
  46. package/dist/http/server.js +82 -0
  47. package/dist/http/session-routes.d.ts +2 -0
  48. package/dist/http/session-routes.js +67 -0
  49. package/dist/http/stream.d.ts +3 -0
  50. package/dist/http/stream.js +30 -0
  51. package/dist/http-types.d.ts +23 -0
  52. package/dist/http-types.js +1 -0
  53. package/dist/http.d.ts +2 -0
  54. package/dist/http.js +1 -0
  55. package/dist/ids.d.ts +5 -0
  56. package/dist/ids.js +32 -0
  57. package/dist/index.d.ts +6 -0
  58. package/dist/index.js +5 -0
  59. package/dist/json.d.ts +7 -0
  60. package/dist/json.js +41 -0
  61. package/dist/mcp/agent-tools.d.ts +3 -0
  62. package/dist/mcp/agent-tools.js +51 -0
  63. package/dist/mcp/helpers.d.ts +5 -0
  64. package/dist/mcp/helpers.js +27 -0
  65. package/dist/mcp/server.d.ts +6 -0
  66. package/dist/mcp/server.js +73 -0
  67. package/dist/mcp/session-tools.d.ts +3 -0
  68. package/dist/mcp/session-tools.js +81 -0
  69. package/dist/mcp/tools.d.ts +3 -0
  70. package/dist/mcp/tools.js +5 -0
  71. package/dist/mcp/types.d.ts +18 -0
  72. package/dist/mcp/types.js +1 -0
  73. package/dist/mcp.d.ts +3 -0
  74. package/dist/mcp.js +2 -0
  75. package/dist/messages.d.ts +3 -0
  76. package/dist/messages.js +56 -0
  77. package/dist/rows.d.ts +7 -0
  78. package/dist/rows.js +65 -0
  79. package/dist/runtime.d.ts +29 -0
  80. package/dist/runtime.js +176 -0
  81. package/dist/schema.d.ts +2 -0
  82. package/dist/schema.js +127 -0
  83. package/dist/session-store.d.ts +15 -0
  84. package/dist/session-store.js +83 -0
  85. package/dist/turn-store.d.ts +31 -0
  86. package/dist/turn-store.js +164 -0
  87. package/dist/types.d.ts +176 -0
  88. package/dist/types.js +1 -0
  89. package/docs/ARCHITECTURE.md +73 -0
  90. package/docs/CLI.md +61 -0
  91. package/docs/DATA_MODEL.md +56 -0
  92. package/docs/DEFINITIONS.md +65 -0
  93. package/docs/DRIVERS.md +72 -0
  94. package/docs/ENGINE_INTEGRATION.md +74 -0
  95. package/docs/MCP.md +24 -0
  96. package/docs/REST.md +78 -0
  97. package/docs/SDK.md +72 -0
  98. package/docs/SECURITY.md +38 -0
  99. package/examples/basic.ts +31 -0
  100. package/examples/reviewer.json +25 -0
  101. package/package.json +64 -0
  102. package/skills/amalgm-agents/SKILL.md +30 -0
  103. package/skills/amalgm-agents/agents/openai.yaml +4 -0
package/docs/SDK.md ADDED
@@ -0,0 +1,72 @@
1
+ # SDK reference
2
+
3
+ The `Agents` class is the sole public behavior boundary. All mutations are
4
+ durable before a method returns.
5
+
6
+ ## Construction
7
+
8
+ ```ts
9
+ const agents = new Agents({
10
+ stateDir: './state',
11
+ drivers: [codexDriver],
12
+ maxInputBytes: 256_000,
13
+ maxEventBytes: 256_000,
14
+ turnTimeoutMs: 600_000,
15
+ });
16
+ ```
17
+
18
+ `databasePath` overrides the database location directly. `turnTimeoutMs: 0`
19
+ disables the service timeout. Call `close()` to abort owned executions, wait
20
+ for them to settle, and close SQLite.
21
+
22
+ ## Agent methods
23
+
24
+ | Method | Behavior |
25
+ |---|---|
26
+ | `createAgent(definition)` | Create identity and revision 1; conflicts on any reused id |
27
+ | `updateAgent(id, patch)` | Merge a patch and apply the resulting definition |
28
+ | `deleteAgent(id)` | Tombstone the identity while retaining history |
29
+ | `getAgent(id, includeDeleted?)` | Read the current definition |
30
+ | `listAgents(includeDeleted?)` | List live agents by default |
31
+
32
+ ## Session methods
33
+
34
+ | Method | Behavior |
35
+ |---|---|
36
+ | `startSession(input)` | Pin a new session to the current or named revision |
37
+ | `talk(agentId, input)` | Start or continue a session, then enqueue a turn |
38
+ | `enqueue(sessionId, input)` | Return immediately with the turn and completion promise |
39
+ | `send(sessionId, input)` | Wait for the turn's terminal state |
40
+ | `cancelSession(id)` | Persist cancellation intent and signal its active driver |
41
+ | `archiveSession(id)` | Archive an inactive session |
42
+ | `listSessions(agentId?, includeArchived?)` | Discover durable sessions |
43
+ | `listTurns(sessionId)` | Read accepted inputs and outcomes |
44
+ | `listEvents(sessionId, after?, limit?)` | Read ordered events |
45
+
46
+ `enqueue` returns `{ turn, completion, duplicate }`. If an idempotency key was
47
+ already accepted, `duplicate` is true and the original turn is returned.
48
+
49
+ ## Event subscription
50
+
51
+ ```ts
52
+ const unsubscribe = agents.subscribe(session.id, (event) => {
53
+ console.log(event.sequence, event.type, event.data);
54
+ });
55
+
56
+ await agents.send(session.id, { message: 'Hello' });
57
+ unsubscribe();
58
+ ```
59
+
60
+ Listeners receive events only after commit. To build a reconnectable consumer,
61
+ read `listEvents(after)` before subscribing and de-duplicate by sequence, as
62
+ the packaged SSE adapter does.
63
+
64
+ ## Errors
65
+
66
+ Expected failures use `AgentError` with a stable code:
67
+
68
+ `invalid_input`, `not_found`, `conflict`, `deleted`, `driver_unavailable`,
69
+ `too_large`, or `cancelled`.
70
+
71
+ Driver failures become durable failed turns rather than escaping as transient
72
+ transport errors. Inspect `turn.error` and the session event ledger.
@@ -0,0 +1,38 @@
1
+ # Security model
2
+
3
+ Agents stores executable configuration and conversation history, so its state
4
+ directory should be treated as user-private data.
5
+
6
+ ## Secrets
7
+
8
+ Agent definitions contain `authRef`, not credentials. Drivers resolve that
9
+ reference at execution time through the host's credential boundary. Do not put
10
+ tokens, cookies, private keys, or passwords in `driver.config`, `metadata`,
11
+ messages, or events.
12
+
13
+ ## Capability references
14
+
15
+ Toolbox ids and subagent ids are requests, not authority. The composing host
16
+ must resolve them against the caller's allowed Toolbox view and agent policy.
17
+ Agents never infers permission merely because an id appears in a definition.
18
+
19
+ ## REST exposure
20
+
21
+ The REST CLI binds `127.0.0.1` by default. Configure a bearer token before
22
+ binding to a LAN, container bridge, tunnel, or public interface. The packaged
23
+ server intentionally does not implement browser sessions, CORS, TLS, user
24
+ accounts, or cloud authorization; Engine supplies those outer boundaries.
25
+
26
+ ## Driver trust
27
+
28
+ Drivers execute inside the hosting process and are trusted code. A driver can
29
+ read its process environment and access the filesystem with that process's
30
+ permissions. Load only reviewed modules. Native process drivers should avoid a
31
+ shell, pass explicit arguments, bound output, and kill their child on abort.
32
+
33
+ ## Stored data
34
+
35
+ SQLite files are created beneath a mode-`0700` state directory. Application
36
+ packaging and backups must preserve appropriate filesystem permissions.
37
+ Messages and driver events may contain sensitive user content; retention and
38
+ export policies belong to the embedding product.
@@ -0,0 +1,31 @@
1
+ import { Agents, defineDriver, messageText } from '@amalgm/agents';
2
+
3
+ const echo = defineDriver({
4
+ id: 'echo',
5
+ async run(request) {
6
+ return {
7
+ driverSessionId: request.driverSessionId || `echo-${request.session.id}`,
8
+ message: {
9
+ role: 'assistant',
10
+ parts: [{ type: 'text', text: `Echo: ${messageText(request.input)}` }],
11
+ },
12
+ };
13
+ },
14
+ });
15
+
16
+ async function main(): Promise<void> {
17
+ const agents = new Agents({ stateDir: './example-state', drivers: [echo] });
18
+ agents.createAgent({
19
+ id: 'reviewer',
20
+ name: 'Reviewer',
21
+ driver: 'echo',
22
+ instructions: 'Review carefully.',
23
+ });
24
+
25
+ const call = agents.talk('reviewer', { message: 'Check this design.' });
26
+ console.log(await call.completion);
27
+ console.log(agents.listEvents(call.session.id));
28
+ await agents.close();
29
+ }
30
+
31
+ void main();
@@ -0,0 +1,25 @@
1
+ {
2
+ "id": "reviewer",
3
+ "name": "Reviewer",
4
+ "description": "Reviews implementation work",
5
+ "instructions": "Find correctness risks before style issues.",
6
+ "driver": {
7
+ "id": "echo",
8
+ "config": {}
9
+ },
10
+ "model": null,
11
+ "authRef": null,
12
+ "resources": {
13
+ "files": [],
14
+ "skills": ["code-review"],
15
+ "subagents": []
16
+ },
17
+ "toolbox": {
18
+ "toolIds": ["git"],
19
+ "actionIds": ["git.diff"]
20
+ },
21
+ "workspace": {
22
+ "cwd": null
23
+ },
24
+ "metadata": {}
25
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@amalgm/agents",
3
+ "version": "0.1.0",
4
+ "description": "Local-first agent definitions, immutable revisions, and durable sessions.",
5
+ "license": "UNLICENSED",
6
+ "private": false,
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/amalgm-inc/amalgm-agents.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "./http": {
23
+ "types": "./dist/http.d.ts",
24
+ "default": "./dist/http.js"
25
+ },
26
+ "./mcp": {
27
+ "types": "./dist/mcp.d.ts",
28
+ "default": "./dist/mcp.js"
29
+ }
30
+ },
31
+ "bin": {
32
+ "amalgm-agents": "./dist/bin/agents.js",
33
+ "amalgm-agents-mcp": "./dist/bin/mcp.js",
34
+ "amalgm-agents-rest": "./dist/bin/rest.js"
35
+ },
36
+ "files": [
37
+ "docs",
38
+ "dist",
39
+ "examples",
40
+ "skills",
41
+ "PURPOSE.md",
42
+ "README.md"
43
+ ],
44
+ "scripts": {
45
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && tsx scripts/mark-executables.ts",
46
+ "check": "tsx scripts/check-tree.ts && tsc -p tsconfig.json && tsc -p tsconfig.test.json",
47
+ "test": "tsx --test --test-concurrency=1 --test-timeout=30000 test/*.test.ts",
48
+ "verify": "npm run check && npm run build && npm test",
49
+ "prepack": "npm run build"
50
+ },
51
+ "engines": {
52
+ "node": ">=20"
53
+ },
54
+ "dependencies": {
55
+ "@amalgm/core": "^0.1.0",
56
+ "@types/better-sqlite3": "^7.6.13",
57
+ "@types/node": "^20.19.43",
58
+ "better-sqlite3": "^12.6.2"
59
+ },
60
+ "devDependencies": {
61
+ "tsx": "^4.23.1",
62
+ "typescript": "^5.9.3"
63
+ }
64
+ }
@@ -0,0 +1,30 @@
1
+ ---
2
+ name: amalgm-agents
3
+ description: Create, inspect, edit, delete, and talk to persistent Amalgm agents and their existing sessions. Use when a user wants to manage an agent definition, discover available agents, delegate work to an agent, continue an agent session, or inspect its transcript. Agents are separate from Chat conversations.
4
+ ---
5
+
6
+ # Amalgm Agents
7
+
8
+ Use the available Agents MCP tools. If MCP is unavailable, use the equivalent
9
+ `amalgm-agents` CLI command.
10
+
11
+ ## Manage agents
12
+
13
+ 1. List or inspect before changing an existing agent.
14
+ 2. Create from a complete definition.
15
+ 3. Update only the fields the user requested.
16
+ 4. Delete only when the user explicitly asks.
17
+ 5. Keep tool, skill, file, credential, and subagent values as references; do
18
+ not copy those products into the agent definition.
19
+
20
+ ## Talk to an agent
21
+
22
+ 1. Resolve the agent with `agents_list` or `agents_get` when its identity is
23
+ ambiguous.
24
+ 2. Call `talk_to_agent` without a session ID to start a session.
25
+ 3. Preserve and return the resulting session ID.
26
+ 4. Pass that ID to continue the same session.
27
+ 5. Use conversation/session inspection to recover durable results or history.
28
+ 6. Use background execution for work likely to outlive one MCP request.
29
+
30
+ Never create a Chat conversation merely to represent an Agents session.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Amalgm Agents"
3
+ short_description: "Create, manage, and talk to Amalgm agents"
4
+ default_prompt: "Use $amalgm-agents to create or talk to an agent."