npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

swift-agent

v0.2.3

Published

A building block of agentic systems: an LLM that can retrieve information, use tools, and store user inputs.

Downloads

52

Readme

SwiftAgent

A building block of agentic systems: an LLM that can retrieve information, use tools, and store user inputs.

Description

SwiftAgent is designed to be a foundational component for building sophisticated AI agents. It provides a structured way to integrate Language Models (LLMs) with external tools via the Model Context Protocol (MCP) and manage conversation history.

Features

  • LLM Integration: Easily integrate with various language models.
  • Tool Usage: Connect to and utilize tools provided by MCP servers.
  • Message History: Manages conversation history for stateful interactions.
  • Extensible Options: Configure the agent with custom options, including system prompts and MCP client settings.

Installation

To install Swift Agent, you can use npm or yarn:

npm install swift-agent
# or
yarn add swift-agent

Usage

Here's a basic example of how to use Swift Agent:

import { ChatGoogleGenerativeAI as Model } from "@langchain/google-genai";
import SwiftAgent from "swift-agent";
import dotenv from "dotenv";

dotenv.config();

async function runAgent() {
  const llm = new Model({
    model: "gemini-2.5-flash-preview-04-17",
    apiKey: process.env.API_KEY, // Ensure you have API_KEY in your .env file
  });

  // Optional: Configure MCP servers
  const mcp = {
    mcpServers: {
      math: {
        command: "npx",
        args: ["-y", "nm-mcp-math"],
      },
      // Add other MCP servers here
    },
  };

  const agent = new SwiftAgent(llm, { mcp });

  // Run the agent with a message
  const result = await agent.run("what's (13 + 74) x 234?");
  console.log(result?.at(-1)?.content);
}

runAgent().catch(console.error);

Example

A runnable example is provided in examples/run-swift-agent.ts. To run this example:

  1. Ensure you have a .env file in the project root with your API_KEY for the chosen LLM.
  2. Install dependencies: npm install or yarn install
  3. Run the example script:
npm run example
# or
yarn example

This example demonstrates using the agent with a Google Generative AI model and an MCP math server to perform a calculation.

API

SwiftAgent(model: BaseChatModel, options?: SwiftAgentOptions)

Creates a new instance of the SwiftAgent.

  • model: An instance of a LangChain BaseChatModel.
  • options: An optional object of type SwiftAgentOptions.
    • mcp: Optional configuration for the MultiServerMCPClient.
      • mcpServers: An object mapping server names to their command and arguments.
      • throwOnLoadError: Whether to throw an error if an MCP server fails to load (defaults to true).
      • prefixToolNameWithServerName: Whether to prefix tool names with the server name (defaults to true).
      • additionalToolNamePrefix: An additional prefix to add to tool names (defaults to "mcp").
    • messageHistory: An optional array of BaseMessage to initialize the agent's message history.
    • systemPrompt: An optional system prompt string to add to the beginning of the message history.

agent.run(message: string): Promise<BaseMessage[] | undefined>

Runs the agent with a new human message.

  • message: The human message string to send to the agent.
  • Returns: A promise that resolves to an array of BaseMessage representing the agent's response, or undefined if an error occurred.

agent.setModel(model: BaseChatModel): void

Sets the internal language model used by the agent.

  • model: An instance of a LangChain BaseChatModel.

agent.enableMcpServer(serverName: string): void

Enables a specific MCP server by its name.

  • serverName: The name of the MCP server to enable.

agent.disableMcpServer(serverName: string): void

Disables a specific MCP server by its name.

  • serverName: The name of the MCP server to disable.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.