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

@enso-labs/agent-core

v0.0.2

Published

A TypeScript package for managing AI agent workflows with memory, tool execution, and conversation state management.

Downloads

20

Readme

Enso Labs - Agent Core

A TypeScript package for managing AI agent workflows with memory, tool execution, and conversation state management.

Installation

npm install @enso-labs/agent-core

Usage

Core Functions

agentMemory(toolIntent, content, state, metadata?)

Adds events to the thread state memory system.

Parameters:

  • toolIntent: {intent: string; args: any} | string - The tool intent or string identifier
  • content: string - The content/message to store
  • state: ThreadState - Current thread state
  • metadata?: any - Optional metadata object

Returns: Promise<ThreadState> - Updated state with new event

Example:

import { agentMemory } from '@enso-labs/agent-core';

const newState = await agentMemory(
  'user_input',
  'Hello, how are you?',
  currentState,
  { timestamp: new Date().toISOString() }
);

executeTools(toolIntents, state, tools)

Executes multiple tool intents and updates the state with results.

Parameters:

  • toolIntents: ToolIntent[] - Array of tool intents to execute
  • state: ThreadState - Current thread state
  • tools: Tool[] - Array of available LangChain tools

Returns: Promise<ThreadState> - Updated state with tool execution results

Example:

import { executeTools } from '@enso-labs/agent-core';
import { Tool } from 'langchain/tools';

const toolIntents = [
  { intent: 'search', args: { query: 'weather today' } }
];

const updatedState = await executeTools(toolIntents, currentState, availableTools);

convertStateToXML(state)

Converts thread state to XML format for compatibility with systems expecting XML.

Parameters:

  • state: ThreadState - The thread state to convert

Returns: string - XML representation of the thread state

Example:

import { convertStateToXML } from '@enso-labs/agent-core';

const xmlString = convertStateToXML(currentState);
console.log(xmlString);
// Output: <thread>\n<event intent="user_input">Hello</event>\n</thread>

agentLoop({ prompt, model?, tools?, state? })

Main orchestration function that processes user queries through the complete agent workflow.

Parameters (Object):

  • prompt: string - User input query
  • model?: string - Model identifier (default: 'openai:gpt-4.1-nano')
  • tools?: Tool[] - Array of available tools (default: [])
  • state?: ThreadState - Current thread state (default: empty state with usage tracking)

Returns: Promise<AgentResponse> - Response containing content, updated state, and token usage

Example:

import { agentLoop } from '@enso-labs/agent-core';
import type { ThreadState } from '@enso-labs/agent-core';

// Simple usage with just a prompt
const response = await agentLoop({
  prompt: "What is the weather like today?",
  tools: weatherTools
});

// Advanced usage with custom state
const initialState: ThreadState = {
  thread: {
    usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 },
    events: []
  }
};

const response = await agentLoop({
  prompt: 'What is the weather like today?',
  state: initialState,
  model: 'openai:gpt-4o-mini',
  tools: weatherTools
});

console.log(response.content); // AI response
console.log(response.tokens);  // Token usage stats

Types

ThreadState

Main state management structure for conversation threads.

AgentResponse

Response structure returned by agentLoop() containing:

  • content: string - The AI response content
  • state: ThreadState - Updated thread state
  • tokens?: object - Token usage information

ToolIntent

Structure for tool execution requests:

  • intent: string - Tool name/identifier
  • args: any - Tool arguments

Error Handling

All functions include comprehensive error handling:

  • Tool execution failures are captured and added to state
  • LLM call failures return error messages in the response
  • Invalid tool references are handled gracefully

Dependencies

  • LangChain Tools for tool execution
  • Internal utilities for intent classification and LLM calls

Source

https://medium.com/@the_nick_morgan/creating-an-npm-package-with-typescript-c38b97a793cf