> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# ツール

> 検証付きのローカルツール、手動ツール、進捗を返すツールを定義します。

エージェントがアプリケーションのデータを読み取る、内部サービスを呼び出す、または処理を実行する場合にツールを使います。Agent SDKはツールとの境界を検証し、アプリケーション内でツールコードを実行します。

## ローカルツールを定義する

`defineTool()`では、説明、任意のJSONパラメーター、実行時バリデーター、タイムアウト、`execute()`関数を指定できます。

```typescript theme={null}
import { defineTool } from "@phaseo/agent-sdk";

const fetchTicket = defineTool({
  id: "fetch-ticket",
  description: "Load one internal support ticket.",
  parameters: {
    type: "object",
    properties: {
      ticketId: { type: "string" },
    },
    required: ["ticketId"],
    additionalProperties: false,
  },
  timeoutMs: 3_000,
  async execute(input: { ticketId: string }, context) {
    const response = await fetch(
      `https://internal.example/tickets/${input.ticketId}`,
      { signal: context.signal },
    );

    return response.json();
  },
});
```

タイムアウトになると、ランタイムは`context.signal`を中断し、実行を失敗として記録してタイムアウトエラーを再スローします。

スキーマには関数、または`parse()`か`safeParse()`を公開するオブジェクトを使えます。モデルの引数やツールの結果が無効な場合、ツール境界を越える前にエラーになります。

## アプリケーション内で処理を実行する

SDKプロセスではなくアプリケーション側で処理を行う場合は、`execute: false`を設定します。`toolOutputs`に結果を指定して一時停止した実行を再開します。

対話型ツールでは、`onToolCalled`から`null`を返します。実行再開後、`onResponseReceived`で渡された応答を検証または変換できます。

## 進捗を通知する

非同期ジェネレーターは最終結果を返す前に、途中経過を順に返せます。

```typescript theme={null}
const indexRepository = defineTool({
  id: "index-repository",
  async *execute(input: { path: string }) {
    yield { phase: "scan" };
    yield { phase: "embed" };
    return { indexed: 248 };
  },
});
```

進捗は`tool.preliminary_result`イベントとステップの`preliminaryResults`から取得できます。

## 独立したツールを並行実行する

1回のモデルターンで複数の独立したツールを安全に呼び出せる場合は、同時実行数を設定します。

```typescript theme={null}
const agent = createAgent({
  id: "research-agent",
  toolExecution: {
    toolConcurrency: 3,
  },
  tools: [fetchDocs, fetchStatus, fetchIncidents],
});
```

ローカルでの実行が重なっても、ランタイムはツール結果メッセージの順序を維持します。

## 関連ガイド

* [実行を一時停止、承認、再開する](./agent-sdk-state-and-approval.mdx)
* [エージェントの結果をストリーミングする](./agent-sdk-streaming.mdx)
* [ローカルツールを並行して呼び出す](../../cookbook/agent-sdk-parallel-tools.mdx)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.