快速开始

几分钟内开始使用 Tarko。

前置要求

  • Node.js 18+
  • npm 或 pnpm

安装

创建新的 Agent(开发中)

🚧 开发中:使用 Tarko CLI 的最快方式即将推出:

npm create tarko  # 即将推出

安装 Tarko 包

目前请手动安装核心包:

npm install @tarko/agent

基本使用

1. 定义你的 Agent

基于真实示例创建 agent.ts 文件:

// 来自 multimodal/tarko/agent/examples/tool-calls/basic.ts
import { Agent, Tool, z, LogLevel } from '@tarko/agent';

const locationTool = new Tool({
  id: 'getCurrentLocation',
  description: "获取用户当前位置",
  parameters: z.object({}),
  function: async () => {
    return { location: 'Boston' };
  },
});

const weatherTool = new Tool({
  id: 'getWeather',
  description: '获取指定位置的天气信息',
  parameters: z.object({
    location: z.string().describe('位置名称,如城市名'),
  }),
  function: async (input) => {
    const { location } = input;
    return {
      location,
      temperature: '70°F (21°C)',
      condition: 'Sunny',
      precipitation: '10%',
      humidity: '45%',
      wind: '5 mph',
    };
  },
});

const agent = new Agent({
  model: {
    provider: 'volcengine',
    id: 'doubao-seed-1-6-vision-250815',
    apiKey: process.env.ARK_API_KEY,
  },
  tools: [locationTool, weatherTool],
  logLevel: LogLevel.DEBUG,
});

export default agent;

2. 运行你的 Agent

直接运行你的 Agent:

// 运行 Agent
const response = await agent.run("今天天气怎么样?");
console.log(response);

3. 流式示例

对于流式响应:

// 来自 multimodal/tarko/agent/examples/streaming/tool-calls.ts
const response = await agent.run({
  input: "今天天气怎么样?",
  stream: true,
});

for await (const chunk of response) {
  console.log(chunk);
}

环境变量

创建包含 API 密钥的 .env 文件:

# .env 文件
ARK_API_KEY=your-volcengine-api-key
OPENAI_API_KEY=your-openai-api-key
ANTHROPIC_API_KEY=your-anthropic-api-key

真实示例

探索仓库中的工作示例:

下一步

测试示例

测试示例是否工作:

# 克隆仓库
git clone https://github.com/bytedance/UI-TARS-desktop.git
cd UI-TARS-desktop/multimodal/tarko/agent

# 安装依赖
npm install

# 运行基础工具调用示例
npx tsx examples/tool-calls/basic.ts

# 运行流式示例
npx tsx examples/streaming/tool-calls.ts