@autonomaai/agent-core 1.0.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/dist/base-agent.d.ts +112 -0
- package/dist/base-agent.d.ts.map +1 -0
- package/dist/base-agent.js +173 -0
- package/dist/base-agent.js.map +1 -0
- package/dist/core.d.ts +81 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +633 -0
- package/dist/core.js.map +1 -0
- package/dist/error-handler.d.ts +78 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/error-handler.js +129 -0
- package/dist/error-handler.js.map +1 -0
- package/dist/factory.d.ts +60 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +621 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/streaming.d.ts +24 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +36 -0
- package/dist/streaming.js.map +1 -0
- package/dist/trading/formatters.d.ts +167 -0
- package/dist/trading/formatters.d.ts.map +1 -0
- package/dist/trading/formatters.js +271 -0
- package/dist/trading/formatters.js.map +1 -0
- package/dist/trading/index.d.ts +9 -0
- package/dist/trading/index.d.ts.map +1 -0
- package/dist/trading/index.js +10 -0
- package/dist/trading/index.js.map +1 -0
- package/dist/trading/types.d.ts +205 -0
- package/dist/trading/types.d.ts.map +1 -0
- package/dist/trading/types.js +7 -0
- package/dist/trading/types.js.map +1 -0
- package/dist/trading/utils.d.ts +120 -0
- package/dist/trading/utils.d.ts.map +1 -0
- package/dist/trading/utils.js +291 -0
- package/dist/trading/utils.js.map +1 -0
- package/dist/trading/validation.d.ts +40 -0
- package/dist/trading/validation.d.ts.map +1 -0
- package/dist/trading/validation.js +247 -0
- package/dist/trading/validation.js.map +1 -0
- package/dist/types.d.ts +282 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
- package/src/base-agent.ts +263 -0
- package/src/core.ts +792 -0
- package/src/error-handler.ts +166 -0
- package/src/factory.ts +687 -0
- package/src/global.d.ts +12 -0
- package/src/index.ts +24 -0
- package/src/streaming.ts +50 -0
- package/src/trading/formatters.ts +363 -0
- package/src/trading/index.ts +10 -0
- package/src/trading/types.ts +263 -0
- package/src/trading/utils.ts +355 -0
- package/src/trading/validation.ts +321 -0
- package/src/types.ts +402 -0
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autonomaai/agent-core",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Standardized agent core for autonoma AI agents with LangGraph + AgentKit integration",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"dev": "tsc --watch",
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"lint": "eslint src/**/*.ts"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"langchain",
|
|
16
|
+
"langgraph",
|
|
17
|
+
"agentkit",
|
|
18
|
+
"ai-agent",
|
|
19
|
+
"trading",
|
|
20
|
+
"crypto",
|
|
21
|
+
"agent-core"
|
|
22
|
+
],
|
|
23
|
+
"author": "autonoma Team",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@autonomaai/mcp-client": "^1.0.1",
|
|
27
|
+
"@coinbase/agentkit": "^0.3.0",
|
|
28
|
+
"@coinbase/agentkit-langchain": "^0.3.0",
|
|
29
|
+
"@langchain/core": "^0.3.29",
|
|
30
|
+
"@langchain/langgraph": "^0.2.39",
|
|
31
|
+
"@langchain/openai": "^0.6.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/jest": "^29.5.0",
|
|
35
|
+
"@types/node": "^20.0.0",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
37
|
+
"@typescript-eslint/parser": "^6.7.0",
|
|
38
|
+
"eslint": "^8.50.0",
|
|
39
|
+
"jest": "^29.7.0",
|
|
40
|
+
"typescript": "^5.2.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"typescript": ">=4.0.0"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist/**/*",
|
|
47
|
+
"src/**/*",
|
|
48
|
+
"README.md"
|
|
49
|
+
],
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/autonoma/autonoma"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Agent Class
|
|
3
|
+
*
|
|
4
|
+
* Reusable base class for all AI agents in the platform.
|
|
5
|
+
* Provides common functionality: chat, sessions, status, lifecycle management.
|
|
6
|
+
*
|
|
7
|
+
* Each specific agent (ExpenseAnalyzer, MarketMaker, etc.) extends this class
|
|
8
|
+
* and adds domain-specific methods and tools.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { StandardAgent, AgentMessage, AgentResponse, createTradingAgent } from './index.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Logger interface abstraction
|
|
15
|
+
* Decouples from specific logging libraries
|
|
16
|
+
*/
|
|
17
|
+
export interface ILogger {
|
|
18
|
+
info(message: string | object, ...args: any[]): void;
|
|
19
|
+
error(message: string | object, ...args: any[]): void;
|
|
20
|
+
warn(message: string | object, ...args: any[]): void;
|
|
21
|
+
debug(message: string | object, ...args: any[]): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Chat message interface
|
|
26
|
+
*/
|
|
27
|
+
export interface ChatMessage {
|
|
28
|
+
role: 'user' | 'assistant' | 'system';
|
|
29
|
+
content: string;
|
|
30
|
+
timestamp: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Chat session interface
|
|
35
|
+
*/
|
|
36
|
+
export interface ChatSession {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
messages: ChatMessage[];
|
|
39
|
+
metadata?: Record<string, any>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Base agent configuration
|
|
44
|
+
*/
|
|
45
|
+
export interface BaseAgentConfig {
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
systemPrompt: string;
|
|
49
|
+
logger: ILogger;
|
|
50
|
+
llm: {
|
|
51
|
+
model: string;
|
|
52
|
+
temperature: number;
|
|
53
|
+
maxTokens: number;
|
|
54
|
+
openAIApiKey: string;
|
|
55
|
+
};
|
|
56
|
+
memory: {
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
persistentThreadId: boolean;
|
|
59
|
+
maxMessages: number;
|
|
60
|
+
};
|
|
61
|
+
capabilities?: string[];
|
|
62
|
+
enableRAG?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Base Agent Class
|
|
67
|
+
*
|
|
68
|
+
* All agents extend this class and inherit common functionality.
|
|
69
|
+
* Specific agents can override methods or add domain-specific ones.
|
|
70
|
+
*/
|
|
71
|
+
export abstract class BaseAgent {
|
|
72
|
+
protected agent: StandardAgent;
|
|
73
|
+
protected logger: ILogger;
|
|
74
|
+
protected sessions: Map<string, ChatSession>;
|
|
75
|
+
protected startTime: number;
|
|
76
|
+
protected config: BaseAgentConfig;
|
|
77
|
+
|
|
78
|
+
constructor(config: BaseAgentConfig) {
|
|
79
|
+
this.config = config;
|
|
80
|
+
this.logger = config.logger;
|
|
81
|
+
this.sessions = new Map();
|
|
82
|
+
this.startTime = Date.now();
|
|
83
|
+
|
|
84
|
+
// Initialize StandardAgent from agent-core
|
|
85
|
+
this.agent = createTradingAgent({
|
|
86
|
+
name: config.name,
|
|
87
|
+
description: config.description,
|
|
88
|
+
|
|
89
|
+
llm: {
|
|
90
|
+
model: config.llm.model,
|
|
91
|
+
temperature: config.llm.temperature,
|
|
92
|
+
maxTokens: config.llm.maxTokens,
|
|
93
|
+
openAIApiKey: config.llm.openAIApiKey
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
memory: {
|
|
97
|
+
enabled: config.memory.enabled,
|
|
98
|
+
persistentThreadId: config.memory.persistentThreadId,
|
|
99
|
+
maxMessages: config.memory.maxMessages
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
prompt: {
|
|
103
|
+
systemMessage: config.systemPrompt,
|
|
104
|
+
capabilities: (config.capabilities || []) as any, // Allow any string capabilities
|
|
105
|
+
enableConversationMemory: config.memory.enabled
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
services: {
|
|
109
|
+
messageService: true,
|
|
110
|
+
ragService: config.enableRAG || false,
|
|
111
|
+
loggingEnabled: true
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
this.logger.info(`✅ ${config.name} initialized`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Start the agent
|
|
120
|
+
*/
|
|
121
|
+
async start(): Promise<void> {
|
|
122
|
+
try {
|
|
123
|
+
await this.agent.start();
|
|
124
|
+
this.logger.info(`🚀 ${this.config.name} started successfully`);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
this.logger.error(`❌ Failed to start ${this.config.name}:`, error);
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Process a user message and return AI response
|
|
133
|
+
*/
|
|
134
|
+
async chat(
|
|
135
|
+
userMessage: string,
|
|
136
|
+
sessionId: string,
|
|
137
|
+
contextMetadata?: Record<string, any>
|
|
138
|
+
): Promise<AgentResponse> {
|
|
139
|
+
try {
|
|
140
|
+
const startTime = Date.now();
|
|
141
|
+
this.logger.info(
|
|
142
|
+
{ sessionId, contextMetadata },
|
|
143
|
+
`💬 Processing chat message: ${userMessage.substring(0, 100)}...`
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// Get or create session
|
|
147
|
+
let session = this.sessions.get(sessionId);
|
|
148
|
+
if (!session) {
|
|
149
|
+
session = {
|
|
150
|
+
sessionId,
|
|
151
|
+
messages: [],
|
|
152
|
+
metadata: {
|
|
153
|
+
createdAt: new Date().toISOString(),
|
|
154
|
+
...contextMetadata
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
this.sessions.set(sessionId, session);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Add user message to session history
|
|
161
|
+
session.messages.push({
|
|
162
|
+
role: 'user',
|
|
163
|
+
content: userMessage,
|
|
164
|
+
timestamp: new Date().toISOString()
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Process through LangGraph agent
|
|
168
|
+
const agentMessage: AgentMessage = {
|
|
169
|
+
content: userMessage,
|
|
170
|
+
timestamp: new Date().toISOString(),
|
|
171
|
+
role: 'user',
|
|
172
|
+
metadata: {
|
|
173
|
+
sessionId,
|
|
174
|
+
messageCount: session.messages.length,
|
|
175
|
+
...contextMetadata
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const response = await this.agent.process(agentMessage);
|
|
180
|
+
|
|
181
|
+
// Add assistant response to session history
|
|
182
|
+
session.messages.push({
|
|
183
|
+
role: 'assistant',
|
|
184
|
+
content: response.content,
|
|
185
|
+
timestamp: new Date().toISOString()
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Trim history if too long
|
|
189
|
+
if (session.messages.length > this.config.memory.maxMessages) {
|
|
190
|
+
session.messages = session.messages.slice(-this.config.memory.maxMessages);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const processingTime = Date.now() - startTime;
|
|
194
|
+
this.logger.info(
|
|
195
|
+
{ sessionId, processingTime, tokensUsed: response.metrics?.tokensUsed },
|
|
196
|
+
`✅ Chat response generated in ${processingTime}ms`
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
return response;
|
|
200
|
+
|
|
201
|
+
} catch (error) {
|
|
202
|
+
this.logger.error({ sessionId, error }, '❌ Error processing chat message');
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Get session history
|
|
209
|
+
*/
|
|
210
|
+
getSession(sessionId: string): ChatSession | undefined {
|
|
211
|
+
return this.sessions.get(sessionId);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Clear session history
|
|
216
|
+
*/
|
|
217
|
+
clearSession(sessionId: string): void {
|
|
218
|
+
this.sessions.delete(sessionId);
|
|
219
|
+
this.logger.info({ sessionId }, 'Session cleared');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Get all active sessions
|
|
224
|
+
*/
|
|
225
|
+
getActiveSessions(): string[] {
|
|
226
|
+
return Array.from(this.sessions.keys());
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Get agent status
|
|
231
|
+
*/
|
|
232
|
+
getStatus() {
|
|
233
|
+
return {
|
|
234
|
+
name: this.config.name,
|
|
235
|
+
status: 'running',
|
|
236
|
+
uptime: Date.now() - this.startTime,
|
|
237
|
+
activeSessions: this.sessions.size,
|
|
238
|
+
model: this.config.llm.model,
|
|
239
|
+
capabilities: this.config.capabilities || []
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Stop the agent
|
|
245
|
+
*/
|
|
246
|
+
async stop(): Promise<void> {
|
|
247
|
+
try {
|
|
248
|
+
await this.agent.stop();
|
|
249
|
+
this.logger.info(`🛑 ${this.config.name} stopped`);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
this.logger.error('Error stopping agent:', error);
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Get underlying StandardAgent (for advanced use)
|
|
258
|
+
*/
|
|
259
|
+
protected getUnderlyingAgent(): StandardAgent {
|
|
260
|
+
return this.agent;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|