Skip to content

Commit

Permalink
Merge branch 'main' into feat/switchboard-feed-simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
thearyanag authored Jan 29, 2025
2 parents 08dbf65 + 8029e89 commit 7233d2d
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 9 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/check-langchain-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check LangChain Tool Names
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
check-langchain-tool-names:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: 9.4.0

- name: Install node-gyp prerequisites
run: sudo apt update && sudo apt install -y build-essential python3 pkg-config libudev-dev libusb-1.0-0-dev

- uses: actions/setup-node@v4
with:
node-version: "23"
cache: "pnpm"

- name: Install dependencies
run: pnpm install -r --no-frozen-lockfile

- run: pnpm run check-tool-names:langchain
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"prepare": "husky"
"tool-summary": "tsx src/utils/analyzeTools.ts",
"check-tool-names:langchain": "tsx scripts/check-langchain-tool-duplicates.ts"
},
"engines": {
"node": ">=22.0.0",
Expand Down Expand Up @@ -94,4 +95,4 @@
"typescript": "^5.7.2"
},
"packageManager": "[email protected]"
}
}
98 changes: 98 additions & 0 deletions scripts/check-langchain-tool-duplicates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Keypair } from "@solana/web3.js";
import { SolanaAgentKit } from "../src";
import { createSolanaTools } from "../src/langchain/index";
import { Tool } from "langchain/tools";
import bs58 from "bs58";

function findDuplicateNames(tools: Tool[]): Map<string, string[]> {
const nameMap = new Map<string, string[]>();

tools.forEach((tool) => {
const existing = nameMap.get(tool.name) || [];
nameMap.set(tool.name, [...existing, tool.constructor.name]);
});

const duplicates = new Map<string, string[]>();
nameMap.forEach((classes, name) => {
if (classes.length > 1) {
duplicates.set(name, classes);
}
});

return duplicates;
}

function findDuplicateClasses(tools: Tool[]): Map<string, string[]> {
const classMap = new Map<string, string[]>();

tools.forEach((tool) => {
const className = tool.constructor.name;
const existing = classMap.get(className) || [];
classMap.set(className, [...existing, tool.name]);
});

// Filter to only classes with multiple names
const duplicates = new Map<string, string[]>();
classMap.forEach((names, className) => {
if (names.length > 1) {
duplicates.set(className, names);
}
});

return duplicates;
}

async function main() {
const kit = new SolanaAgentKit(
process.env.SOLANA_PRIVATE_KEY ||
bs58.encode(Buffer.from(Keypair.generate().secretKey)),
process.env.RPC_URL || "",
{ OPENAI_API_KEY: process.env.OPENAI_API_KEY || "" },
);

const tools = createSolanaTools(kit);
const nameDuplicates = findDuplicateNames(tools);
const classDuplicates = findDuplicateClasses(tools);

let hasErrors = false;
const errorMessages: string[] = [];

if (nameDuplicates.size > 0) {
hasErrors = true;
errorMessages.push("❌ Duplicate tool names detected:");
nameDuplicates.forEach((classes, name) => {
errorMessages.push(
`\nName: ${name}`,
`Used by classes:`,
...classes.map((c) => `- ${c}`),
);
});
}

if (classDuplicates.size > 0) {
hasErrors = true;
errorMessages.push("\n❌ Classes used for multiple tools:");
classDuplicates.forEach((names, className) => {
errorMessages.push(
`\nClass: ${className}`,
"Used for tools:",
...names.map((name) => `- ${name}`),
);
});
}

if (hasErrors) {
console.error(errorMessages.join("\n"));
process.exit(1);
}

console.log(

Check warning on line 89 in scripts/check-langchain-tool-duplicates.ts

View workflow job for this annotation

GitHub Actions / check

Unexpected console statement
"✅ All checks passed:\n- No duplicate tool names\n- No classes reused for multiple tools",
);
process.exit(0);
}

main().catch((err) => {
console.error("Script failed:", err);
process.exit(1);
});
2 changes: 1 addition & 1 deletion src/langchain/3land/create_collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SolanaAgentKit } from "../../agent";
import { CreateCollectionOptions } from "@3land/listings-sdk/dist/types/implementation/implementationTypes";

export class Solana3LandCreateCollection extends Tool {
name = "3land_minting_tool";
name = "3land_minting_tool_collection";
description = `Creates an NFT Collection that you can visit on 3.land's website (3.land/collection/{collectionAccount})
Inputs:
Expand Down
2 changes: 1 addition & 1 deletion src/langchain/3land/create_single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SolanaAgentKit } from "../../agent";
import { CreateSingleOptions } from "@3land/listings-sdk/dist/types/implementation/implementationTypes";

export class Solana3LandCreateSingle extends Tool {
name = "3land_minting_tool";
name = "3land_minting_tool_single";
description = `Creates an NFT and lists it on 3.land's website
Inputs:
Expand Down
5 changes: 0 additions & 5 deletions src/langchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaDeleteHeliusWebhookTool(solanaKit),
new SolanaParseTransactionHeliusTool(solanaKit),
new SolanaGetAllAssetsByOwner(solanaKit),
new Solana3LandCreateSingle(solanaKit),
new SolanaSendTransactionWithPriorityFee(solanaKit),
new SolanaHeliusWebhookTool(solanaKit),
new SolanaGetHeliusWebhookTool(solanaKit),
new SolanaDeleteHeliusWebhookTool(solanaKit),
new SolanaCreateDriftUserAccountTool(solanaKit),
new SolanaCreateDriftVaultTool(solanaKit),
new SolanaDepositIntoDriftVaultTool(solanaKit),
Expand Down

0 comments on commit 7233d2d

Please sign in to comment.