
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@agent-ts/core
Advanced tools
A simple TypeScript library for building AI agents with OpenAI's API. This package provides a flexible and type-safe way to create AI agents that can use custom tools to perform various tasks.
Unlike simple completion APIs, an Agent is capable of having multi-turn conversations with tools. When a user asks a question, the Agent can:
This iterative process allows the Agent to handle complex queries that require multiple steps and external data sources.
bun install @agent-ts/core
Here's a simple example of creating and using an agent:
import { OpenAI } from "openai";
import { makeAgent, isTextChunk, isToolCallRequest, isToolCallResponse, isNewIteration } from "@agent-ts/core";
import { makeTool } from "@agent-ts/core/tools";
// Create a simple tool
const calculator = makeTool({
name: "calculator",
description: "A simple calculator that can perform basic arithmetic operations",
parameters: {
type: "object",
properties: {
operation: {
type: "string",
enum: ["add", "subtract", "multiply", "divide"]
},
a: { type: "number" },
b: { type: "number" }
},
required: ["operation", "a", "b"]
}
}, async ({ operation, a, b }) => {
switch (operation) {
case "add": return (a + b).toString();
case "subtract": return (a - b).toString();
case "multiply": return (a * b).toString();
case "divide": return (a / b).toString();
}
});
// Initialize OpenAI client
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
});
// Create an agent
const agent = makeAgent({
tools: [calculator],
model: "gpt-4-turbo-preview",
openAI: openai
});
// Use the agent
async function main() {
// The agent will automatically handle the conversation flow:
// 1. Receive the question
// 2. Decide to use the calculator tool
// 3. Call the tool with appropriate parameters
// 4. Process the result
// 5. Provide a natural language response
for await (const chunk of agent("What is 42 plus 13?")) {
if (isNewIteration(chunk)) {
console.log("-".repeat(20));
} else if (isTextChunk(chunk)) {
process.stdout.write(chunk.content);
} else if (isToolCallRequest(chunk)) {
console.log(`\nAgent is using tool: ${chunk.name}(${chunk.arguments})`);
} else if (isToolCallResponse(chunk)) {
console.log(`\nTool result: ${chunk.result}`);
}
}
}
main();
You can create custom tools using the makeTool
function. Here's an example of a more complex tool:
import { makeTool } from "@agent-ts/core/tools";
import { schema } from "@agent-ts/core/tools/schema";
const weatherTool = makeTool({
name: "get_weather",
description: "Get the current weather for a location",
parameters: schema.object({
location: schema.string().describe("The city name"),
unit: schema.string().enum(["celsius", "fahrenheit"]).default("celsius")
})
}, async ({ location, unit }) => {
// Implement your weather API call here
const response = await fetch(`https://api.weatherapi.com/v1/current.json?key=YOUR_API_KEY&q=${location}`);
const data = await response.json();
return JSON.stringify(data);
});
To run tests:
bun test
MIT
FAQs
Unknown package
The npm package @agent-ts/core receives a total of 2 weekly downloads. As such, @agent-ts/core popularity was classified as not popular.
We found that @agent-ts/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.