tinycodinglm / agentic /aiagent-0045.jsonl
winapiadmin's picture
Upload folder using huggingface_hub
1f3a244 verified
|
Raw History Blame
2.65 kB
opencode trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

What are ReAct, Plan-and-Execute, Tree-of-Thoughts and self-reflection planning strategies? Show plan-then-execute with re-planning. Include code examples.

Assistant

Planning patterns:

  • ReAct (Yao et al., 2022): Thought -> Action -> Observation loop
  • Plan-and-Execute: planner writes steps, executor runs them, re-plan on failure
  • Tree-of-Thoughts: branch multiple reasonings, score and keep best
  • Self-reflection: generate -> critique -> revise

Planning is an LLM call that returns steps; execution grounds them in tools.

python
def parse_steps(text: str) -> list[str]:
    return [ln.strip("- ").strip() for ln in text.splitlines() if ln.strip()][:10]

def execute_step(step: str, tools: dict) -> str:
    # route step to a tool; stub for example
    return f"done: {step}"

def synthesize(results: list[str]) -> str:
    return "\n".join(results)

def plan_and_execute(goal: str, llm, tools: dict) -> str:
    plan_text = llm.chat.completions.create(
        model="model-identifier-from-lm-studio",
        messages=[{"role": "user",
                   "content": f"Create a numbered step-by-step plan to: {goal}"}],
    ).choices[0].message.content or ""
    steps = parse_steps(plan_text)
    results: list[str] = []
    for step in steps:
        try:
            results.append(execute_step(step, tools))
        except Exception as e:
            # re-plan once with failure context
            fix = llm.chat.completions.create(
                model="model-identifier-from-lm-studio",
                messages=[{"role": "user",
                           "content": f"Step failed '{step}': {e}. Propose one alternative step."}],
            ).choices[0].message.content or step
            results.append(execute_step(fix.strip(), tools))
    return synthesize(results)

Note: do not hardcode model versions as facts (e.g. Python is 3.15 as of Oct 2026, not 3.12) - query the environment instead.