AI
Strands
Quickstart
TypeScript
SDK
Series
Strands SDK 시리즈 3: 빠른 시작 — 첫 Strand 만들기
제 환경은 Node 20, pnpm 기준입니다. npm/yarn도 동일하게 적용됩니다.
설치
pnpm add strands
# or
npm i strands
첫 Strand
import { strand, tool } from strands;
const fetchWeather = tool({
name: fetchWeather,
run: async (city: string) => {
const res = await fetch(`https://wttr.in/${city}?format=j1`);
return res.json();
}
});
export const weatherStrand = strand({
name: weather,
steps: [
async (ctx) => {
const data = await ctx.run(fetchWeather, Seoul);
ctx.state.weather = data.current_condition?.[0];
return done;
}
]
});
실행
import { run } from strands;
import { weatherStrand } from ./weather;
const out = await run(weatherStrand);
console.log(out.state.weather);
다음 편에서는 상태/메모리, 실패/재시도, 타임아웃을 추가합니다.
