A lightweight AI agent framework for TypeScript.
Note
agentnode-ts is under active development. APIs and capabilities may change as the framework evolves.
- Multi-turn conversations
- Custom tool calling
- Multiple tool calls in one run
- OpenAI support
- Fully typed TypeScript API
npm install agentnode-tsSet your OpenAI API key:
export OPENAI_API_KEY="your-api-key"import {
AgentNode,
OpenAIModel,
} from "agentnode-ts";
const model = new OpenAIModel({
model: "gpt-4.1-mini",
});
const agent = new AgentNode({
model,
instructions: "You are a concise and helpful assistant.",
});
const response = await agent.run(
"Explain what an AI agent is in one sentence.",
);
console.log(response.text);An agent remembers earlier messages across calls to run():
const firstResponse = await agent.run(
"My favorite color is blue.",
);
console.log(firstResponse.text);
// Blue is a great choice! Is there something specific you'd like to know or discuss about the color blue?
const secondResponse = await agent.run(
"What is my favorite color?",
);
console.log(secondResponse.text);
// Your favorite color is blue.You can also continue from existing history:
const history = agent.getHistory();
const restoredAgent = new AgentNode({
model,
instructions: "You are a concise and helpful assistant.",
history,
});
const restoredResponse = await restoredAgent.run(
"What fact did I share with you?",
);
console.log(restoredResponse.text);
// You shared that your favorite color is blue.Use one AgentNode per conversation. Start over with:
agent.reset();Define a tool:
import type {
Tool,
} from "agentnode-ts";
const getCurrentTimeTool: Tool = {
name: "get_current_time",
description: "Get the current date and time for an IANA time zone.",
inputSchema: {
type: "object",
properties: {
timeZone: {
type: "string",
description: "An IANA time zone such as America/Los_Angeles.",
},
},
required: ["timeZone"],
additionalProperties: false,
},
async execute(input) {
const timeZone = input.timeZone;
if (typeof timeZone !== "string") {
throw new Error("timeZone must be a string.");
}
return {
currentTime: new Intl.DateTimeFormat(
"en-US",
{
dateStyle: "full",
timeStyle: "long",
timeZone,
},
).format(new Date()),
};
},
};Register the tool and run the agent:
const agent = new AgentNode({
model,
instructions: "You are a concise and helpful assistant.",
tools: [getCurrentTimeTool],
});
const response = await agent.run(
"What time is it in San Francisco?",
);
console.log(response.text);From a cloned repository, install dependencies:
npm installRun the basic example:
npx tsx examples/basic.tsRun the conversation example:
npx tsx examples/conversation/index.tsRun the tool-calling example:
npx tsx examples/current-time/index.ts- OpenAI
- Context window management
- Streaming responses
- Structured output
- Additional model providers
- Persistent memory
- MCP support
- Multi-step planning
MIT