Koog 문서 한국어 번역 11: LLM 기반 플래너

·4분 읽기

원문: Koog 공식 문서

LLM 기반 플래너

LLM 기반 플래너는 LLM을 사용하여 계획을 생성하고 평가합니다. 문자열 기반 상태에서 동작하며, LLM 요청을 통해 각 단계를 실행합니다. 문자열 기반 상태란 에이전트 상태가 단일 문자열임을 의미합니다. 각 단계마다 에이전트는 초기 상태 문자열을 입력받아 최종 상태 문자열을 결과로 반환합니다.

참고 — 사전 준비

이 페이지의 예제는 OPENAI_API_KEY 환경 변수가 설정되어 있다고 가정합니다.

Koog는 두 가지 간단한 플래너를 제공합니다:

  • SimpleLLMPlanner 는 맨 처음에 한 번만 계획을 생성하고, 이후 계획이 완료될 때까지 그 계획을 따릅니다. 재계획(replanning)을 포함하려면 SimpleLLMPlanner를 확장하고 assessPlan 메서드를 재정의하여 에이전트가 언제 재계획을 수행할지를 지정합니다.
  • SimpleLLMWithCriticPlanner 는 LLM 요청을 통해 계획의 유효성을 검사하고 에이전트가 재계획해야 하는지 평가하는 assessPlan 메서드를 구현합니다.

다음 예제는 SimpleLLMPlanner를 사용하여 간단한 플래너 에이전트를 생성하는 방법을 보여줍니다:

Kotlin

1// Create the planner2val planner = SimpleLLMPlanner()34// Wrap it in a planner strategy5val strategy = AIAgentPlannerStrategy(6    name = "simple-planner",7    planner = planner8)910// Configure the agent11val agentConfig = AIAgentConfig(12    prompt = prompt("planner") {13        system("You are a helpful planning assistant.")14    },15    model = OpenAIModels.Chat.GPT4o,16    maxAgentIterations = 5017)1819// Create the planner agent20val agent = PlannerAIAgent(21    promptExecutor = simpleOpenAIExecutor(System.getenv("OPENAI_API_KEY")),22    strategy = strategy,23    agentConfig = agentConfig24)2526suspend fun main() {27    // Run the agent with a task28    val result = agent.run("Create a plan to organize a team meeting")29    println(result)30}

Java

1// Create the planner strategy with LLM-based planner2AIAgentPlannerStrategy<String, String, ?> strategy =3    AIAgentPlannerStrategy.builder("simple-planner")4        .llmBasedPlanner()5        .build();67// Create the OpenAI executor8var promptExecutor = PromptExecutor.builder()9    .openAI("OPENAI_API_KEY")10    .build();1112// Create the planner agent using AIAgent builder13AIAgent<String, String> agent = AIAgent.builder()14    .plannerStrategy(strategy)15    .promptExecutor(promptExecutor)16    .llmModel(OpenAIModels.Chat.GPT4o)17    .systemPrompt("You are a helpful planning assistant.")18    .maxIterations(50)19    .build();2021// Run the agent with a task22String result = agent.run("Create a plan to organize a team meeting");23System.out.println(result);

다음 단계