# SDK TypeScript 和 Python 的类型化客户端,都从 AREX_API_KEY 读取密钥。 ## TypeScript research.run 创建 Run 并等待答案;research.create、get、wait、cancel 和 delete 可分步操作。错误均为 ArexError 的子类。 ### Shell ```bash npm install @arex-research/ts-sdk ``` ### TypeScript ```typescript import { Arex } from "@arex-research/ts-sdk"; const arex = new Arex(); // reads AREX_API_KEY const { results } = await arex.search("how are AI agents evaluated", { limit: 5 }); for (const { url } of results) { const page = await arex.contents(url, { maxCharacters: 4000 }); } const run = await arex.research.run("Compare agent evaluation benchmarks", { mode: "fast" }); console.log(run.result.answer); ``` ## Python 需要 Python 3.10 及以上。AsyncArex 提供相同的异步调用。 ### Shell ```bash pip install arex-python-sdk ``` ### Python ```python from arex import Arex with Arex() as arex: # reads AREX_API_KEY search = arex.search("how are AI agents evaluated", limit=5) for item in search.results: page = arex.contents(item.url, max_characters=4000) run = arex.research.run("Compare agent evaluation benchmarks", mode="fast") assert run.result is not None # always set once run() returns print(run.result.answer) ``` ## 作为 Agent 工具 在 Pi SDK 或 LangGraph 中把 SDK 调用封装成工具。 ### Pi SDK ```typescript import { Arex } from "@arex-research/ts-sdk"; const arex = new Arex(); // reads AREX_API_KEY export const arexTools = [ { name: "arex_search", description: "Search the web for ranked URLs and snippets.", parameters: { type: "object", properties: { query: { type: "string" }, limit: { type: "number" } }, required: ["query"], }, execute: async ({ query, limit = 5 }: { query: string; limit?: number }) => arex.search(query, { limit }), }, { name: "arex_contents", description: "Read clean markdown text from a public URL.", parameters: { type: "object", properties: { url: { type: "string" } }, required: ["url"], }, execute: async ({ url }: { url: string }) => arex.contents(url, { maxCharacters: 8000 }), }, { name: "arex_research", description: "Answer a question with cited web sources in one call.", parameters: { type: "object", properties: { query: { type: "string" } }, required: ["query"], }, execute: async ({ query }: { query: string }) => arex.research.run(query, { mode: "fast" }), }, ]; ``` ### LangGraph ```python from dataclasses import asdict from arex import Arex from langchain_core.tools import tool from langgraph.prebuilt import create_react_agent client = Arex() # reads AREX_API_KEY @tool def arex_search(query: str, limit: int = 5) -> dict: """Search the web for ranked URLs and snippets.""" return asdict(client.search(query, limit=limit)) @tool def arex_contents(url: str) -> str: """Read clean markdown text from a public URL.""" return client.contents(url, max_characters=8000).content @tool def arex_research(query: str) -> str: """Answer a research question with cited sources in one call.""" run = client.research.run(query, mode="fast") return run.result.answer if run.result else "" agent = create_react_agent("openai:gpt-4.1", tools=[arex_search, arex_contents, arex_research]) ``` [npm · @arex-research/ts-sdk](https://www.npmjs.com/package/@arex-research/ts-sdk) [PyPI · arex-python-sdk](https://pypi.org/project/arex-python-sdk/) [GitHub](https://github.com/AREX-Research/arex-sdk) [TypeScript Changelog](https://github.com/AREX-Research/arex-sdk/blob/main/ts/CHANGELOG.md) [Python Changelog](https://github.com/AREX-Research/arex-sdk/blob/main/python/CHANGELOG.md)