Skip to content

Commit b735df8

Browse files
committed
add detailed comments
1 parent c7cc5f7 commit b735df8

File tree

7 files changed

+440
-75
lines changed

7 files changed

+440
-75
lines changed

packages/sui-agent/src/@types/interface.ts

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
// Response interface for the intent agent's operations
1+
/**
2+
* Core Type Definitions for the Atoma AI Agent System
3+
* This file contains all the essential interfaces and types used throughout the agent.
4+
*
5+
* The type system is designed to ensure:
6+
* 1. Type Safety - Strong typing for all agent operations
7+
* 2. Consistency - Standardized interfaces across the system
8+
* 3. Extensibility - Easy addition of new tools and features
9+
*
10+
* @module Types
11+
*/
12+
13+
/**
14+
* Response interface for the intent agent's operations.
15+
* Represents the structured output from tool selection and execution.
16+
*
17+
* @interface IntentAgentResponse
18+
*/
219
export interface IntentAgentResponse {
320
success: boolean; // Indicates if the operation was successful
421
selected_tools: null | string[]; // Name of the tool that was selected for the operation
@@ -8,9 +25,20 @@ export interface IntentAgentResponse {
825
tool_arguments: (string | number | boolean | bigint)[]; // Arguments passed to the tool
926
}
1027

28+
/**
29+
* Basic type for tool arguments.
30+
* Supports common primitive types used in tool execution.
31+
*
32+
* @typedef ToolArgument
33+
*/
1134
export type ToolArgument = string | number | boolean | bigint;
1235

13-
// Response interface for tool operations (similar to IntentAgentResponse)
36+
/**
37+
* Response interface for tool operations.
38+
* Similar structure to IntentAgentResponse for consistency.
39+
*
40+
* @interface toolResponse
41+
*/
1442
export interface toolResponse {
1543
success: boolean;
1644
selected_tools: null | string;
@@ -20,15 +48,25 @@ export interface toolResponse {
2048
tool_arguments: (string | number | boolean | bigint)[];
2149
}
2250

23-
// Defines the structure for tool parameters
51+
/**
52+
* Defines the structure for tool parameters.
53+
* Used in tool registration and validation.
54+
*
55+
* @interface ToolParameter
56+
*/
2457
export interface ToolParameter {
2558
name: string; // Name of the parameter
2659
type: string; // Data type of the parameter
2760
description: string; // Description of what the parameter does
2861
required: boolean; // Whether the parameter is mandatory
2962
}
3063

31-
// Defines the structure for tools that can be used by the agent
64+
/**
65+
* Defines the structure for tools that can be used by the agent.
66+
* Core interface for all tool implementations.
67+
*
68+
* @interface Tool
69+
*/
3270
export interface Tool {
3371
name: string; // Name of the tool
3472
description: string; // Description of what the tool does
@@ -38,8 +76,21 @@ export interface Tool {
3876
) => Promise<string> | string; // Function to execute the tool
3977
}
4078

41-
// Mapping of different coin names/variants to their standardized symbol
42-
// This helps in recognizing different ways users might refer to the same coin
79+
/**
80+
* Mapping of different coin names/variants to their standardized symbol.
81+
* Helps in recognizing different ways users might refer to the same coin.
82+
*
83+
* Key Features:
84+
* - Case-insensitive matching
85+
* - Multiple variants per coin
86+
* - Standardized output symbols
87+
*
88+
* TODO:
89+
* - Add support for more coin variants
90+
* - Add support for token metadata
91+
*
92+
* @const COIN_SYNONYMS
93+
*/
4394
export const COIN_SYNONYMS: Record<string, string> = {
4495
// SUI and variants
4596
SUI: 'SUI',
@@ -124,8 +175,16 @@ export const COIN_SYNONYMS: Record<string, string> = {
124175
WSBCOIN: 'WSB',
125176
} as const;
126177

127-
// Mapping of coin symbols to their respective addresses on the Sui network
128-
// These addresses are used to interact with the coins on the blockchain
178+
/**
179+
* Mapping of coin symbols to their respective addresses on the Sui network.
180+
* Used for blockchain interactions and token operations.
181+
*
182+
* Features:
183+
* - Mainnet addresses
184+
* - Type information
185+
* - Standardized format
186+
* @const COIN_ADDRESSES
187+
*/
129188
export const COIN_ADDRESSES = {
130189
SUI: '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI',
131190
USDC: '0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT',
@@ -164,27 +223,46 @@ export const COIN_ADDRESSES = {
164223
WSB: '0x4db126eac4fa99207e98db61d968477021fdeae153de3b244bcfbdc468ef0722::wsb::WSB',
165224
} as const;
166225

167-
// Structure for token balance information
226+
/**
227+
* Structure for token balance information.
228+
* Used for representing token holdings and balances.
229+
*
230+
* @interface TokenBalance
231+
*/
168232
export interface TokenBalance {
169233
token: string; // Token address or identifier
170234
amount: bigint; // Token amount
171235
symbol?: string; // Token symbol (optional)
172236
decimals?: number; // Number of decimal places for the token (optional)
173237
}
174238

175-
// Configuration for a specific network (mainnet or testnet)
239+
/**
240+
* Configuration for a specific network (mainnet or testnet).
241+
* Contains network-specific endpoints and settings.
242+
*
243+
* @interface NetworkConfig
244+
*/
176245
export interface NetworkConfig {
177246
fullnode: string; // URL for the network's fullnode
178247
faucet?: string; // URL for the network's faucet (optional)
179248
}
180249

181-
// Configuration for all supported networks
250+
/**
251+
* Configuration for all supported networks.
252+
* Manages configurations for different network environments.
253+
*
254+
* @interface NetworkConfigs
255+
*/
182256
export interface NetworkConfigs {
183257
MAINNET: NetworkConfig; // Mainnet configuration
184258
TESTNET: NetworkConfig; // Testnet configuration
185259
}
186260

187-
// Network configuration constants
261+
/**
262+
* Network configuration constants.
263+
* Defines the default network endpoints and settings.
264+
* @const NETWORK_CONFIG
265+
*/
188266
export const NETWORK_CONFIG: NetworkConfigs = {
189267
MAINNET: {
190268
fullnode: 'https://fullnode.mainnet.sui.io',

packages/sui-agent/src/agents/SuiAgent.ts

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@ import Atoma from '../config/atoma';
88
import decomposerPrompt from '../prompts/decomposer';
99

1010
/**
11-
* Main agent class that handles intent processing and decision making
12-
* Coordinates between different agent types to process user queries
11+
* Main agent class that handles intent processing and decision making.
12+
* Coordinates between different agent types to process user queries.
13+
* This is the primary entry point for all agent-based operations.
14+
*
15+
* The agent follows a pipeline architecture:
16+
* 1. Query Decomposition - Breaks down complex queries into simpler subqueries
17+
* 2. Tool Selection - Identifies appropriate tools for each subquery
18+
* 3. Query Processing - Executes tools and aggregates results
19+
*
20+
* TODO:
21+
* - Implement retry mechanisms for failed tool executions
22+
* - Add context management to maintain conversation history
23+
* - Implement caching for frequently used tool results
24+
* - Add error recovery strategies for each pipeline stage
25+
* - Implement rate limiting for API calls
26+
* - Add validation for tool arguments before execution
1327
*
1428
* @example
1529
* const agent = new Agents("your-bearer-auth-token");
@@ -21,6 +35,13 @@ class Agents {
2135
private utils: Utils;
2236
private AtomaClass: Atoma;
2337

38+
/**
39+
* Creates a new instance of the Agents class.
40+
* Initializes all necessary components and registers available tools.
41+
*
42+
* @param bearerAuth - Authentication token for API access
43+
* TODO: Add support for additional configuration options
44+
*/
2445
constructor(bearerAuth: string) {
2546
this.tools = new Tools(bearerAuth, intent_agent_prompt);
2647
this.AtomaClass = new Atoma(bearerAuth);
@@ -29,6 +50,13 @@ class Agents {
2950
registerAllTools(this.tools);
3051
}
3152

53+
/**
54+
* Decomposes a complex user query into simpler subqueries that can be processed independently.
55+
* Uses the Atoma LLM to break down queries based on the decomposer prompt.
56+
*
57+
* @param prompt - The original user query to decompose
58+
* @returns Promise containing array of decomposed subqueries
59+
*/
3260
async QueryDecomposer(prompt: string) {
3361
return await this.AtomaClass.atomaChat([
3462
{ content: decomposerPrompt, role: 'assistant' },
@@ -37,9 +65,12 @@ class Agents {
3765
}
3866

3967
/**
40-
* Processes initial user intent and selects appropriate tools
41-
* @param prompt - User's input query
42-
* @returns IntentAgentResponse containing tool selection and processing details
68+
* Analyzes decomposed subqueries and selects appropriate tools for processing each one.
69+
* Maps each subquery to one or more tools that can handle it.
70+
*
71+
* @param subqueries - Array of decomposed subqueries
72+
* @param address - Optional wallet address for context
73+
* @returns Promise containing tool selection responses for each subquery
4374
*/
4475
async toolsSelector(subqueries: string[], address?: string) {
4576
const IntentResponse: IntentAgentResponse[] =
@@ -53,14 +84,17 @@ class Agents {
5384
}
5485

5586
/**
56-
* Makes decisions based on the intent response and user query
57-
* @param intentResponse - Response from the IntentAgent
58-
* @param query - Original user query
59-
* @returns Processed response after decision making
87+
* Processes the selected tools' responses and generates a final answer.
88+
* Coordinates execution of tools and aggregates their results.
89+
*
90+
* @param intentResponse - Array of tool selection responses
91+
* @param query - Original user query for context
92+
* @returns Promise containing processed final response
93+
*
94+
* TODO:
95+
* - Add support for parallel tool execution
6096
*/
6197
async QueryProcessor(intentResponse: IntentAgentResponse[], query: string) {
62-
// Pass both the selected tool name and arguments to processQuery
63-
6498
return await this.utils.processQuery(
6599
this.AtomaClass,
66100
query,
@@ -69,10 +103,18 @@ class Agents {
69103
}
70104

71105
/**
72-
* Main entry point for processing user queries
73-
* Coordinates between IntentAgent and DecisionMakingAgent
106+
* Main pipeline for processing user queries from start to finish.
107+
* Orchestrates the entire process from query decomposition to final response.
108+
*
109+
* Pipeline stages:
110+
* 1. Query decomposition
111+
* 2. Tool selection for each subquery
112+
* 3. Tool execution and response processing
113+
* 4. Final answer generation
114+
*
74115
* @param prompt - User's input query
75-
* @returns Final processed response
116+
* @param walletAddress - Optional wallet address for context
117+
* @returns Promise containing final processed response
76118
*/
77119
async processUserQueryPipeline(prompt: string, walletAddress?: string) {
78120
// Process intent

packages/sui-agent/src/config/atoma.ts

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,70 @@ import { AtomaSDK } from 'atoma-sdk';
22
import * as dotenv from 'dotenv';
33
dotenv.config();
44

5+
/**
6+
* Default model for chat completions if not specified in environment
7+
* Currently defaults to Llama-3.3-70B-Instruct for optimal performance
8+
*
9+
* TODO:
10+
* - Add support for model fallbacks
11+
* - Implement model performance tracking
12+
* - Add model selection based on query complexity
13+
*/
514
const ATOMA_CHAT_COMPLETIONS_MODEL =
615
process.env.ATOMA_CHAT_MODEL || 'meta-llama/Llama-3.3-70B-Instruct';
716
console.log(ATOMA_CHAT_COMPLETIONS_MODEL);
817

18+
/**
19+
* Core class for interacting with the Atoma AI platform.
20+
* Handles all LLM-related operations including chat completions and health checks.
21+
*
22+
* This class serves as the primary interface for:
23+
* - Chat completions
24+
* - Model management
25+
* - Health monitoring
26+
* - SDK initialization
27+
*
28+
* TODO:
29+
* - Implement request rate limiting
30+
* - Add response caching
31+
* - Implement retry mechanisms
32+
* - Add support for streaming responses
33+
* - Implement context management
34+
* - Add token usage tracking
35+
* - Implement cost optimization strategies
36+
*/
937
class Atoma {
1038
private bearerAuth;
39+
40+
/**
41+
* Creates a new Atoma instance with authentication
42+
*
43+
* @param bearerAuth - Bearer authentication token for API access
44+
*
45+
* TODO:
46+
* - Add support for multiple authentication methods
47+
* - Implement token refresh mechanism
48+
* - Add token validation
49+
*/
1150
constructor(bearerAuth: string) {
1251
this.bearerAuth = bearerAuth;
1352
}
1453

1554
/**
16-
* Helper function to create chat completions using Atoma SDK
17-
* @param messages - Array of message objects with content and role
55+
* Creates chat completions using the Atoma SDK.
56+
* Handles message formatting and model selection.
57+
*
58+
* @param messages - Array of message objects containing content and role
1859
* @param model - Optional model identifier (defaults to environment variable or Llama-3.3-70B-Instruct)
19-
* @returns Chat completion response
60+
* @returns Promise containing chat completion response
61+
*
62+
* TODO:
63+
* - Implement message validation
64+
* - Add support for conversation history
65+
* - Implement response filtering
66+
* - Add support for system messages
67+
* - Implement prompt optimization
68+
* - Add response quality checks
2069
*/
2170
async atomaChat(
2271
messages: { content: string; role: string }[],
@@ -32,17 +81,34 @@ class Atoma {
3281
}
3382

3483
/**
35-
* Initialize Atoma SDK with authentication
36-
* @param bearerAuth - Bearer auth token for Atoma SDK
37-
* @returns Initialized Atoma SDK instance
84+
* Initializes the Atoma SDK with authentication.
85+
* Creates and configures a new SDK instance.
86+
*
87+
* @param bearerAuth - Bearer authentication token
88+
* @returns Configured AtomaSDK instance
89+
*
90+
* TODO:
91+
* - Add SDK configuration validation
92+
* - Implement SDK instance pooling
93+
* - Add support for custom configurations
3894
*/
3995
public static initializeAtomaSDK(bearerAuth: string): AtomaSDK {
4096
return new AtomaSDK({ bearerAuth });
4197
}
98+
4299
/**
43-
* Health check function that returns service status
100+
* Performs a health check on the Atoma service.
101+
* Verifies if the service is responsive and functioning correctly.
102+
*
44103
* @param sdk - Initialized Atoma SDK instance
45-
* @returns Boolean indicating if service is healthy
104+
* @returns Promise<boolean> indicating if service is healthy
105+
*
106+
* TODO:
107+
* - Add detailed health metrics
108+
* - Implement health check caching
109+
* - Add support for custom health checks
110+
* - Implement health check alerts
111+
* - Add performance monitoring
46112
*/
47113
static async isAtomaHealthy(sdk: AtomaSDK): Promise<boolean> {
48114
try {

0 commit comments

Comments
 (0)