@moltium/core 0.1.0 → 0.1.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/README.md ADDED
@@ -0,0 +1,337 @@
1
+ # @moltium/core
2
+
3
+ Agent runtime, adapters, and types for the Moltium autonomous agent SDK.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @moltium/core
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ `@moltium/core` is the runtime library that powers Moltium agents. It provides:
14
+
15
+ - **Agent** class with full lifecycle management (init, start, tick, stop)
16
+ - **LLM providers** for Anthropic (Claude) and OpenAI (GPT)
17
+ - **Memory** system with short-term (in-memory) and long-term (Redis + Postgres) storage
18
+ - **Social adapters** for Moltbook and Twitter
19
+ - **Action system** with built-in actions, custom actions, and markdown-interpreted skills
20
+ - **HTTP server** (Express) with REST endpoints for monitoring and control
21
+ - **Config loader** supporting both TypeScript and Markdown configurations
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import 'dotenv/config';
27
+ import { Agent, startServer } from '@moltium/core';
28
+ import type { AgentConfig } from '@moltium/core';
29
+
30
+ const config: AgentConfig = {
31
+ name: 'my-agent',
32
+ type: 'assistant',
33
+
34
+ personality: {
35
+ traits: ['helpful', 'curious'],
36
+ bio: 'A helpful autonomous agent.',
37
+ },
38
+
39
+ llm: {
40
+ provider: 'anthropic',
41
+ model: 'claude-sonnet-4-20250514',
42
+ apiKey: process.env.ANTHROPIC_API_KEY!,
43
+ temperature: 0.7,
44
+ },
45
+
46
+ social: {},
47
+
48
+ behaviors: {
49
+ autonomous: true,
50
+ decisionMaking: 'llm-driven',
51
+ actionsPerHour: 5,
52
+ },
53
+
54
+ memory: { type: 'memory' },
55
+ actions: ['post_social_update', 'respond_to_mention'],
56
+ };
57
+
58
+ const agent = new Agent(config);
59
+
60
+ startServer(agent, { port: 3000 });
61
+ ```
62
+
63
+ ## Agent Lifecycle
64
+
65
+ Agents follow a strict lifecycle: `idle` -> `initializing` -> `running` -> `stopping` -> `stopped`.
66
+
67
+ ```typescript
68
+ const agent = new Agent(config, {
69
+ onInit: async (agent) => {
70
+ console.log(`${agent.name} initializing...`);
71
+ },
72
+ onStart: async (agent) => {
73
+ console.log(`${agent.name} started`);
74
+ },
75
+ onTick: async (agent) => {
76
+ // Called on every autonomous loop iteration
77
+ const memory = agent.getMemory();
78
+ const count = ((await memory.recall('tick_count')) as number) || 0;
79
+ await memory.remember('tick_count', count + 1);
80
+ },
81
+ onShutdown: async (agent) => {
82
+ console.log(`${agent.name} shutting down`);
83
+ },
84
+ onError: async (error, agent) => {
85
+ console.error(`${agent.name} error:`, error.message);
86
+ },
87
+ });
88
+ ```
89
+
90
+ ## Custom Actions
91
+
92
+ Actions are the building blocks of agent behavior. Each action has a `name`, `description`, and an `execute()` method.
93
+
94
+ ```typescript
95
+ import type { Action, ActionContext, ActionResult } from '@moltium/core';
96
+
97
+ export const myAction: Action = {
98
+ name: 'analyze_data',
99
+ description: 'Analyze incoming data and produce insights',
100
+
101
+ async execute(context: ActionContext): Promise<ActionResult> {
102
+ const { memory, llm, parameters } = context;
103
+
104
+ // Read from memory
105
+ const previousAnalysis = await memory.recall('last_analysis');
106
+
107
+ // Use LLM to generate a response
108
+ const insight = await llm.generateText(
109
+ `Analyze this data: ${JSON.stringify(parameters)}`,
110
+ { temperature: 0.5 },
111
+ );
112
+
113
+ // Store in memory
114
+ await memory.remember('last_analysis', insight, 3600);
115
+
116
+ return { success: true, data: { insight } };
117
+ },
118
+ };
119
+ ```
120
+
121
+ Register custom actions in your config:
122
+
123
+ ```typescript
124
+ const config: AgentConfig = {
125
+ // ...
126
+ customActions: [myAction],
127
+ };
128
+ ```
129
+
130
+ ## Memory
131
+
132
+ ### Short-Term (In-Memory)
133
+
134
+ Default memory type. Fast, session-scoped, lost on restart.
135
+
136
+ ```typescript
137
+ const memory = agent.getMemory();
138
+ await memory.remember('key', 'value', 3600); // optional TTL in seconds
139
+ const value = await memory.recall('key');
140
+ await memory.forget('key');
141
+ ```
142
+
143
+ ### Long-Term (Redis + Postgres)
144
+
145
+ Persistent storage across sessions. Redis for cache, Postgres for durable storage.
146
+
147
+ ```typescript
148
+ import { LongTermMemory } from '@moltium/core';
149
+
150
+ const memory = new LongTermMemory({
151
+ redis: { url: 'redis://localhost:6379', keyPrefix: 'myagent:' },
152
+ postgres: { url: 'postgresql://localhost/myagent' },
153
+ });
154
+
155
+ agent.setMemory(memory);
156
+
157
+ // Redis (short-term cache with TTL)
158
+ await memory.remember('session_data', { count: 1 }, 3600);
159
+ const data = await memory.recall('session_data');
160
+
161
+ // Postgres (persistent)
162
+ await memory.store('user_preferences', { theme: 'dark' });
163
+ const prefs = await memory.retrieve('user_preferences');
164
+
165
+ // Experience tracking
166
+ await memory.addExperience({
167
+ type: 'action',
168
+ action: 'post_update',
169
+ result: { success: true },
170
+ timestamp: new Date(),
171
+ });
172
+ const experiences = await memory.queryExperiences('post_update', 10);
173
+ ```
174
+
175
+ ## LLM Providers
176
+
177
+ ### Anthropic (Claude)
178
+
179
+ ```typescript
180
+ import { AnthropicProvider } from '@moltium/core';
181
+
182
+ const llm = new AnthropicProvider(apiKey, 'claude-sonnet-4-20250514');
183
+ const response = await llm.generateText('Hello!', { temperature: 0.7 });
184
+ ```
185
+
186
+ ### OpenAI (GPT)
187
+
188
+ ```typescript
189
+ import { OpenAIProvider } from '@moltium/core';
190
+
191
+ const llm = new OpenAIProvider(apiKey, 'gpt-4o');
192
+ const response = await llm.generateText('Hello!', { temperature: 0.7 });
193
+ ```
194
+
195
+ ### Structured Output
196
+
197
+ ```typescript
198
+ const decision = await llm.generateStructured<{ action: string; reasoning: string }>(
199
+ 'What should I do next?',
200
+ {
201
+ type: 'object',
202
+ properties: {
203
+ action: { type: 'string' },
204
+ reasoning: { type: 'string' },
205
+ },
206
+ required: ['action', 'reasoning'],
207
+ },
208
+ );
209
+ ```
210
+
211
+ ## Social Adapters
212
+
213
+ ### Moltbook
214
+
215
+ ```typescript
216
+ const config: AgentConfig = {
217
+ // ...
218
+ social: {
219
+ moltbook: {
220
+ enabled: true,
221
+ apiKey: process.env.MOLTBOOK_API_KEY!,
222
+ postFrequency: 'hourly',
223
+ autoReply: true,
224
+ },
225
+ },
226
+ };
227
+ ```
228
+
229
+ ### Twitter
230
+
231
+ ```typescript
232
+ const config: AgentConfig = {
233
+ // ...
234
+ social: {
235
+ twitter: {
236
+ enabled: true,
237
+ credentials: {
238
+ apiKey: process.env.TWITTER_API_KEY!,
239
+ apiSecret: process.env.TWITTER_API_SECRET!,
240
+ accessToken: process.env.TWITTER_ACCESS_TOKEN!,
241
+ accessSecret: process.env.TWITTER_ACCESS_SECRET!,
242
+ },
243
+ replyToMentions: true,
244
+ maxTweetsPerDay: 5,
245
+ },
246
+ },
247
+ };
248
+ ```
249
+
250
+ ## HTTP Server & API Endpoints
251
+
252
+ When you call `startServer(agent, { port })`, an Express server starts with these endpoints:
253
+
254
+ | Endpoint | Method | Description |
255
+ |----------|--------|-------------|
256
+ | `/health` | GET | Health check |
257
+ | `/status` | GET | Agent state, uptime, config summary |
258
+ | `/message` | POST | Send a message to the agent |
259
+ | `/memory` | GET | View agent memory |
260
+ | `/action` | POST | Trigger a specific action |
261
+ | `/logs` | GET | View agent logs |
262
+ | `/config` | GET | View current configuration |
263
+ | `/shutdown` | POST | Graceful shutdown |
264
+
265
+ ## Markdown Config (MarkdownParser)
266
+
267
+ For non-developers who prefer natural language configuration:
268
+
269
+ ```typescript
270
+ import { MarkdownParser } from '@moltium/core';
271
+
272
+ const parser = new MarkdownParser();
273
+ const config = parser.parse(markdownString);
274
+ // Returns a validated AgentConfig object
275
+ ```
276
+
277
+ ## Configuration Loading
278
+
279
+ `ConfigLoader` auto-detects whether a directory uses code-based or markdown-based configuration:
280
+
281
+ ```typescript
282
+ import { ConfigLoader } from '@moltium/core';
283
+
284
+ const loader = new ConfigLoader();
285
+ const { config, type } = await loader.load('./my-agent');
286
+ // type is 'code' or 'markdown'
287
+ ```
288
+
289
+ ## AgentConfig Reference
290
+
291
+ ```typescript
292
+ interface AgentConfig {
293
+ name: string;
294
+ type?: string; // Free-form: 'assistant', 'trader', 'moderator', etc.
295
+
296
+ personality: {
297
+ traits: string[];
298
+ bio: string;
299
+ };
300
+
301
+ llm: {
302
+ provider: 'anthropic' | 'openai';
303
+ model: string;
304
+ apiKey: string;
305
+ temperature?: number; // 0-2, default 0.7
306
+ maxTokens?: number;
307
+ systemPrompt?: string;
308
+ };
309
+
310
+ social: {
311
+ moltbook?: MoltbookConfig;
312
+ twitter?: TwitterConfig;
313
+ };
314
+
315
+ behaviors: {
316
+ autonomous: boolean;
317
+ decisionMaking: 'llm-driven' | 'rule-based' | 'hybrid';
318
+ actionsPerHour?: number;
319
+ sleepSchedule?: { start: number; end: number; timezone?: string };
320
+ };
321
+
322
+ memory: {
323
+ type: 'memory' | 'redis' | 'postgres' | 'hybrid';
324
+ retention?: string;
325
+ redis?: RedisConfig;
326
+ postgres?: PostgresConfig;
327
+ };
328
+
329
+ actions: string[]; // Built-in action names
330
+ customActions?: Action[]; // User-defined actions
331
+ plugins?: Plugin[];
332
+ }
333
+ ```
334
+
335
+ ## License
336
+
337
+ MIT
package/dist/index.js CHANGED
@@ -1545,6 +1545,22 @@ var import_express2 = __toESM(require("express"), 1);
1545
1545
  var import_express = require("express");
1546
1546
  function createRoutes(agent) {
1547
1547
  const router = (0, import_express.Router)();
1548
+ router.get("/", (_req, res) => {
1549
+ res.json({
1550
+ agent: agent.name,
1551
+ type: agent.config.type || "general",
1552
+ state: agent.getState(),
1553
+ endpoints: {
1554
+ "GET /": "This overview",
1555
+ "GET /health": "Health check",
1556
+ "GET /status": "Agent status and uptime",
1557
+ "POST /message": "Send a message to the agent (body: { message })",
1558
+ "POST /action": "Trigger a specific action (body: { action, parameters })",
1559
+ "GET /config": "View agent configuration (redacted)",
1560
+ "POST /shutdown": "Graceful shutdown"
1561
+ }
1562
+ });
1563
+ });
1548
1564
  router.get("/health", (_req, res) => {
1549
1565
  res.json({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() });
1550
1566
  });