画面上の「Weather Agent」をクリックし、「Write a message…」と書かれているところに「渋谷の天気を知りたい」と入れて送信すると、現時点(2025/3/31の午後6時)だと以下のような結果が返ってきます。後で説明しますが、これはopen-meteo.comという緯度経度から現在の天気を教えてくれるAPIの結果をもとに出力されています。
Shibuya's current weather is overcast with a temperature of 7.6°C, but it feels like 4.5°C due to the wind. The humidity is at 76%, and there is a wind speed of 11.3 km/h with gusts up to 29.9 km/h.
export const weatherAgent = new Agent({
name: 'Weather Agent',
instructions: `
You are a helpful weather assistant that provides accurate weather information.
Your primary function is to help users get weather details for specific locations. When responding:
- Always ask for a location if none is provided
- If the location name isn’t in English, please translate it
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
- Include relevant details like humidity, wind conditions, and precipitation
- Keep responses concise but informative
Use the weatherTool to fetch current weather data.
`,
model: openai('gpt-4o'),
tools: { weatherTool },
});
ここからWeather Agentについて以下のことがわかります。
instructionsで天気情報を提供することを命じられている
modelでopenaiの”gpt-4o”のAIモデル(LLM)を使用するように設定されている
toolsでweatherToolが指定されている
instructionsはそのAgentの基本動作を規定します。これをもとにAIモデル(openAIのgpt-4o)は何をユーザから聞き出し、何を実行し、何をユーザに提供するかをの指針を得ることができます。今回の例であれば天気を調べるにあたり必要な情報(location)を理解します。そして、天気の情報を得るために、weatherToolというツールを使えること、およびユーザに提供する情報に含めるべきこと(wind conditionsなども含める)や、形式(concise but informative)について理解します。
const weatherWorkflow = new Workflow({
name: 'weather-workflow',
triggerSchema: z.object({
city: z.string().describe('The city to get the weather for'),
}),
})
.step(fetchWeather)
.then(planActivities);
weatherWorkflow.commit();
import { AgentNetwork } from '@mastra/core';
import { openai } from '@mastra/openai';
// Create specialized agents
const webSearchAgent = new Agent({
name: 'Web Search Agent',
instructions: 'You search the web for information.',
model: openai('gpt-4o'),
tools: { /* web search tools */ },
});
const dataAnalysisAgent = new Agent({
name: 'Data Analysis Agent',
instructions: 'You analyze data and provide insights.',
model: openai('gpt-4o'),
tools: { /* data analysis tools */ },
});
// Create the network
const researchNetwork = new AgentNetwork({
name: 'Research Network',
instructions: 'Coordinate specialized agents to research topics thoroughly.',
model: openai('gpt-4o'),
agents: [webSearchAgent, dataAnalysisAgent],
});
// Use the network
const result = await researchNetwork.generate('Research the impact of climate change on agriculture');
console.log(result.text);
上記はMastraの公式のサンプルですがこのように、複数のAgentをAgentNetworkに集めて、’Research the impact of climate change on agriculture’というプロンプトから適切なAgentを自律的に選択しながら、気候変動の農業の影響を調査するタスクを実行します。
Macの場合、デフォルトでzipでダウンロードされるので、ダブルクリックで解凍します。すると「Visual Studio Code – Insiders.app」というファイルが出てくるので、それをダブルクリックすることで、VSCodeを起動することができます。通常のVSCodeはブルーのアイコンになっていますが、Insiders版はエメラルドグリーンのアイコンになっています。必要に応じて、アプリケーションフォルダに移動することで、Launchpadからも選択できる様になります。
実はアピリッツのサイトは現在「JIS X 8341-3:2016 適合レベルAAに準拠するWebサイト」を目指して改修を始めた段階となります。 そのため、現在は情報を入手できないユーザーがいた場合はお問い合わせなどで人的な対応をしつつ、徐々にアクセシビリティ対応したサイトになるように改修を進めております!