1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

概要

SpringのA2Aのサンプルコードが公開されている。
エージェントは、生成AIが不可欠なので、無償で使用できる「さくらのAI Engine」に接続して、サンプルの動作を確かめる。

サンプル概要

image.png
ホストエージェントがユーザーのリクエスト(天気情報やAirbnb検索)を受け取り、専門のリモートエージェント(天気エージェント、Airbnbエージェント)にタスクを委譲するというもの。

サンプルからの変更点

  • pom.xmlのOpenAIスターターを変更
  • application.propertiesを「さくらのAI Engine」接続用に変更(spring.ai.openai.base-urlがagentによって少し違うので注意)

pom.xml

変更前

		<dependency>
			<groupId>org.springframework.ai</groupId>
			<artifactId>spring-ai-starter-model-openai-sdk</artifactId>
		</dependency>

変更後

		<dependency>
			<groupId>org.springframework.ai</groupId>
			<artifactId>spring-ai-starter-model-openai</artifactId>
		</dependency>

host-agent下のapplication.properties

変更前

## OpenAI SDK
spring.ai.openai-sdk.api-key=${OPENAI_API_KEY}
spring.ai.openai-sdk.chat.options.model=gpt-5-mini-2025-08-07
spring.ai.openai-sdk.chat.options.temperature=1.0

変更後

## OpenAI SDK
spring.ai.openai.base-url=https://api.ai.sakura.ad.jp
spring.ai.openai.api-key=${SAKURA_API_KEY}
spring.ai.openai.chat.options.model=preview/gemma-4-31B-it

host-agent以外のagent下application.properties

変更前

## OpenAI SDK
spring.ai.openai-sdk.api-key=${OPENAI_API_KEY}
spring.ai.openai-sdk.chat.options.model=gpt-5-mini-2025-08-07
spring.ai.openai-sdk.chat.options.temperature=1.0

変更後

## OpenAI SDK
spring.ai.openai.base-url=https://api.ai.sakura.ad.jp/v1
spring.ai.openai.api-key=${SAKURA_API_KEY}
spring.ai.openai.chat.options.model=preview/gemma-4-31B-it

使い方

使い方は上記のサイト通り。
VSCodeのpowershellでホストエージェントにリクエストした例を載せる。
以下のコマンドを実行した

curl.exe --% -X POST http://localhost:10000/host/chat -H "Content-Type: application/json" -d "{\"message\": \"What is the weather in Tokyo?\"}"

東京の気温が返っていることを確認できる
image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?