Skip to content

What is AI Agent

Translation in Progress

This page is being translated. Content below is a placeholder.

Definition

An AI Agent is not just an LLM (Large Language Model), but a system that can autonomously complete tasks.

Core formula:

Agent = LLM + Tools + Loop
  • LLM: The "brain" for reasoning and decision-making
  • Tools: Capabilities like reading files, executing commands, web search
  • Loop: Iteratively call LLM until task completion

Agent vs Chatbot

FeatureChatbotAgent
InteractionQ&ATask execution
CapabilitiesText generation onlyUse tools
AutonomyRequires each instructionCan plan and execute
StateStateless or simple contextComplex state management

Agent Capabilities

What can an Agent do?

  1. File operations: Read, write, edit code
  2. Command execution: Run shell commands
  3. Web interaction: Search, fetch pages
  4. Complex tasks: Multi-step reasoning and execution

Example: File Modification Task

User: "Fix the bug in src/utils.ts line 42"

Agent thinking:
1. Read src/utils.ts → understand code
2. Locate line 42 → identify issue
3. Decide fix → generate patch
4. Edit file → apply changes
5. Verify → check result

How gemini-cli Implements Agents

gemini-cli's Agent implementation is in packages/core/src/core/client.ts:

typescript
// Simplified structure
class GeminiClient {
  // Main loop
  async run(userMessage: string) {
    while (true) {
      // 1. Send to LLM
      const response = await this.chat.send(message)

      // 2. Check for tool calls
      if (response.hasToolCall()) {
        // 3. Execute tool
        const result = await this.executeTool(response.toolCall)
        // 4. Feed result back to LLM
        message = result
      } else {
        // 5. Done
        return response.text()
      }
    }
  }
}

Summary

  • Agent = LLM + Tools + Loop
  • Differs from chatbots by having tools and autonomy
  • Core is the "think → act → observe" loop

Next

Learn more about the pattern behind Agent reasoning: ReAct Pattern →

Learn AI Agent development through real source code