Agent-Tool/README.md at main · NeaByteLab/Agent-Tool · GitHub
Skip to content

Latest commit

 

History

History
109 lines (77 loc) · 3.08 KB

README.md

File metadata and controls

109 lines (77 loc) · 3.08 KB

Agent Tool

Helper that wraps functions into agent tool plugin instances

Deno Node Bun Browser

Installation

Deno:

deno add npm:@neabyte/agent-tool

npm:

npm install @neabyte/agent-tool

CDN (jsDelivr/esm.sh):

<script type="module">
  import Tool from 'https://cdn.jsdelivr.net/npm/@neabyte/agent-tool/dist/index.mjs'
</script>

Or via esm.sh:

<script type="module">
  import Tool from 'https://esm.sh/@neabyte/agent-tool'
</script>

Quick Start

Import the default export, define a tool with name, description, schema, and handler, then call execute with input and an optional signal.

import Tool, { type ToolPlugin } from '@neabyte/agent-tool'

// Define a tool that returns the weather for a city
const weather: ToolPlugin = Tool.define({
  name: 'get_weather',
  description: 'Get the current weather for a city',
  parameters: {
    type: 'object',
    properties: {
      city: { type: 'string' }
    },
    required: ['city']
  },
  execute(args) {
    return {
      success: true,
      json: { temp: 28, condition: 'sunny' },
      text: 'Sunny, 28C'
    }
  }
})

// Inspect the JSON Schema that the API consumes
console.log(weather.schema)

// Call the tool with input, optional signal, and optional event callback
const result = await weather.execute({ city: 'Jakarta' })
console.log(result.text)

Read docs/README.md for full API reference, schema shapes, abort flows, and type definitions.

Build and Test

Note

Prerequisites: Deno for all development tasks.

Check - format, lint, and typecheck source:

deno task check

Unit tests - run all tests:

deno task test

Docs

  • Defining Tools - Tool.define() configuration shape and execute function contract
  • Executing Tools - ToolPlugin.execute() flow, abort handling, error translation
  • Schemas - ToolDef union, OpenAI flat and nested layouts, Anthropic layout

Reference

License

Code in this repository is licensed under Apache 2.0, documentation is licensed under CC-BY-4.0.