Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Langchain Tool checking to CI #240

Merged
merged 7 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -93,4 +94,4 @@
"typescript": "^5.7.2"
},
"packageManager": "pnpm@9.15.3"
}
}
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 @@ -217,11 +217,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
Loading