`isLoopFinished()`
isLoopFinished()
절대 트리거하지 않는 stop condition을 만들어 에이전트 루프가 자연스럽게 끝날 때까지(즉, 모델이 툴 호출을 멈출 때까지) 실행되도록 합니다. 기본적으로 ToolLoopAgent는 과도한 API 호출과 비용을 초래할 수 있는 폭주 루프를 막기 위한 안전장치로 isStepCount(20)을 사용합니다. 에이전트가 자연스럽게 종료될 것이라고 확신하거나 비용에 덜 민감하다면, isLoopFinished()는 그 제한을 제거하고 모델이 정말로 끝날 때까지 에이전트가 실행되도록 합니다.
출처: 문서
본문
import { ToolLoopAgent, isLoopFinished } from 'ai';
__PROVIDER_IMPORT__;
const agent = new ToolLoopAgent({
model: __MODEL__,
tools: {
// your tools
},
stopWhen: isLoopFinished(),
});
const result = await agent.generate({
prompt: 'Analyze this dataset and create a summary report',
});
Import
import { isLoopFinished } from "ai"
API Signature
Parameters (파라미터)
이 함수는 파라미터를 받지 않습니다.
Returns (반환값)
항상 false를 반환하는 StopCondition 함수로, 즉 stop condition을 절대 트리거하지 않습니다. 에이전트 루프는 자연적인 종료 조건을 통해서만 멈춥니다.
- 모델이 툴 호출을 멈추거나
execute함수가 없는 툴이 호출되거나- 툴 호출이 승인을 필요로 할 때
Examples (예제)
기본 사용법
에이전트가 끝날 때까지 실행되게 합니다.
import { ToolLoopAgent, isLoopFinished } from 'ai';
const agent = new ToolLoopAgent({
model: yourModel,
tools: yourTools,
stopWhen: isLoopFinished(),
});
다른 조건과 결합
isLoopFinished()를 다른 조건과 결합할 수 있습니다. isLoopFinished()는 절대 트리거하지 않으므로 다른 조건들은 여전히 적용됩니다.
import { ToolLoopAgent, isLoopFinished, hasToolCall } from 'ai';
const agent = new ToolLoopAgent({
model: yourModel,
tools: yourTools,
stopWhen: [isLoopFinished(), hasToolCall('finalAnswer')],
});
실제로는 이 맥락에서 큰 의미가 없습니다. 그냥 isLoopFinished()를 생략하면 되기 때문입니다.