Skip to content

Add Smarter tool calling and ToolManager for multiple Tool calling#35

Merged
jorgeantonio21 merged 4 commits intoAtomaAI:mainfrom
kamalbuilds:smarter-tools
Feb 17, 2025
Merged

Add Smarter tool calling and ToolManager for multiple Tool calling#35
jorgeantonio21 merged 4 commits intoAtomaAI:mainfrom
kamalbuilds:smarter-tools

Conversation

@kamalbuilds
Copy link
Contributor

@kamalbuilds kamalbuilds commented Feb 13, 2025

Multi-Tool Execution System

Fixes #29

This PR tries to add a smart multiple tool calling manager for efficient calling of the tools

Overview

This enhanced Tool Management System provides a robust framework for executing multiple tools in parallel or sequence, with built-in support for retries, timeouts, and error handling.

This system is designed to handle complex workflows where multiple tools need to be coordinated efficiently.

Key Components

1. Enhanced Tool Interface

interface EnhancedTool extends Tool {
  category: string;
  version: string;
  dependencies?: ToolDependency[];
  parallelExecutionSupported?: boolean;
  requiredContext?: string[];
  validateInput?: (args: any[]) => boolean;
  transformOutput?: (result: any) => any;
  execute: (args: any[], context: ToolExecutionContext) => Promise<ToolExecutionResult>;
}
  • category: Groups tools by functionality
  • version: Tracks tool implementation version
  • dependencies: Specifies other tools required for execution
  • parallelExecutionSupported: Indicates if tool can run in parallel
  • requiredContext: Lists required context parameters
  • validateInput: Custom input validation function
  • transformOutput: Custom output transformation function
  • execute: Main execution function with context support

2. Execution Context

interface ToolExecutionContext {
  walletAddress?: string;
  chainId?: string;
  timestamp?: number;
  priority?: number;
  maxRetries?: number;
  timeout?: number;
}

Provides execution configuration and environment information:

  • Network details (walletAddress, chainId)
  • Execution parameters (priority, maxRetries, timeout)
  • Timing information (timestamp)

3. Execution Plan

interface ToolExecutionPlan {
  tools: EnhancedTool[];
  executionOrder: number[];
  parallelGroups?: number[][];
  context: ToolExecutionContext;
}

Defines how tools should be executed:

  • List of tools to execute
  • Order of execution
  • Groups of tools that can run in parallel
  • Shared execution context

Key Features

1. Parallel Execution

  • Tools marked with parallelExecutionSupported can be executed simultaneously
  • Uses Promise.all for efficient parallel execution
  • Maintains execution order between parallel groups
  • Handles dependencies between tools

2. Error Handling

  • Comprehensive error capture and reporting
  • Per-tool error tracking
  • Exponential backoff for retries
  • Timeout protection for long-running operations

3. Execution Tracking

  • Real-time execution statistics
  • Per-tool execution time tracking
  • Success/failure tracking
  • Retry count monitoring

Copy link
Contributor

@jorgeantonio21 jorgeantonio21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

But it seems it doesn't add support for tool composition, afaik

expect(result.successfulTools).toHaveLength(1);
expect(result.failedTools).toHaveLength(0);
expect(result.stats).toHaveLength(1);
expect(result.totalExecutionTime).toBeGreaterThan(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve this forbidden non-null access assert

@fishonamos fishonamos self-requested a review February 14, 2025 14:20
Copy link
Collaborator

@fishonamos fishonamos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool! and I love the execution context added. Though it doesn't currently work with the Sui agent—maybe it's still in progress?

Also, the approach I'm considering is to have a query decomposer so that the LLM itself determines if multiple tools are needed. The model should do most of the work imo and we want to avoid much automation as that will make it less of an AI agent.

For example, we could have something like:

async QueryDecomposer(prompt: string) {  
    return await this.AtomaClass.atomaChat([  
      { content: decomposerPrompt, role: 'assistant' },  
      { content: prompt, role: 'user' },  
    ]);  
} 

The prompt will also be updated for that.

@fishonamos
Copy link
Collaborator

Looks cool! and I love the execution context added. Though it doesn't currently work with the Sui agent—maybe it's still in progress?

Also, the approach I'm considering is to have a query decomposer so that the LLM itself determines if multiple tools are needed. The model should do most of the work imo and we want to avoid much automation as that will make it less of an AI agent.

For example, we could have something like:

async QueryDecomposer(prompt: string) {  
    return await this.AtomaClass.atomaChat([  
      { content: decomposerPrompt, role: 'assistant' },  
      { content: prompt, role: 'user' },  
    ]);  
} 

The prompt will also be updated for that.

Let me know what you think @jorgeantonio21

@jorgeantonio21
Copy link
Contributor

I am fine with more work on the server regarding the AI agent. That said, the model should be able to evaluate which tool(s) to choose and act upon

@jorgeantonio21 jorgeantonio21 merged commit 8d68f28 into AtomaAI:main Feb 17, 2025
1 check failed
fishonamos added a commit that referenced this pull request Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement multiple tools on AI agent

3 participants