0.1.0-4 • Published 11 months ago
@lit-protocol/aw-subagent-openai v0.1.0-4
Subagent: Intent Parsing and Tool Matching
Subagent is a utility that uses OpenAI to parse user intents and match them to the appropriate tools. It’s designed to simplify the process of understanding user requests and mapping them to the correct tools in a web3 environment.
How It Works
- Intent Matching: Subagent analyzes a user’s intent (e.g., "I want to mint an NFT") and matches it to a registered tool.
- Parameter Parsing: If a tool is matched, Subagent extracts and validates the required parameters from the user’s intent.
- OpenAI Integration: It uses OpenAI’s API to perform intent analysis and parameter extraction.
Example Usage
import { OpenAiIntentMatcher } from './agent';
import type { AwTool } from '@lit-protocol/aw-tool';
// Initialize Subagent
const apiKey = 'your-openai-api-key';
const intentMatcher = new OpenAiIntentMatcher(apiKey);
// Register tools
const registeredTools: AwTool<any, any>[] = [
{
name: 'MintNFT',
description: 'Mint a new NFT',
ipfsCid: 'QmExampleCID1',
parameters: {
descriptions: {
tokenId: 'The ID of the token to mint',
recipient: 'The address of the recipient',
},
schema: {}, // Zod schema for validation
validate: (params) => true, // Validation logic
},
},
// Add more tools as needed
];
// Analyze user intent
const userIntent = "I want to mint an NFT with token ID 123 to address 0x123...";
const result = await intentMatcher.analyzeIntentAndMatchTool(userIntent, registeredTools);
// Check results
if (result.matchedTool) {
console.log('Matched Tool:', result.matchedTool.name);
console.log('Found Parameters:', result.params.foundParams);
console.log('Missing Parameters:', result.params.missingParams);
} else {
console.log('No matching tool found.');
}Key Features
Intent Matching: Matches user intents to registered tools.
Parameter Extraction: Parses and validates parameters from the user’s intent.
OpenAI Integration: Uses OpenAI for accurate intent analysis.Conclusion
Subagent makes it easy to parse user intents and match them to the right tools, ensuring seamless execution in web3 workflows.
0.1.0-23
9 months ago
0.1.0-22
10 months ago
0.1.0-21
10 months ago
0.1.0-19
10 months ago
0.1.0-18
10 months ago
0.1.0-17
10 months ago
0.1.0-16
10 months ago
0.1.0-15
10 months ago
0.1.0-13
10 months ago
0.1.0-12
10 months ago
0.1.0-11
10 months ago
0.1.0-10
10 months ago
0.1.0-9
11 months ago
0.1.0-8
11 months ago
0.1.0-7
11 months ago
0.1.0-6
11 months ago
0.1.0-5
11 months ago
0.1.0-4
11 months ago
0.1.0-3
11 months ago
0.1.0-2
11 months ago