AI Agent Patterns — AI Web

AI Agent Patterns AI Agent adalah LLM yang bisa mengambil action secara otonom: panggil API, baca file, jalankan kode, navigasi web. Bukan hanya menjawab pertan

AI Agent Patterns

AI Agent adalah LLM yang bisa mengambil action secara otonom: panggil API, baca file, jalankan kode, navigasi web. Bukan hanya menjawab pertanyaan — tapi menyelesaikan tugas.

Agent Loop

// Simplified agent loop
async function agentLoop(task) {
  const messages = [
    { role: "system", content: "Kamu adalah agent yang bisa menggunakan tools." },
    { role: "user", content: task },
  ];

  while (true) {
    const response = await llm.chat({ messages, tools });

    // If model wants to use a tool
    if (response.tool_calls) {
      for (const call of response.tool_calls) {
        const result = await executeTool(call);
        messages.push({ role: "tool", content: result, tool_call_id: call.id });
      }
      continue; // Loop back to LLM with tool results
    }

    // Model is done — return final answer
    return response.content;
  }
}

Common Patterns

Guardrails

Yang akan kamu pelajari