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

@yeshwanthyk/agent-core

v0.1.1

Published

General-purpose agent with transport abstraction, state management, and attachment support

Readme

@yeshwanthyk/agent-core

Stateful agent abstraction with transport layer for LLM interactions. Provides a reactive Agent class that manages conversation state, emits granular events, and supports pluggable transports for different deployment scenarios.

Installation

npm install @yeshwanthyk/agent-core

Quick Start

import { Agent, ProviderTransport } from '@yeshwanthyk/agent-core';
import { getModel } from '@yeshwanthyk/ai';

// Create agent with direct provider transport
const agent = new Agent({
  transport: new ProviderTransport(),
  initialState: {
    systemPrompt: 'You are a helpful assistant.',
    model: getModel('anthropic', 'claude-sonnet-4-20250514'),
    thinkingLevel: 'medium',
    tools: []
  }
});

// Subscribe to events for reactive UI updates
agent.subscribe((event) => {
  switch (event.type) {
    case 'message_update':
      // Stream text to UI
      const content = event.message.content;
      for (const block of content) {
        if (block.type === 'text') console.log(block.text);
      }
      break;
    case 'tool_execution_start':
      console.log(`Calling ${event.toolName}...`);
      break;
    case 'tool_execution_update':
      // Stream tool output (e.g., bash stdout)
      console.log('Progress:', event.partialResult.content);
      break;
    case 'tool_execution_end':
      console.log(`Result:`, event.result.content);
      break;
  }
});

// Send a prompt
await agent.prompt('Hello, world!');

// Access conversation state
console.log(agent.state.messages);

Core Concepts

Agent State

The Agent maintains reactive state:

interface AgentState {
  systemPrompt: string;
  model: Model<any>;
  thinkingLevel: ThinkingLevel;  // 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'
  tools: AgentTool<any>[];
  messages: AppMessage[];
  isStreaming: boolean;
  streamMessage: Message | null;
  pendingToolCalls: Set<string>;
  error?: string;
}

Events

Events provide fine-grained lifecycle information:

| Event | Description | |-------|-------------| | agent_start | Agent begins processing | | agent_end | Agent completes, contains all generated messages | | turn_start | New turn begins (one LLM response + tool executions) | | turn_end | Turn completes with assistant message and tool results | | message_start | Message begins (user, assistant, or toolResult) | | message_update | Assistant message streaming update | | message_end | Message completes | | tool_execution_start | Tool begins execution | | tool_execution_update | Tool streams progress (e.g., bash output) | | tool_execution_end | Tool completes with result |

Transports

Transports abstract LLM communication:

  • ProviderTransport: Direct API calls using @yeshwanthyk/ai
  • AppTransport: Proxy through a backend server (for browser apps)
  • CodexTransport: OAuth-based access via ChatGPT subscription (gpt-5.2)
  • RouterTransport: Auto-routes to correct transport based on model provider
// Direct provider access (Node.js)
const agent = new Agent({
  transport: new ProviderTransport({
    getApiKey: (provider) => process.env[`${provider.toUpperCase()}_API_KEY`]
  })
});

// Via proxy (browser)
const agent = new Agent({
  transport: new AppTransport({
    endpoint: '/api/agent',
    headers: { 'Authorization': 'Bearer ...' }
  })
});

// Multi-provider with Codex + API keys
import { RouterTransport, CodexTransport, ProviderTransport, loadTokens, saveTokens, clearTokens } from '@yeshwanthyk/agent-core';

const router = new RouterTransport({
  codex: new CodexTransport({
    getTokens: async () => loadTokens(),
    setTokens: async (t) => saveTokens(t),
    clearTokens: async () => clearTokens(),
  }),
  provider: new ProviderTransport({
    getApiKey: (p) => process.env[`${p.toUpperCase()}_API_KEY`],
  }),
});

const agent = new Agent({ transport: router, initialState: { ... } });

Message Queue

Queue messages to inject at the next turn:

// Queue mode: 'all' or 'one-at-a-time'
agent.setQueueMode('one-at-a-time');

// Queue a message while agent is streaming
await agent.queueMessage({
  role: 'user',
  content: 'Additional context...',
  timestamp: Date.now()
});

Attachments

User messages can include attachments:

await agent.prompt('What is in this image?', [{
  id: 'img1',
  type: 'image',
  fileName: 'photo.jpg',
  mimeType: 'image/jpeg',
  size: 102400,
  content: base64ImageData
}]);

Custom Message Types

Extend AppMessage for app-specific messages via declaration merging:

declare module '@yeshwanthyk/agent-core' {
  interface CustomMessages {
    artifact: { role: 'artifact'; code: string; language: string };
  }
}

// Now AppMessage includes your custom type
const msg: AppMessage = { role: 'artifact', code: '...', language: 'typescript' };

API Reference

Agent Methods

| Method | Description | |--------|-------------| | prompt(text, attachments?) | Send a user prompt | | continue() | Continue from current context (for retry after overflow) | | abort() | Abort current operation | | waitForIdle() | Returns promise that resolves when agent is idle | | reset() | Clear all messages and state | | subscribe(fn) | Subscribe to events, returns unsubscribe function | | queueMessage(msg) | Queue message for next turn | | clearMessageQueue() | Clear queued messages |

State Mutators

| Method | Description | |--------|-------------| | setSystemPrompt(v) | Update system prompt | | setModel(m) | Switch model | | setThinkingLevel(l) | Set reasoning level | | setQueueMode(m) | Set queue mode ('all' or 'one-at-a-time') | | setTools(t) | Update available tools | | replaceMessages(ms) | Replace all messages | | appendMessage(m) | Append a message | | clearMessages() | Clear all messages |

License

MIT