# OpenAI Agents SDK

Source: https://aiand-docs-staging.pages.dev/ja/integrations/openai-agents/

[OpenAI Agents SDK](https://github.com/openai/openai-agents-python) (Python) と JS 版は、`OpenAI` クライアントをカスタム設定するだけで ai& と接続できます。

## セットアップ

```bash
pip install openai-agents
```

```python
from agents import Agent, Runner, ModelSettings
from agents.models.openai_chatcompletions import OpenAIChatCompletionsModel
from openai import AsyncOpenAI

client = AsyncOpenAI(
    base_url="https://api.aiand.com/v1",
    api_key="sk-your-api-key",
)

model = OpenAIChatCompletionsModel(
    model="google/gemma-4-31b-it",
    openai_client=client,
)
```

## シンプルなエージェント

```python
agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant. Always reply concisely.",
    model=model,
)

result = await Runner.run(agent, "What is the capital of France?")
print(result.final_output)
```

## ツール付きエージェント

```python
from agents import function_tool

@function_tool
def get_weather(city: str) -> str:
    """Get current weather for a city."""
    return f"Sunny in {city}, 22°C"

agent = Agent(
    name="WeatherBot",
    instructions="Help the user with weather questions.",
    model=model,
    tools=[get_weather],
)

result = await Runner.run(agent, "What's the weather in Tokyo?")
print(result.final_output)
```

## ハンドオフとマルチエージェント

Agents SDK のハンドオフパターンも同じ要領で動きます — `Agent(...)` に `handoffs=[other_agent]` を渡します。ai& 固有の設定は不要です。

<Aside type="note">
  Agents SDK は内部で `chat.completions` を利用しているため、ai& のすべての機能 (ツール呼び出し、構造化出力、`file_id` 経由のビジョン) が利用可能です。
</Aside>
