New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

daemon-agent

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

daemon-agent

A framework for building and running background agents with tool-use capabilities

latest
npmnpm
Version
1.1.0
Version published
Weekly downloads
4
100%
Maintainers
1
Weekly downloads
 
Created
Source

Daemon Agent

A framework for building and running background agents with tool-use capabilities.

Overview

Daemon Agent provides a flexible, type-safe framework for creating autonomous agents powered by OpenAI's language models. The framework includes support for:

  • Tool-calling with structured input/output
  • Long and short-term memory with vector storage
  • Event-based communication
  • Extensible agent architecture

Installation

npm install daemon-agent

Peer Dependencies

The following peer dependencies are required:

  • @qdrant/js-client-rest: ^1.14.0 (for vector storage)
  • openai: ^4.0.0
  • zod: ^3.0.0
  • typescript: ^5

Quick Start

import { OpenAI } from 'openai';
import { QdrantClient } from '@qdrant/js-client-rest';
import {
  OpenAIAgent,
  OpenAIEmbedding,
  OpenAIChatLLM,
  QdrantMemory,
  ReasoningTool,
  SendMessageTool
} from 'daemon-agent';

// Initialize OpenAI client
const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY
});

// Set up embedding and LLM
const embedding = new OpenAIEmbedding({ client });
const llm = new OpenAIChatLLM({ client });

// Initialize Qdrant for vector storage
const qdrantClient = new QdrantClient({
  url: process.env.QDRANT_URL
});

// Create memory with persistence
const memory = new QdrantMemory({
  id: 'my-agent',
  collectionName: 'agent-memories',
  qdrantClient,
  embedding,
  llm
});

// Create tools
const sendMessageTool = new SendMessageTool();

// Create an agent
const agent = new OpenAIAgent({
  name: 'my-agent',
  client,
  model: 'gpt-4-turbo',
  memory,
  tools: [sendMessageTool]
});

// Listen for events
agent.event.on('finalMessage', (message) => {
    console.log('Agent response:', message.content);
});

// Run the agent with initial message
const result = await agent.run({
  messages: [{
    role: 'user',
    content: 'Hello, I need help with my project.'
  }]
});

// Print the final response messages
console.log(result);

Architecture

The framework follows a modular architecture with several key components:

Agents

  • BaseAgent: Abstract interface for all agent implementations
  • OpenAIAgent: Implementation using OpenAI's chat completions API
  • OpenAIAgentOS: Extended agent with operating-system like capabilities

Memory

  • BaseAgentMemory: Abstract memory interface
  • InMemoryMemory: Simple in-memory storage
  • QdrantMemory: Vector-based persistent storage using Qdrant

Embeddings

  • BaseEmbedding: Abstract embedding interface
  • OpenAIEmbedding: Implementation using OpenAI's embedding models

LLMs

  • BaseLLM: Abstract LLM interface
  • OpenAIChatLLM: Implementation using OpenAI's chat models

Tools

  • OpenAITool: Base class for creating tools with Zod schemas
  • ReasoningTool: Allows the agent to reason step-by-step
  • SendMessageTool: Enables messaging functionality
  • SleepTool: Allows the agent to pause execution
  • LinkupSearchTool: Provides search capabilities

Advanced Usage

Creating a Typesafe Custom Tools

import { z } from 'zod';
import { OpenAITool } from 'daemon-agent';

new OpenAITool({
    name: "calculator",
    description: "Perform basic mathematical operations",
    parameters: z.object({
        operation: z.enum(["add", "subtract", "multiply", "divide"]),
        a: z.number(),
        b: z.number(),
    }),
    function: async (params) => {
        // complete typesafety
        const { operation, a, b } = params;
        switch (operation) {
            case "add":
                return String(a + b);
            case "subtract":
                return String(a - b);
            case "multiply":
                return String(a * b);
            case "divide":
                return String(a / b);
        }
    },
}),

Typesafe Event Handling

agent.event.on('stepMessage', ({ step, message }) => {
  console.log(`Step ${step}:`, message);
});

agent.event.on('usage', ({ step, usage }) => {
  console.log(`Token usage at step ${step}:`, usage);
});

agent.event.on('totalUsage', (usage) => {
  console.log('Total token usage:', usage);
});

License

MIT

Author

Viky (vikyw89@gmail.com)

FAQs

Package last updated on 16 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts