@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.
Files changed (62) hide show
  1. package/dist/base-agent.d.ts +112 -0
  2. package/dist/base-agent.d.ts.map +1 -0
  3. package/dist/base-agent.js +173 -0
  4. package/dist/base-agent.js.map +1 -0
  5. package/dist/core.d.ts +81 -0
  6. package/dist/core.d.ts.map +1 -0
  7. package/dist/core.js +633 -0
  8. package/dist/core.js.map +1 -0
  9. package/dist/error-handler.d.ts +78 -0
  10. package/dist/error-handler.d.ts.map +1 -0
  11. package/dist/error-handler.js +129 -0
  12. package/dist/error-handler.js.map +1 -0
  13. package/dist/factory.d.ts +60 -0
  14. package/dist/factory.d.ts.map +1 -0
  15. package/dist/factory.js +621 -0
  16. package/dist/factory.js.map +1 -0
  17. package/dist/index.d.ts +13 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +19 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/streaming.d.ts +24 -0
  22. package/dist/streaming.d.ts.map +1 -0
  23. package/dist/streaming.js +36 -0
  24. package/dist/streaming.js.map +1 -0
  25. package/dist/trading/formatters.d.ts +167 -0
  26. package/dist/trading/formatters.d.ts.map +1 -0
  27. package/dist/trading/formatters.js +271 -0
  28. package/dist/trading/formatters.js.map +1 -0
  29. package/dist/trading/index.d.ts +9 -0
  30. package/dist/trading/index.d.ts.map +1 -0
  31. package/dist/trading/index.js +10 -0
  32. package/dist/trading/index.js.map +1 -0
  33. package/dist/trading/types.d.ts +205 -0
  34. package/dist/trading/types.d.ts.map +1 -0
  35. package/dist/trading/types.js +7 -0
  36. package/dist/trading/types.js.map +1 -0
  37. package/dist/trading/utils.d.ts +120 -0
  38. package/dist/trading/utils.d.ts.map +1 -0
  39. package/dist/trading/utils.js +291 -0
  40. package/dist/trading/utils.js.map +1 -0
  41. package/dist/trading/validation.d.ts +40 -0
  42. package/dist/trading/validation.d.ts.map +1 -0
  43. package/dist/trading/validation.js +247 -0
  44. package/dist/trading/validation.js.map +1 -0
  45. package/dist/types.d.ts +282 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js +21 -0
  48. package/dist/types.js.map +1 -0
  49. package/package.json +57 -0
  50. package/src/base-agent.ts +263 -0
  51. package/src/core.ts +792 -0
  52. package/src/error-handler.ts +166 -0
  53. package/src/factory.ts +687 -0
  54. package/src/global.d.ts +12 -0
  55. package/src/index.ts +24 -0
  56. package/src/streaming.ts +50 -0
  57. package/src/trading/formatters.ts +363 -0
  58. package/src/trading/index.ts +10 -0
  59. package/src/trading/types.ts +263 -0
  60. package/src/trading/utils.ts +355 -0
  61. package/src/trading/validation.ts +321 -0
  62. package/src/types.ts +402 -0
package/src/types.ts ADDED
@@ -0,0 +1,402 @@
1
+ /**
2
+ * Type definitions for the autonoma Agent Core library.
3
+ *
4
+ * Provides standardized interfaces for AI agents across the ecosystem.
5
+ */
6
+
7
+ // Import types - these will be resolved when the package is used
8
+ // with the proper dependencies installed
9
+ export type Tool = any; // from "@langchain/core/tools"
10
+ export type BaseChatModel = any; // from "@langchain/core/language_models/chat_models"
11
+ export type MemorySaver = any; // from "@langchain/langgraph"
12
+ export type ReactAgent = any; // from "@langchain/langgraph/prebuilt"
13
+ export type AgentKit = any; // from "@coinbase/agentkit"
14
+ export type WalletProvider = any; // from "@coinbase/agentkit"
15
+
16
+ // =============================================================================
17
+ // Agent Configuration Types
18
+ // =============================================================================
19
+
20
+ // Agent types for autonoma trading platform
21
+ export interface AgentConfig {
22
+ name: string;
23
+ description?: string;
24
+ llm?: {
25
+ model?: string;
26
+ temperature?: number;
27
+ maxTokens?: number;
28
+ openAIApiKey?: string;
29
+ };
30
+ agentKit?: {
31
+ cdpApiKeyId?: string;
32
+ cdpApiKeySecret?: string;
33
+ networkId?: string;
34
+ walletDataFile?: string;
35
+ };
36
+ tools?: {
37
+ enableMCP?: boolean;
38
+ enableRAG?: boolean;
39
+ enableAgentKit?: boolean;
40
+ mcpServerUrl?: string;
41
+ ragServerUrl?: string;
42
+ customTools?: any[];
43
+ };
44
+ prompt?: {
45
+ systemMessage?: string;
46
+ capabilities?: string[];
47
+ context?: string;
48
+ instructions?: string;
49
+ enableConversationMemory?: boolean;
50
+ };
51
+ memory?: {
52
+ enabled?: boolean;
53
+ persistentThreadId?: boolean;
54
+ maxMessages?: number;
55
+ };
56
+ services?: {
57
+ messageService?: boolean | MessageService;
58
+ ragService?: boolean | RAGService;
59
+ analyticsService?: boolean;
60
+ loggingEnabled?: boolean;
61
+ };
62
+ }
63
+
64
+ export interface TradingAgentConfig extends AgentConfig {
65
+ prompt?: AgentConfig['prompt'] & {
66
+ capabilities?: (
67
+ | 'question_answering'
68
+ | 'knowledge_base_search'
69
+ | 'issue_escalation'
70
+ | 'conversation_management'
71
+ | 'sentiment_analysis'
72
+ | 'market_making'
73
+ | 'exchange_connectivity'
74
+ | 'real_time_analytics'
75
+ | 'risk_management'
76
+ | 'automated_trading'
77
+ | 'performance_monitoring'
78
+ | 'defi_yield_optimization'
79
+ | 'multi_chain_analysis'
80
+ | 'apy_strategy_development'
81
+ | 'portfolio_optimization'
82
+ | 'liquidity_provision'
83
+ | 'yield_farming'
84
+ | 'protocol_analysis'
85
+ | 'viral_detection'
86
+ | 'memecoin_analysis'
87
+ | 'social_sentiment'
88
+ | 'trend_analysis'
89
+ )[];
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Enhanced agent environment interface supporting agent-specific API keys
95
+ * with fallback to global keys for backward compatibility
96
+ */
97
+ export interface AgentEnvironment {
98
+ // Global API Keys (fallback)
99
+ OPENAI_API_KEY?: string;
100
+ OPENAI_MODEL?: string;
101
+ OPENAI_MAX_TOKENS?: string;
102
+ CDP_API_KEY_ID?: string;
103
+ CDP_API_KEY_SECRET?: string;
104
+ NETWORK_ID?: string;
105
+
106
+ // Portfolio Manager Agent API Keys
107
+ PORTFOLIO_MANAGER_OPENAI_API_KEY?: string;
108
+ PORTFOLIO_MANAGER_CDP_API_KEY_ID?: string;
109
+ PORTFOLIO_MANAGER_CDP_API_KEY_SECRET?: string;
110
+ PORTFOLIO_MANAGER_NETWORK_ID?: string;
111
+ PORTFOLIO_MANAGER_OPENAI_MODEL?: string;
112
+ PORTFOLIO_MANAGER_MAX_TOKENS?: string;
113
+
114
+ // Market Maker Agent API Keys
115
+ MARKET_MAKER_OPENAI_API_KEY?: string;
116
+ MARKET_MAKER_CDP_API_KEY_ID?: string;
117
+ MARKET_MAKER_CDP_API_KEY_SECRET?: string;
118
+ MARKET_MAKER_NETWORK_ID?: string;
119
+ MARKET_MAKER_OPENAI_MODEL?: string;
120
+ MARKET_MAKER_MAX_TOKENS?: string;
121
+
122
+ // Memecoin Agent API Keys
123
+ MEMECOIN_OPENAI_API_KEY?: string;
124
+ MEMECOIN_CDP_API_KEY_ID?: string;
125
+ MEMECOIN_CDP_API_KEY_SECRET?: string;
126
+ MEMECOIN_NETWORK_ID?: string;
127
+ MEMECOIN_OPENAI_MODEL?: string;
128
+ MEMECOIN_MAX_TOKENS?: string;
129
+
130
+ // APY Yields Agent API Keys
131
+ APY_OPENAI_API_KEY?: string;
132
+ APY_CDP_API_KEY_ID?: string;
133
+ APY_CDP_API_KEY_SECRET?: string;
134
+ APY_NETWORK_ID?: string;
135
+ APY_OPENAI_MODEL?: string;
136
+ APY_MAX_TOKENS?: string;
137
+
138
+ // Service URLs
139
+ MCP_SERVER_URL?: string;
140
+ RAG_SERVER_URL?: string;
141
+ NODE_ENV?: string;
142
+ }
143
+
144
+ /**
145
+ * Utility function to get agent-specific environment variables with fallback
146
+ */
147
+ export function getAgentEnvironment(
148
+ agentType: 'portfolio-manager' | 'market-maker' | 'memecoin' | 'apy'
149
+ ): {
150
+ openaiApiKey: string | undefined;
151
+ cdpApiKeyId: string | undefined;
152
+ cdpApiKeySecret: string | undefined;
153
+ networkId: string;
154
+ openaiModel: string;
155
+ maxTokens: number;
156
+ } {
157
+ const env = process.env as AgentEnvironment;
158
+
159
+ const agentPrefix = agentType.toUpperCase().replace('-', '_');
160
+
161
+ return {
162
+ openaiApiKey: env[`${agentPrefix}_OPENAI_API_KEY` as keyof AgentEnvironment] || env.OPENAI_API_KEY,
163
+ cdpApiKeyId: env[`${agentPrefix}_CDP_API_KEY_ID` as keyof AgentEnvironment] || env.CDP_API_KEY_ID,
164
+ cdpApiKeySecret: env[`${agentPrefix}_CDP_API_KEY_SECRET` as keyof AgentEnvironment] || env.CDP_API_KEY_SECRET,
165
+ networkId: env[`${agentPrefix}_NETWORK_ID` as keyof AgentEnvironment] || env.NETWORK_ID || 'base-sepolia',
166
+ openaiModel: env[`${agentPrefix}_OPENAI_MODEL` as keyof AgentEnvironment] || env.OPENAI_MODEL || 'gpt-4o-mini',
167
+ maxTokens: parseInt(env[`${agentPrefix}_MAX_TOKENS` as keyof AgentEnvironment] || env.OPENAI_MAX_TOKENS || '2000', 10)
168
+ };
169
+ }
170
+
171
+ // =============================================================================
172
+ // Agent Interface Types
173
+ // =============================================================================
174
+
175
+ export interface autonomaAgent {
176
+ id: string;
177
+ name: string;
178
+ description?: string;
179
+ capabilities: string[];
180
+ tools: Tool[];
181
+ config: AgentConfig;
182
+
183
+ // Core methods
184
+ start(): Promise<void>;
185
+ stop(): Promise<void>;
186
+ process(message: AgentMessage): Promise<AgentResponse>;
187
+
188
+ // Configuration methods
189
+ updateConfig(config: Partial<AgentConfig>): Promise<void>;
190
+ addTool(tool: Tool): Promise<void>;
191
+ removeTool(toolName: string): Promise<void>;
192
+
193
+ // State methods
194
+ getStatus(): AgentStatus;
195
+ getMetrics(): AgentMetrics;
196
+
197
+ // Memory methods
198
+ clearMemory(): Promise<void>;
199
+ getConversationHistory(limit?: number): Promise<AgentMessage[]>;
200
+ }
201
+
202
+ export interface AgentMessage {
203
+ role: 'user' | 'assistant' | 'system';
204
+ content: string;
205
+ timestamp?: string;
206
+ metadata?: Record<string, any>;
207
+ }
208
+
209
+ export interface AgentResponse {
210
+ content: string;
211
+ timestamp: string;
212
+ toolCalls?: ToolCall[];
213
+ metrics?: {
214
+ processingTime: number;
215
+ tokensUsed: number;
216
+ toolsUsed: string[];
217
+ };
218
+ error?: string;
219
+ }
220
+
221
+ export interface ToolCall {
222
+ tool: string;
223
+ input: any;
224
+ output: any;
225
+ duration: number;
226
+ success: boolean;
227
+ error?: string;
228
+ }
229
+
230
+ export interface AgentStatus {
231
+ status: 'idle' | 'processing' | 'error' | 'stopped';
232
+ uptime: number;
233
+ lastActivity: string;
234
+ activeTools: string[];
235
+ memoryUsage?: {
236
+ conversationMessages: number;
237
+ totalMemoryMB: number;
238
+ };
239
+ }
240
+
241
+ export interface AgentMetrics {
242
+ totalMessages: number;
243
+ totalToolCalls: number;
244
+ averageResponseTime: number;
245
+ successRate: number;
246
+ topTools: Array<{ tool: string; count: number }>;
247
+ errorCount: number;
248
+ uptime: number;
249
+ }
250
+
251
+ // =============================================================================
252
+ // Service Interface Types
253
+ // =============================================================================
254
+
255
+ export interface MessageService {
256
+ saveMessage(message: AgentMessage): Promise<void>;
257
+ getRecentMessages(limit: number): Promise<AgentMessage[]>;
258
+ getConversationStats(): Promise<{
259
+ totalMessages: number;
260
+ userMessages: number;
261
+ assistantMessages: number;
262
+ }>;
263
+ clearHistory(): Promise<void>;
264
+ }
265
+
266
+ export interface RAGService {
267
+ search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
268
+ getContext(query: string): Promise<string>;
269
+ addDocument(document: Document): Promise<void>;
270
+ getStatus(): Promise<{ available: boolean; documentCount: number }>;
271
+ }
272
+
273
+ export interface SearchOptions {
274
+ limit?: number;
275
+ category?: string;
276
+ threshold?: number;
277
+ }
278
+
279
+ export interface SearchResult {
280
+ content: string;
281
+ metadata: Record<string, any>;
282
+ score: number;
283
+ }
284
+
285
+ export interface Document {
286
+ id: string;
287
+ content: string;
288
+ metadata: Record<string, any>;
289
+ }
290
+
291
+ // =============================================================================
292
+ // Agent Builder Types
293
+ // =============================================================================
294
+
295
+ export interface AgentBuilder {
296
+ setName(name: string): AgentBuilder;
297
+ setDescription(description: string): AgentBuilder;
298
+ setLLM(config: AgentConfig['llm']): AgentBuilder;
299
+ setAgentKit(config: AgentConfig['agentKit']): AgentBuilder;
300
+ setTools(config: AgentConfig['tools']): AgentBuilder;
301
+ setPrompt(config: AgentConfig['prompt']): AgentBuilder;
302
+ setMemory(config: AgentConfig['memory']): AgentBuilder;
303
+ setServices(config: AgentConfig['services']): AgentBuilder;
304
+ addCustomTool(tool: Tool): AgentBuilder;
305
+ build(): Promise<autonomaAgent>;
306
+ }
307
+
308
+ // =============================================================================
309
+ // LangGraph Integration Types
310
+ // =============================================================================
311
+
312
+ export type LangGraphAgent = ReactAgent;
313
+
314
+ export interface LangGraphConfig {
315
+ llm: BaseChatModel;
316
+ tools: Tool[];
317
+ checkpointSaver?: MemorySaver;
318
+ messageModifier?: string;
319
+ }
320
+
321
+ // =============================================================================
322
+ // AgentKit Integration Types
323
+ // =============================================================================
324
+
325
+ export interface AgentKitConfig {
326
+ agentKit: AgentKit;
327
+ walletProvider: WalletProvider;
328
+ networkId: string;
329
+ }
330
+
331
+ // =============================================================================
332
+ // Factory Function Types
333
+ // =============================================================================
334
+
335
+ export interface DataAnalysisAgentConfig extends AgentConfig {
336
+ analysis?: {
337
+ dataSources?: string[];
338
+ updateFrequency?: number;
339
+ analysisTypes?: string[];
340
+ };
341
+ }
342
+
343
+ export interface CustomerServiceAgentConfig extends AgentConfig {
344
+ customerService?: {
345
+ knowledgeBase?: string;
346
+ escalationRules?: Record<string, any>;
347
+ supportedLanguages?: string[];
348
+ };
349
+ }
350
+
351
+ export interface DeFiYieldAgentConfig extends AgentConfig {
352
+ // DeFi-specific configuration
353
+ defiConfig?: {
354
+ // Risk management parameters
355
+ maxProtocolAllocation?: number; // Maximum allocation per protocol (default: 0.25)
356
+ maxPortfolioRisk?: number; // Maximum portfolio VaR (default: 0.15)
357
+ minLiquidityThreshold?: number; // Minimum liquidity requirement (default: 1000000)
358
+ maxRiskScore?: number; // Maximum protocol risk score (default: 70)
359
+
360
+ // Optimization settings
361
+ optimizationStrategy?: 'max_sharpe' | 'risk_parity' | 'mean_variance';
362
+ rebalancingThreshold?: number; // Portfolio drift threshold (default: 0.02)
363
+ rebalancingFrequency?: 'daily' | 'weekly' | 'monthly';
364
+
365
+ // Chain preferences
366
+ supportedChains?: string[]; // Supported blockchain networks
367
+ preferredChains?: string[]; // Preferred chains for optimization
368
+
369
+ // Protocol filters
370
+ whitelistedProtocols?: string[]; // Approved protocols only
371
+ blacklistedProtocols?: string[]; // Excluded protocols
372
+ minProtocolTVL?: number; // Minimum protocol TVL
373
+ minAuditScore?: number; // Minimum audit score requirement
374
+
375
+ // Transaction settings
376
+ maxGasCost?: number; // Maximum acceptable gas cost
377
+ slippageTolerance?: number; // Maximum slippage tolerance
378
+ mevProtection?: boolean; // Enable MEV protection
379
+
380
+ // Performance settings
381
+ benchmarkStrategy?: string; // Benchmark for performance comparison
382
+ performanceReportingFrequency?: 'daily' | 'weekly' | 'monthly';
383
+ enableRealTimeAlerts?: boolean; // Enable real-time performance alerts
384
+ };
385
+
386
+ // RAG configuration for DeFi knowledge
387
+ ragConfig?: {
388
+ serverUrl?: string;
389
+ enableHistoricalDecisions?: boolean;
390
+ enableProtocolKnowledge?: boolean;
391
+ enableRiskAnalysis?: boolean;
392
+ knowledgeUpdateFrequency?: 'hourly' | 'daily' | 'weekly';
393
+ };
394
+
395
+ // Integration settings
396
+ orchestratorConfig?: {
397
+ url?: string;
398
+ enableCoordination?: boolean;
399
+ conflictResolutionStrategy?: 'priority' | 'consensus' | 'arbitration';
400
+ resourceSharingEnabled?: boolean;
401
+ };
402
+ }