React agent loop

From MarceloClaro/OpenCode_Ecosystem · View interactive version

React agent loop is an AI agent skill from the GitHub repository MarceloClaro/OpenCode_Ecosystem. React Agent Loop skill for the OpenCode ecosystem

How to use this skill

Skill file

ReAct Agent Loop — Ciclo Thought -> Action -> Observation

Origem

Extraido de SandeClaw (specs/agent-loop.md, PRD.md secao 6.2).

E a engrenagem central do SandeClaw: recebe input bruto, submete ao LLM

(Thought), executa ferramentas (Action+Observation), repete ate resposta final.

Como Funciona

Loop com hard limit de iteracoes que evita loops infinitos:

User Input ──> [System Prompt + Tools]
                    |
               ┌────────────────────┐
               │  LLM.chat()        │<──┐
               │  Thought/Action    │   │
               └───────┬────────────┘   │
                       │                │
               ┌───────▼────────────┐   │
               │  Tool call?        │   │
               │  SIM: executa tool │   │ Observation
               │  NAO: resposta     │   │ injetada no
               │  final             │   │ contexto
               └───────┬────────────┘   │
                       │                │
               ┌───────▼────────────┐   │
               │  iter >= MAX?      │───┘
               │  SIM: break        │
               │  NAO: continua     │
               └────────────────────┘

Cada iteracao registra log estruturado:

[Iter 1] ACTION: write_file({"path": "teste.txt", "content": "Ola"})
[Iter 1] OBSERVATION: Arquivo 'teste.txt' criado (3 bytes)
[Iter 2] FINAL: Arquivo criado com sucesso!

Hard limit: MAX_ITERATIONS (default 5) impede billing infinito. Se atingido,

retorna mensagem de erro controlada em vez de quebrar.

Tratamento de erros:

Valor para OpenCode

reasoning-orchestrator, cora-debate, etc.

Uso

from skills.react_agent_loop.scripts.agent_loop import (
    AgentLoop, ToolRegistry, FileWriterTool, BashTool
)
from skills.provider_factory.scripts.provider_factory import ProviderFactory

llm = ProviderFactory.from_env("LLM_")
tools = ToolRegistry()
tools.register(FileWriterTool())
tools.register(BashTool())

loop = AgentLoop(llm_client=llm, tool_registry=tools, max_iterations=5)
answer = loop.run("Liste os arquivos .py no diretorio atual")
print(answer)

Ficheiros

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.