create-bk-agent 0.17.1 → 0.17.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-bk-agent",
3
- "version": "0.17.1",
3
+ "version": "0.17.2",
4
4
  "description": "Create a new BackendKit agent project",
5
5
  "main": "dist/src/index.js",
6
6
  "bin": {
@@ -1,5 +1,7 @@
1
1
  import 'dotenv/config';
2
- import { createAutonomousAgent } from '@backendkit-labs/agent-core';
2
+ import * as os from 'os';
3
+ import * as path from 'path';
4
+ import { createAutonomousAgent, createMemorySystem } from '@backendkit-labs/agent-core';
3
5
  import type { AgentProfile } from '@backendkit-labs/agent-core';
4
6
 
5
7
  // ── Agent definition ──────────────────────────────────────────────────────────
@@ -23,6 +25,18 @@ const apiKey = process.env.ANTHROPIC_API_KEY ?? process.env.OPENAI_API_KEY ??
23
25
 
24
26
  if (!apiKey) { console.error('Missing API key'); process.exit(1); }
25
27
 
28
+ // ── Memory — persists context between trigger executions ──────────────────────
29
+
30
+ const APP_DIR = path.join(os.homedir(), '.my-autonomous-agent');
31
+ const MEM_DIR = path.join(APP_DIR, 'memory');
32
+
33
+ const memory = createMemorySystem({
34
+ episodic: { provider: 'json', path: path.join(MEM_DIR, 'episodes.json') },
35
+ semantic: { provider: 'json', path: path.join(MEM_DIR, 'knowledge.json') },
36
+ procedural: { provider: 'json', path: path.join(MEM_DIR, 'patterns.json') },
37
+ retention: { maxEpisodes: 200 },
38
+ });
39
+
26
40
  // ── Autonomous agent ──────────────────────────────────────────────────────────
27
41
 
28
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -32,6 +46,7 @@ const agent = createAutonomousAgent({
32
46
  agents: [monitorAgent],
33
47
  defaultAgent: 'monitor',
34
48
  goal: 'TODO: describe the agent goal',
49
+ memorySystem: memory,
35
50
 
36
51
  triggers: [
37
52
  // Run every day at 9:00 AM
@@ -45,7 +60,7 @@ const agent = createAutonomousAgent({
45
60
  {
46
61
  type: 'webhook',
47
62
  path: '/events',
48
- // secret: process.env.WEBHOOK_SECRET, // uncomment to validate signatures
63
+ // secret: process.env.WEBHOOK_SECRET,
49
64
  },
50
65
 
51
66
  // TODO: add more triggers as needed
@@ -61,6 +76,7 @@ void (async () => {
61
76
  await agent.start();
62
77
  console.log('Autonomous agent started.');
63
78
  console.log('Webhook listening on port', process.env.WEBHOOK_PORT ?? 3000);
79
+ console.log(`Memory stored in: ${APP_DIR}`);
64
80
 
65
81
  process.on('SIGTERM', async () => { await agent.stop(); process.exit(0); });
66
82
  process.on('SIGINT', async () => { await agent.stop(); process.exit(0); });
@@ -1,9 +1,12 @@
1
+ import * as os from 'os';
2
+ import * as path from 'path';
1
3
  import {
2
4
  AgentEngine,
3
5
  AgentRegistry,
4
6
  ToolRegistry,
5
7
  ProviderRegistry,
6
8
  CallbackTransport,
9
+ createMemorySystem,
7
10
  } from '@backendkit-labs/agent-core';
8
11
  import { OpenAICompatibleProvider } from './providers/openai-compatible';
9
12
  import { loadConfig } from './config';
@@ -12,6 +15,24 @@ import { SPECIALIST_A_PROFILE } from './agents/specialist-a';
12
15
  import { SPECIALIST_B_PROFILE } from './agents/specialist-b';
13
16
  import { exampleAction, exampleQuery } from './tools/example-tools';
14
17
 
18
+ // ── Persistent storage paths ──────────────────────────────────────────────────
19
+ // All state lives in ~/.my-agent/ so it survives restarts.
20
+
21
+ const APP_DIR = path.join(os.homedir(), '.my-agent');
22
+ const HISTORY = path.join(APP_DIR, 'history.json');
23
+ const MEM_DIR = path.join(APP_DIR, 'memory');
24
+
25
+ // ── Memory system ─────────────────────────────────────────────────────────────
26
+ // Three-tier: episodic (past experiences) + semantic (knowledge) + procedural (patterns).
27
+ // buildContextBlock() auto-injects relevant memories into each agent turn.
28
+
29
+ const memory = createMemorySystem({
30
+ episodic: { provider: 'json', path: path.join(MEM_DIR, 'episodes.json') },
31
+ semantic: { provider: 'json', path: path.join(MEM_DIR, 'knowledge.json') },
32
+ procedural: { provider: 'json', path: path.join(MEM_DIR, 'patterns.json') },
33
+ retention: { maxEpisodes: 500 },
34
+ });
35
+
15
36
  export function createEngine(transport: CallbackTransport): AgentEngine {
16
37
  const config = loadConfig();
17
38
 
@@ -19,6 +40,8 @@ export function createEngine(transport: CallbackTransport): AgentEngine {
19
40
  tools
20
41
  .register(exampleAction)
21
42
  .register(exampleQuery);
43
+ // Register memory tools so agents can explicitly save/recall memories
44
+ for (const t of memory.getTools()) tools.register(t);
22
45
  // TODO: register more tools
23
46
 
24
47
  const agents = new AgentRegistry();
@@ -36,7 +59,7 @@ export function createEngine(transport: CallbackTransport): AgentEngine {
36
59
  }));
37
60
 
38
61
  return new AgentEngine({
39
- model: { provider: 'default', id: config.llmModel },
62
+ model: { provider: 'default', id: config.llmModel },
40
63
  agents,
41
64
  tools,
42
65
  providers,
@@ -45,5 +68,10 @@ export function createEngine(transport: CallbackTransport): AgentEngine {
45
68
  transport,
46
69
  maxIterations: 30,
47
70
  iterationMode: 'auto',
71
+ // Conversation history — persists between runs
72
+ historyPath: HISTORY,
73
+ maxContextMessages: 100,
74
+ // Long-term memory — injects relevant context each turn
75
+ memorySystem: memory,
48
76
  });
49
77
  }
@@ -1,15 +1,33 @@
1
+ import * as os from 'os';
2
+ import * as path from 'path';
1
3
  import {
2
4
  AgentEngine,
3
5
  AgentRegistry,
4
6
  ToolRegistry,
5
7
  ProviderRegistry,
6
8
  CallbackTransport,
9
+ createMemorySystem,
7
10
  } from '@backendkit-labs/agent-core';
8
11
  import { OpenAICompatibleProvider } from './providers/openai-compatible';
9
12
  import { loadConfig } from './config';
10
13
  import { MY_AGENT_PROFILE } from './agents/my-agent';
11
14
  import { exampleAction, exampleQuery } from './tools/example-tools';
12
15
 
16
+ // ── Persistent storage paths ──────────────────────────────────────────────────
17
+
18
+ const APP_DIR = path.join(os.homedir(), '.my-agent');
19
+ const HISTORY = path.join(APP_DIR, 'history.json');
20
+ const MEM_DIR = path.join(APP_DIR, 'memory');
21
+
22
+ // ── Memory system ─────────────────────────────────────────────────────────────
23
+
24
+ const memory = createMemorySystem({
25
+ episodic: { provider: 'json', path: path.join(MEM_DIR, 'episodes.json') },
26
+ semantic: { provider: 'json', path: path.join(MEM_DIR, 'knowledge.json') },
27
+ procedural: { provider: 'json', path: path.join(MEM_DIR, 'patterns.json') },
28
+ retention: { maxEpisodes: 500 },
29
+ });
30
+
13
31
  export function createEngine(transport: CallbackTransport): AgentEngine {
14
32
  const config = loadConfig();
15
33
 
@@ -17,6 +35,7 @@ export function createEngine(transport: CallbackTransport): AgentEngine {
17
35
  tools
18
36
  .register(exampleAction)
19
37
  .register(exampleQuery);
38
+ for (const t of memory.getTools()) tools.register(t);
20
39
  // TODO: register more tools
21
40
 
22
41
  const agents = new AgentRegistry();
@@ -31,7 +50,7 @@ export function createEngine(transport: CallbackTransport): AgentEngine {
31
50
  }));
32
51
 
33
52
  return new AgentEngine({
34
- model: { provider: 'default', id: config.llmModel },
53
+ model: { provider: 'default', id: config.llmModel },
35
54
  agents,
36
55
  tools,
37
56
  providers,
@@ -40,5 +59,8 @@ export function createEngine(transport: CallbackTransport): AgentEngine {
40
59
  transport,
41
60
  maxIterations: 20,
42
61
  iterationMode: 'auto',
62
+ historyPath: HISTORY,
63
+ maxContextMessages: 100,
64
+ memorySystem: memory,
43
65
  });
44
66
  }