Agentic - AI智慧體標準庫
項目概述
Agentic 是一個 AI 功能/工具的標準庫,針對普通 TypeScript 使用和基於 LLM 的使用進行了優化。Agentic 與所有主要的 TypeScript AI SDK 相容(包括 Vercel AI SDK、Mastra、LangChain、LlamaIndex、OpenAI SDK、MCP 等)。
項目地址: https://github.com/transitive-bullshit/agentic
核心特性
🎯 雙重使用模式
- 標準 TypeScript 類別:可以作為普通的 TS 類別直接使用
- LLM 工具:可以輕鬆整合到各種 AI SDK 中作為工具使用
🔧 廣泛的 SDK 支援
支援所有主流的 TypeScript AI SDK:
- Vercel AI SDK
- Mastra AI Agent 框架
- LangChain
- LlamaIndex
- OpenAI SDK
- Genkit
- Dexter
- xsAI SDK
- GenAIScript
- MCP (Model Context Protocol)
✨ 主要優勢
- ✅ 所有工具都經過生產環境的全面測試
- ✅ 跨所有主流 TS AI SDK 工作
- ✅ 工具手工編碼,極其精簡
- ✅ 透過
@aiFunction 裝飾器提供良好的手動 DX 和 LLM DX
- ✅ 使用原生
fetch
- ✅ 使用
ky 封裝 fetch,便於自定義 HTTP 選項、限流、重試等
- ✅ 支援任何 MCP 伺服器的工具
- ✅ 可從 OpenAPI 規範生成新的 Agentic 工具客戶端
- ✅ 100% 開源,不銷售任何產品
使用範例
作為普通 TypeScript 類別使用
import { WeatherClient } from '@agentic/stdlib'
// 需要設定環境變數 WEATHER_API_KEY (可從weatherapi.com免費獲取)
const weather = new WeatherClient()
const result = await weather.getCurrentWeather({
q: 'San Francisco'
})
console.log(result)
作為 LLM 工具使用 (Vercel AI SDK 示例)
// SDK 特定導入
import { openai } from '@ai-sdk/openai'
import { generateText } from 'ai'
import { createAISDKTools } from '@agentic/ai-sdk'
// SDK 無關導入
import { WeatherClient } from '@agentic/stdlib'
const weather = new WeatherClient()
const result = await generateText({
model: openai('gpt-4o-mini'),
// 關鍵行:使用@agentic/ai-sdk適配器
tools: createAISDKTools(weather),
toolChoice: 'required',
prompt: 'What is the weather in San Francisco?'
})
console.log(result.toolResults[0])
混合使用多個工具
import { SerperClient, WikipediaClient, FirecrawlClient } from '@agentic/stdlib'
import { createAIFunction } from '@agentic/core'
import { z } from 'zod'
const googleSearch = new SerperClient()
const wikipedia = new WikipediaClient()
const firecrawl = new FirecrawlClient()
const result = await generateText({
model: openai('gpt-4o-mini'),
// 這個例子使用了來自4個不同來源的工具
tools: createAISDKTools(
googleSearch,
wikipedia,
// 從firecrawl客戶端的AI功能集中選擇單個功能
firecrawl.functions.pick('firecrawl_search'),
// 創建自定義AI功能
createAIFunction({
name: 'think',
description: `Use this tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.`,
inputSchema: z.object({
thought: z.string().describe('A thought to think about.')
}),
execute: ({ thought }) => thought
})
),
prompt: 'What year did Jurassic Park the movie come out, and what else happened that year?'
})
支援的工具和服務
項目提供了 50+ 個實用工具,涵蓋以下類別:
🔍 搜尋和資訊檢索
| 工具 |
包名 |
描述 |
| Brave Search |
@agentic/brave-search |
Brave 搜尋 API |
| Bing |
@agentic/bing |
微软 Bing 搜尋 API |
| DuckDuckGo |
@agentic/duck-duck-go |
DuckDuckGo 搜尋 |
| Google Custom Search |
@agentic/google-custom-search |
谷歌自定義搜尋 |
| Serper |
@agentic/serper |
Serper 搜尋 API |
| SerpAPI |
@agentic/serpapi |
SerpAPI 搜尋服務 |
| Tavily |
@agentic/tavily |
Tavily 搜尋 API |
| Exa |
@agentic/exa |
Exa 搜尋 API |
📚 知識和研究
| 工具 |
包名 |
描述 |
| Wikipedia |
@agentic/wikipedia |
維基百科 API |
| Wikidata |
@agentic/wikidata |
維基數據訪問 |
| ArXiv |
@agentic/arxiv |
ArXiv 學術論文 |
| Wolfram Alpha |
@agentic/wolfram-alpha |
Wolfram Alpha 計算引擎 |
| HackerNews |
@agentic/hacker-news |
Hacker News API |
🌐 網頁抓取和處理
| 工具 |
包名 |
描述 |
| Firecrawl |
@agentic/firecrawl |
網頁抓取和爬蟲 |
| Jina |
@agentic/jina |
Jina Reader |
| Diffbot |
@diffbot |
網頁結構化提取 |
☁️ 雲服務和文檔
| 工具 |
包名 |
描述 |
| Google Drive |
@agentic/google-drive |
谷歌雲端硬碟 |
| Google Docs |
@agentic/google-docs |
谷歌文檔 |
| Notion |
@agentic/notion |
Notion API |
| Airtable |
@agentic/airtable |
Airtable 數據庫 |
🌦️ 天氣和環境
| 工具 |
包名 |
描述 |
| Weather |
@agentic/weather |
天氣 API |
| Open Meteo |
@agentic/open-meteo |
開放天氣數據 |
💼 商業和數據
| 工具 |
包名 |
描述 |
| Apollo |
@agentic/apollo |
Apollo 銷售工具 |
| Clearbit |
@agentic/clearbit |
公司數據 API |
| Hunter |
@agentic/hunter |
郵箱查找工具 |
| People Data Labs |
@agentic/people-data-labs |
人員數據 API |
| Polygon |
@agentic/polygon |
金融市場數據 |
🎨 創意和媒體
| 工具 |
包名 |
描述 |
| Midjourney |
@agentic/midjourney |
AI 圖像生成 |
| YouTube |
@agentic/youtube |
YouTube API |
📱 社交和通信
| 工具 |
包名 |
描述 |
| Twitter |
@agentic/twitter |
Twitter API |
| Slack |
@agentic/slack |
Slack API |
| Twilio |
@agentic/twilio |
Twilio 通信 |
| Reddit |
@agentic/reddit |
Reddit API |
💻 開發和工具
| 工具 |
包名 |
描述 |
| Calculator |
@agentic/calculator |
數學計算器 |
| E2B |
@agentic/e2b |
代碼執行環境 |
| MCP Tools |
@agentic/mcp |
MCP 伺服器支援 |
架構設計
核心概念
- AIFunctionLike: 可以是任何 agentic 客戶端實例、從客戶端函數集中選擇的單個 AIFunction,或透過 createAIFunction 手動創建的 AI 功能
- AIFunctionSet: AI 功能的集合,提供靈活的函數管理
- 適配器模式: 為不同的 AI SDK 提供統一的介面
擴展性
- 支援 OpenAPI 規範自動生成工具客戶端
- 支援自定義 AI 功能創建
- 支援 MCP 伺服器整合
- 支援函數組合和選擇
安裝和使用
# 安裝核心庫
npm install @agentic/core
# 安裝標準工具庫
npm install @agentic/stdlib
# 安裝特定 AI SDK 適配器
npm install @agentic/ai-sdk # Vercel AI SDK
npm install @agentic/langchain # LangChain
npm install @agentic/llamaindex # LlamaIndex
總結
Agentic 是一個功能強大、設計精良的 AI 工具標準庫,為 TypeScript 開發者提供了構建 AI 應用的完整工具鏈。它的設計理念是 "一次編寫,處處運行",讓開發者能夠在不同的 AI 框架之間無縫切換,同時提供豐富的預建工具來加速 AI 應用開發。