Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

This PR implements the requested improvements to the Auto-coder-agent_Cursor_Roo_code repository:

Improvements Added

Documentation Enhancements

  • Added detailed installation guide with prerequisites and troubleshooting
  • Created comprehensive usage documentation with examples
  • Added metrics management overview with key indicators and analysis methods
  • Implemented feedback loop documentation with structured processes

Code Quality Improvements

  • Added unit test framework with sample tests for logging and memory bank
  • Created test README with instructions for running and extending tests
  • Implemented test coverage reporting setup

Community Engagement

  • Added contribution guidelines with clear processes
  • Created code of conduct for community standards
  • Added root-level CONTRIBUTING.md for easy discovery

Project Structure

  • Organized documentation in logical directories
  • Improved discoverability of key components
  • Added bilingual support (Japanese/English) throughout documentation

These improvements address all the requested areas from the initial proposal and provide a solid foundation for future development and community engagement.

Link to Devin run: https://app.devin.ai/sessions/55297f980ea347a5b18e1b85254b697f
Requested by: ShunsukeHayashi

- Added detailed installation and usage guides
- Created contribution guidelines and code of conduct
- Implemented test framework with sample tests
- Added metrics and feedback documentation
- Improved project structure with better organization

Co-Authored-By: Shunsuke Hayashi <supernovasyun@gmail.com>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

Original prompt from Shunsuke:

https://github.com/ShunsukeHayashi/Auto-coder-agent_Cursor_Roo_code


プロジェクト「Auto-coder-agent_Cursor_Roo_code」を改善するための提案を以下にまとめました。

1. **ドキュメントの充実**:
   - **詳細なセットアップ手順**: 依存関係や環境設定の手順を詳しく記載し、新規ユーザーが容易に導入できるようにします。
   - **使用例の追加**: 具体的な使用例やチュートリアルを提供し、ユーザーが機能を理解しやすくします。

2. **コードの品質向上**:
   - **コードレビューの実施**: 定期的なコードレビューを行い、バグの早期発見やコードの最適化を図ります。
   - **ユニットテストの追加**: 主要な機能に対するユニットテストを作成し、コードの信頼性を高めます。

3. **コミュニティの活性化**:
   - **貢献ガイドラインの作成**: 新たな貢献者が参加しやすいよう、貢献方法やルールを明確にします。
   - **ディスカッションの促進**: GitHubのDiscussions機能を活用し、ユーザー間の情報交換やフィードバックを促します。

4. **機能の拡張**:
   - **新機能の追加**: ユーザーの要望やフィードバックを取り入れ、プロジェクトの機能を拡充します。
   - **既存機能の改善**: パフォーマンスの最適化やユーザーインターフェースの改善を行い、使いやすさを向上させます。

これらの改善を通じて、プロジェクトの品質とユーザー体験を向上させることが期待できます。 
PLAYBOOK_md: Xinobi
◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
# Jinja2 Playbook Template

## Procedure

{% for step in procedures %}
{{ loop.index }}. **{{ step.title }}**

   - {{ step.description }}

{% endfor %}

## Advice & Pointers

{% for advice in advice_pointers %}
- {{ advice }}
{% endfor %}

## Forbidden Actions

{% for forbidden_action in forbidden_actions %}
- ⚠️ **{{ forbidden_action }}**
{% endfor %}

## User Intent Interpretation

◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢

**User Input:**

{{ user_input }}


◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢

### Abstracted Intent
- Original Intent: {{ original_intent }}
- Want or Need Intent: {{ want_or_need_intent }}

### Goals

{% for goal in fixed_goals %}
- ✅ **{{ goal }}**
{% endfor %}

## Task Breakdown

{% for task in tasks %}
- [Task {{ loop.index }}] {{ task }}
{% endfor %}

## Agent Execution Stack

{% for task in agent_tasks %}
{{ loop.index }}. Task: **{{ task.name }}**
   - Assigned Agent: {{ task.agent }}
   - Description: {{ task.description }}
   - Expected Outcome: {{ task.outcome }}
{% endfor %}

## Visual Guidelines

### Invalid Format (NG)
```xml
<thinking>
ここにコンテキストが挿入されます。
</thinking>

Valid Format (OK)

◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
ここにコンテキストが挿入されます。
◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢

Environment & Initialization Check

  • Operating System: {{ system_information.operating_system }}
  • Default Shell: {{ system_information.default_shell }}
  • Home Directory: {{ system_information.home_directory }}
  • Current Working Directory: {{ system_information.current_working_directory }}

Continuous Execution & Testing

  • Unit Testing: {{ testing.unit_testing }}
  • Overall Testing: {{ testing.overall_testing }}
  • Continuous Execution: {{ continuous_execution }}

Git Usage

  • Commit Message: AIが実行した内容

◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢

I'll help you create a comprehensive agent prompt using OpenAI API based on the information you've provided.

I'll create a well-structured agent prompt file that implements the "generic agentive workflow" concept described in the requirements. This will include:
A clear definition of the agent's role and responsibilities
Implementation of the Working Backwards methodology
Step-back questioning approach
Integration of tools and capabilities
API implementation patterns
Create a comprehensive generic agent prompt that implements the Working Backwards methodology === """ Generic Agentive Workflow Agent Prompt
This module defines the prompt templates for a generic agent that uses a
Working Backwards methodology to solve problems step by step.
"""

System prompt that defines the agent's role, methodology and approach
SYSTEM_PROMPT = """

Generic Agentive Workflow Agent
You are an advanced AI agent designed to achieve goals through systematic reverse-engineering of solutions.

METHODOLOGY: WORKING BACKWARDS
Your primary methodology is "Working Backwards" - you start with the end goal and work backward to the initial state by:

First clarifying the exact goal state in concrete detail
Using step-back questioning to identify prerequisites for each step
Working backwards until you reach actions that can be taken from the current state
Reordering these steps to create a forward execution plan
Executing this plan step by step using available tools
YOUR ROLE AND RESPONSIBILITIES
Problem Analyzer: Break down complex problems into manageable steps
Plan Creator: Design executable plans with clear milestones
Tool Operator: Effectively utilize available tools to accomplish tasks
Information Seeker: Gather necessary information at each step
Execution Monitor: Track progress and adapt the plan as needed
YOUR CORE ABILITIES
Step-back Questioning: Identifying what must happen immediately before each goal state
Recursive Planning: Breaking down complex steps into simpler ones
Information Integration: Combining information across steps into a coherent plan
Tool Selection: Choosing the right tool for each step based on context
Adaptive Execution: Adjusting the plan based on results of each step
OPERATIONAL FRAMEWORK
I operate through the following formula:

F(Generic Agentive Workflow) =
Goal(G) → Step-back questions to trace backwards (Z→Y→X→...→A) →
Reorder steps for execution (A→B→C→...→Z) →
∫(Each step clarified through OpenAI API reasoning + tool use)d(step) →
Integrated execution plan (Result)

KEY PRINCIPLES
Always clarify the final goal state first
At each step, ask "What must be true immediately before this can happen?"
Identify tools needed for each step
Prioritize concrete, actionable steps
Adapt the plan based on feedback from each step's execution """
Next step prompt that guides the agent through the working backwards process
NEXT_STEP_PROMPT = """

Current Status Review
Goal State
{goal_state}

Progress So Far
{current_progress}

Current State
{current_state}

Working Backwards Analysis
Looking at our goal, what is the immediate prerequisite state that must exist right before we achieve the final result?

What tools or information do we need to move from that prerequisite state to the goal state?

Continue working backwards - what must be true before that prerequisite can be achieved?

Have we reached actions that can be taken from our current state? If not, continue the step-back questioning.

Based on this analysis, what is the next concrete action to take using available tools?

Next Action Decision
Given the available tools and our current position in the plan, what is the most appropriate next action? Be specific about:

Which tool to use
What parameters to provide
What information to gather
How this advances our plan """
Planning template for creating a structured plan
PLANNING_TEMPLATE = """

Comprehensive Working Backwards Plan
Final Goal
{goal}

Current State
{current_state}

Working Backwards Analysis
{backwards_analysis}

Forward Execution Plan
{forward_plan}

Tools Required
{tools_required}

Success Criteria
{success_criteria}

Potential Challenges
{potential_challenges}

Monitoring Approach
{monitoring_approach}
"""

Execution status template for tracking progress
EXECUTION_STATUS_TEMPLATE = """

Execution Status
Goal: {goal}
Plan Steps:
{plan_steps}

Current Position:
{current_step}

Completed Steps:
{completed_steps}

Pending Steps:
{pending_steps}

Observations:
{observations}

Adjustments Needed:
{adjustments}
"""

Human-in-the-loop feedback request template
FEEDBACK_REQUEST_TEMPLATE = """

Feedback Request
I've reached a point where human input would be valuable:

Current Goal:
{goal}

Plan So Far:
{plan}

Current Challenge:
{challenge}

Specific Questions:
{questions}

Possible Paths Forward:
{options}

What direction would you like me to take?
"""

Tools error handling template
TOOL_ERROR_TEMPLATE = """

Tool Execution Error
Tool Used:
{tool_name}

Attempted Operation:
{operation}

Error Encountered:
{error}

Impact on Plan:
{impact}

Recommended Recovery:
{recovery_steps}

Question for User:
{user_question} """

Create a generic agent implementation that uses the Working Backwards methodology === """ Generic Agent implementation that uses a Working Backwards methodology.
This agent starts from the goal state and works backwards to create a plan,
then executes the plan step by step using available tools.
"""

from typing import Dict, List, Optional, Any, Literal

from pydantic import Field, model_validator

from app.agent.toolcall import ToolCallAgent
from app.logger import logger
from app.prompt.generic_agent import (
SYSTEM_PROMPT,
NEXT_STEP_PROMPT,
PLANNING_TEMPLATE,
EXECUTION_STATUS_TEMPLATE
)
from app.schema import Message, ToolCall, AgentState
from app.tool import ToolCollection, Terminate

class GenericAgent(ToolCallAgent):
"""
An agent that implements the Working Backwards methodology to solve problems.

This agent first clarifies the goal, then uses step-back questioning to identify
prerequisites for each step, working backwards until reaching actions that can be
taken from the current state. It then reorders these steps and executes them.
"""

name: str = "generic_agent"
description: str = "A general-purpose agent that uses Working Backwards methodology to solve tasks"

system_prompt: str = SYSTEM_PROMPT
next_step_prompt: str = NEXT_STEP_PROMPT

Tracking goal and plan

goal_state: str = Field(default="")
current_state: str = Field(default="")
current_progress: str = Field(default="No progress yet. Planning phase.")

Working backwards tracking

backwards_steps: List[Dict[str, Any]] = Field(default_factory=list)
forward_plan: List[Dict[str, Any]] = Field(default_factory=list)

Execution tracking

plan_ready: bool = Field(default=False)
current_step_index: int = Field(default=0)
completed_steps: List[Dict[str, Any]] = Field(default_factory=list)
pending_steps: List[Dict[str, Any]] = Field(default_factory=list)

Additional state for flexibility

state_variables: Dict[str, Any] = Field(default_factory=dict)

max_steps: int = 30

def init(self, **data):
"""Initialize the GenericAgent with custom tools if provided."""
# If no tools are provided, add a basic set
if "available_tools" not in data:
data["available_tools"] = ToolCollection([Terminate()])

# Ensure Terminate tool is always available
terminate_tool_exists = False
for tool in data.get("available_tools", []):
    if isinstance(tool, Terminate) or (hasattr(tool, "name") and tool.name == "terminate"):
        terminate_tool_exists = True
        break
        
if not terminate_tool_exists and "available_tools" in data:
    data["available_tools"].add_tool(Terminate())
    
super().__init__(**data)

@model_validator(mode="after")
def validate_agent_state(self) -> "GenericAgent":
"""Validate the agent's state and ensure all required fields are initialized."""
if not self.goal_state:
self.goal_state = "Not yet specified"

if not self.current_state:
    self.current_state = "Initial state"
    
# Ensure special tools are properly tracked
terminate_names = ["terminate", "finish", "complete"]
self.special_tool_names = list(set(self.special_tool_names + [
    tool for tool in terminate_names if tool in [t.name for t in self.available_tools.tools]
]))
    
return self

async def set_goal(self, goal: str) -> str:
"""
Set the agent's goal state.

Args:
    goal: The goal state the agent should work towards.
    
Returns:
    A confirmation message.
"""
self.goal_state = goal
logger.info(f"Goal set: {goal}")

# Clear previous plan if it exists
self.backwards_steps = []
self.forward_plan = []
self.plan_ready = False
self.current_step_index = 0
self.completed_steps = []
self.pending_steps = []

# Add goal setting message to memory
self.update_memory("system", f"Goal set: {goal}")

# Generate initial clarification of the goal
goal_clarification_msg = Message.user_message(
    f"My goal is: {goal}\n\nPlease clarify this goal in concrete, specific terms "
    f"and begin the Working Backwards analysis to determine how to achieve it."
)
self.memory.add_message(goal_clarification_msg)

return f"Goal set to: {goal}. I will now analyze this goal and work backwards to create a plan."

async def think(self) -> bool:
"""
Process the current state and decide the next action using Working Backwards methodology.

Returns:
    bool: True if there are actions to take, False otherwise.
"""
formatted_prompt = NEXT_STEP_PROMPT.format(
    goal_state=self.goal_state,
    current_progress=self.current_progress,
    current_state=self.current_state
)

# Add next step prompt to memory
self.messages.append(Message.user_message(formatted_prompt))

# Get response with tool options
result = await super().think()

# If we're done planning but haven't started executing, organize the plan
if not self.plan_ready and self.backwards_steps and not self.tool_calls:
    await self._organize_plan()
    
return result

async def act(self) -> str:
"""
Execute decided actions and update plan progress.

Returns:
    str: Result of the action.
"""
# Execute the action
result = await super().act()

# Update plan status if we have a plan
if self.plan_ready and self.forward_plan:
    # Find the current step and mark it as completed
    if self.current_step_index < len(self.forward_plan):
        completed_step = self.forward_plan[self.current_step_index].copy()
        completed_step["result"] = result
        self.completed_steps.append(completed_step)
        
        # Update progress tracking
        self.current_progress = (
            f"Completed {len(self.completed_steps)}/{len(self.forward_plan)} steps. "
            f"Last completed: {completed_step.get('description', 'Step')}"
        )
        
        # Move to next step
        self.current_step_index += 1
        
        # Update pending steps
        self.pending_steps = self.forward_plan[self.current_step_index:] if self.current_step_index < len(self.forward_plan) else []
        
        logger.info(f"Completed step {self.current_step_index}/{len(self.forward_plan)}: {result[:100]}...")

return result

async def run(self, request: Optional[str] = None) -> str:
"""
Execute the agent's main workflow.

Args:
    request: Initial request or goal for the agent.
    
Returns:
    str: Summary of execution results.
"""
if request:
    await self.set_goal(request)
    
return await super().run()

async def _organize_plan(self) -> None:
"""
Organize the backwards steps into a forward execution plan.
This reverses the order of steps and prepares them for execution.
"""
if not self.backwards_steps:
return

# Prepare to create the forward plan using LLM
planning_prompt = PLANNING_TEMPLATE.format(
    goal=self.goal_state,
    current_state=self.current_state,
    backwards_analysis="\n".join([f"{i+1}. {step.get('description', 'Step')}" for i, step in enumerate(self.backwards_steps)]),
    forward_plan="To be determined",
    tools_required=", ".join([tool.name for tool in self.available_tools.tools]),
    success_criteria="To be determined",
    potential_challenges="To be determined",
    monitoring_approach="To be determined"
)

# Ask LLM to create the forward plan
messages = self.messages + [Message.user_message(planning_prompt)]
response = await self.llm.ask(messages=messages)

# Parse the response to extract the forward plan
# This is simplified and might need more robust parsing in a real implementation
self.update_memory("assistant", response)

# Create simple forward plan by reversing backwards steps
self.forward_plan = list(reversed(self.backwards_steps))

# Mark the plan as ready
self.plan_ready = True
self.pending_steps = self.forward_plan.copy()

# Log the plan creation
plan_summary = "\n".join([f"{i+1}. {step.get('description', 'Step')}" for i, step in enumerate(self.forward_plan)])
logger.info(f"Forward execution plan created with {len(self.forward_plan)} steps:\n{plan_summary}")

# Add the plan to memory
self.update_memory("system", f"Forward execution plan created with {len(self.forward_plan)} steps:\n{plan_summary}")

def _update_execution_status(self) -> str:
"""
Create a formatted status of the execution plan.

Returns:
    str: Formatted execution status.
"""
if not self.plan_ready:
    return "Plan is still being formulated."
    
plan_steps = "\n".join([f"{i+1}. {step.get('description', 'Step')}" for i, step in enumerate(self.forward_plan)])
completed_steps = "\n".join([f"✓ {i+1}. {step.get('description', 'Step')}" for i, step in enumerate(self.completed_steps)])
pending_steps = "\n".join([f"○ {self.current_step_index+i+1}. {step.get('description', 'Step')}" for i, step in enumerate(self.pending_steps)])

current_step = (
    f"Currently executing step {self.current_step_index+1}/{len(self.forward_plan)}: "
    f"{self.forward_plan[self.current_step_index].get('description', 'Step')}"
    if self.current_step_index < len(self.forward_plan) else "All steps completed."
)

return EXECUTION_STATUS_TEMPLATE.format(
    goal=self.goal_state,
    plan_steps=plan_steps,
    current_step=current_step,
    completed_steps=completed_steps if self.completed_steps else "None yet.",
    pending_steps=pending_steps if self.pending_steps else "None remaining.",
    observations=self.current_progress,
    adjustments="None required at this time."
)

def add_backward_step(self, description: str, tools_needed: List[str], prerequisites: List[str]) -> None:
"""
Add a step to the backwards planning process.

Args:
    description: Description of this step
    tools_needed: Tools required for this step
    prerequisites: What must be true before this step
"""
self.backwards_steps.append({
    "description": description,
    "tools_needed": tools_needed,
    "prerequisites": prerequisites
})

async def get_execution_status(self) -> str:
"""
Get the current execution status.

Returns:
    str: Formatted execution status.
"""
return self._update_execution_status()

===


Update the init.py file to include the new GenericAgent === from app.agent.base import BaseAgent from app.agent.planning import PlanningAgent from app.agent.react import ReActAgent from app.agent.swe import SWEAgent from app.agent.toolcall import ToolCallAgent from app.agent.generic_agent import GenericAgent
all = [ "BaseAgent", "PlanningAgent", "ReActAgent", "SWEAgent", "ToolCallAgent", "GenericAgent", ]

Create an example usage of the GenericAgent === """ Example usage of the GenericAgent with the Working Backwards methodology.
This example demonstrates how to create and use a GenericAgent to solve
a task by working backwards from the goal.
"""

import asyncio
from typing import List

from app.agent.generic_agent import GenericAgent
from app.tool import Bash, GoogleSearch, ToolCollection, Terminate, PythonExecute

async def run_generic_agent_example(goal: str) -> None:
"""
Run an example of the GenericAgent with a specific goal.

Args:
goal: The goal to achieve
"""

Create a tool collection with useful tools

tools = ToolCollection([
Bash(),
GoogleSearch(),
PythonExecute(),
Terminate()
])

Create the generic agent

agent = GenericAgent(
name="task_solver",
description="Solves tasks using Working Backwards methodology",
available_tools=tools,
max_steps=15 # Limit steps to prevent excessive execution
)

Run the agent with the provided goal

result = await agent.run(goal)

Print the execution summary

print("\n=== EXECUTION SUMMARY ===")
print(result)

Print the final plan status

status = await agent.get_execution_status()
print("\n=== FINAL PLAN STATUS ===")
print(status)
async def main():
"""Run the example."""
GOALS: List[str] = [
"Create a simple Python web server that displays 'Hello, World!' on the home page",
"Calculate the first 10 Fibonacci numbers and save them to a file",
"Find the current weather in Tokyo and create a summary report"
]

Choose a goal to execute

selected_goal = GOALS[0] # Change index to try different goals

print(f"Running GenericAgent with goal: {selected_goal}")
await run_generic_agent_example(selected_goal)
if name == "main": asyncio.run(main())

Create a README file explaining the Generic Agent implementation === # Generic Agentive Workflow Agent
This project implements a generic agent that uses a "Working Backwards" methodology to solve problems step by step using OpenAI API.

Concept
The Generic Agentive Workflow is defined as:

F(Generic Agentive Workflow) =
Agent(OpenAI API [LLM, Roles & Responsibilities, Tools, Abilities])
achieving goals through Working Backwards methodology.
Specifically, it uses step-back questioning to decompose thinking from the final goal state back to the initial state.

Implementation
The agent works as follows:

Goal state is clearly defined
Step-back questions are used to identify the state immediately before the goal
This process continues recursively, working backwards to the initial state
The steps are then reordered from initial state to goal (A→B→C→...→Z)
Each step is executed using OpenAI API reasoning and appropriate tools
This can be expressed as:

F(Generic Agentive Workflow) =
Goal → Step-back questions (Z→Y→X→...→A) →
Reordering (A→B→C→...→Z) →
∫(Each step with OpenAI API reasoning + tool use)d(step) →
Integrated execution plan (Result)
Key Components
GenericAgent class: Implements the Working Backwards methodology
Prompt templates: Guide the agent through the Working Backwards process
Tool integration: Allows the agent to interact with the environment
Plan tracking: Manages both backwards analysis and forward execution
Usage
from app.agent.generic_agent import GenericAgent
from app.tool import ToolCollection, Bash, GoogleSearch, Terminate

Create a tool collection

tools = ToolCollection([Bash(), GoogleSearch(), Terminate()])

Create the generic agent

agent = GenericAgent(
name="task_solver",
description="Solves tasks using Working Backwards methodology",
available_tools=tools
)

Run the agent with a goal

result = await agent.run("Create a Python script that downloads the latest Bitcoin price")

Print the result

print(result)
OpenAI API Usage
The implementation uses OpenAI API with:

LLM: For reasoning and planning
Roles & Responsibilities: Defined in system prompts
Tools: For information gathering and environment interaction
Abilities: Encoded in prompts and agent behavior
Key Features
Step-by-step planning from goal to initial state
Dynamic plan creation and execution
Tool selection based on task requirements
Progress tracking and status reporting
Adaptive execution based on previous steps' results
Example Run
See app/examples/generic_agent_example.py for a complete example of using the GenericAgent.

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:
- Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
- Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:
- [ ] Disable automatic comment and CI monitoring

@ShunsukeHayashi ShunsukeHayashi merged commit 1d5c4d6 into main Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants