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应用开发。