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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tsagent/core

v1.3.6

Published

Typescript API for agents

Readme

@tsagent/core

The core TypeScript library for building, testing, and managing AI agents. This package provides the foundational framework for creating intelligent agents with support for multiple LLM providers, MCP integration, and agent lifecycle management.

About TSAgent

This package is part of TSAgent, an open-source TypeScript-first platform for building, testing, running, and orchestrating AI agents.

Installation

npm install @tsagent/core

Quick Start

Basic Agent Usage

import { loadAgent } from '@tsagent/core/runtime';

const logger = console as any; // Any object with info/debug/error is fine

// Load an existing agent
const agent = await loadAgent('./my-agent.yaml', logger);

// Create a chat session
const session = agent.createChatSession('session-1');

// Send a message
const result = await session.handleMessage('Hello, how can you help me?');
console.log(result.updates[1].modelReply);

Create a New Agent

import { createAgent } from '@tsagent/core/runtime';

const logger = console as any;

// Create a new agent
await createAgent('./new-agent.yaml', logger, {
  metadata: {
    name: 'My Assistant',
    description: 'A helpful AI assistant'
  }
});

Core Features

Multi-Provider Support

  • OpenAI: GPT-3.5, GPT-4, and other models
  • Anthropic: Claude 3.5 Sonnet, Claude 3 Haiku, and more
  • Google: Gemini Pro, Gemini Ultra
  • AWS Bedrock: Access to various foundation models
  • Ollama: Local model support
  • Custom Providers: Extensible provider architecture

Agent Management

  • Agent Lifecycle: Create, load, save, and manage agents
  • Configuration: Flexible agent configuration with YAML format (.yaml or .yml)
  • State Management: Persistent agent state and conversation history
  • Error Handling: Robust error handling and recovery

MCP Integration

  • Model Context Protocol: Full MCP client implementation
  • Tool Integration: Connect to thousands of MCP-compatible tools
  • Dynamic Tool Loading: Load tools at runtime
  • Tool Management: Manage tool permissions and configurations

Chat Sessions

  • Conversation Management: Maintain chat history and context
  • Streaming Support: Real-time message streaming
  • Tool Calls: Handle tool calls and user permissions
  • Session State: Persistent session state across restarts

API Reference

Core Classes

Agent

The main agent interface for managing AI agents. Obtain instances via runtime functions (loadAgent / createAgent), not via new.

// Obtained from runtime, supports chat sessions among other capabilities
agent.createChatSession(id: string, options?: ChatSessionOptions): ChatSession;
agent.getChatSession(id: string): ChatSession | null;
agent.getAllChatSessions(): ChatSession[];
agent.deleteChatSession(id: string): Promise<boolean>;

ChatSession

Manages chat sessions and conversation history.

// Create via: const session = agent.createChatSession('session-1', options)
session.handleMessage(message: string | ChatMessage): Promise<MessageUpdate>;
session.getState(): ChatState;
session.clearModel(): MessageUpdate;
session.switchModel(modelType: ProviderType, modelId: string): MessageUpdate;
session.addReference(name: string): boolean;
session.removeReference(name: string): boolean;
session.addRule(name: string): boolean;
session.removeRule(name: string): boolean;

Provider Management

// From an Agent instance
const providersInfo = agent.getAvailableProvidersInfo();
const models = await agent.getProviderModels('openai');

MCP Integration

// Via the Agent instance
const clients = await agent.getAllMcpClients();
const client = await agent.getMcpClient('filesystem');

Agent Configuration

Agents are configured using a single YAML file (.yaml or .yml). All agent content (system prompt, rules, references) is embedded in the file:

Note: For a limited time, the system will automatically convert older JSON-based agents (directory structure with tsagent.json) to the new YAML format when you load them. The conversion happens transparently on first load, and the original JSON file is preserved. After conversion, the agent uses the new YAML file.

metadata:
  name: "My Assistant"
  description: "A helpful AI assistant"
  version: "1.0.1"
  skills: []
  iconUrl: "https://example.com/icon.png"
  documentationUrl: "https://example.com/docs"
  provider:
    organization: "Example Org"
    url: "https://example.com"
  created: "2025-04-07T17:32:29.081Z"
  lastAccessed: "2025-04-07T17:32:29.081Z"

systemPrompt: |
  You are a helpful AI assistant.
  This is a multi-line system prompt.
  Supports markdown formatting.

settings:
  maxChatTurns: 20
  maxOutputTokens: 1000
  temperature: 0.5
  topP: 0.5
  theme: "light"
  mostRecentModel: "gemini:gemini-2.0-flash"

rules:
  - name: "example-rule"
    description: "An example rule"
    priorityLevel: 500
    text: |
      Rule content here.
      Supports markdown.
    include: "always"

references:
  - name: "example-reference"
    description: "An example reference"
    priorityLevel: 500
    text: |
      Reference content here.
      Supports markdown.
    include: "manual"

providers:
  anthropic:
    ANTHROPIC_API_KEY: "xxxxx"
  gemini:
    GOOGLE_API_KEY: "xxxxx"
  openai:
    OPENAI_API_KEY: "xxxxx"
  bedrock:
    BEDROCK_ACCESS_KEY_ID: "xxxxx"
    BEDROCK_SECRET_ACCESS_KEY: "xxxxx"
  ollama:
    OLLAMA_HOST: "localhost:11434"  # optional

mcpServers:
  filesystem:
    type: "stdio"
    command: "npx"
    args:
      - "-y"
      - "@modelcontextprotocol/server-filesystem"
      - "./test_files"
    toolPermissionRequired:
      serverDefault: false
      tools:
        read_text_file: true
    toolInclude:
      serverDefault: "agent"
      tools:
        directory_tree: "manual"
    # toolEmbeddings: Automatically managed - contains semantic embeddings for tools
    #   tools:
    #     tool_name:
    #       embeddings: [[...]]
    #       hash: "..."

TypeScript Support

This package is written in TypeScript and provides full type definitions:

import type { 
  Agent, 
  AgentConfig, 
  ChatMessage, 
  ProviderType,
  ToolCall 
} from '@tsagent/core';

Related Packages

  • @tsagent/cli - Command-line interface for agent operations
  • @tsagent/server - A2A protocol server for exposing agents as HTTP endpoints
  • @tsagent/orchestrator - MCP server for orchestrating A2A agent servers

Development

# Build the package
npm run build

License

MIT License - see LICENSE for details.