+
Skip to content

Conversation

tunahorse
Copy link
Contributor

@tunahorse tunahorse commented Sep 11, 2025

Summary

  • Implement enum-based state machine for agent completion detection
  • Update system prompt with new completion marker format
  • Add configurable tool validation settings
  • Update changelog with versions 0.0.70-0.0.72
  • Fix test alignment issues

Changes Made

  • Agent State Machine: Replaced error-prone boolean flags with robust enum-based state transitions
  • System Prompt: Updated completion marker from TUNACODE_TASK_COMPLETE to TUNACODE DONE:
  • Tool Validation: Made validation configurable via tool_strict_validation setting
  • Documentation: Updated changelog with all recent versions and improvements
  • Tests: Fixed test cases to match new completion marker format

Test plan

  • All tests pass
  • Pre-commit hooks pass
  • Changelog updated with proper formatting

Summary by CodeRabbit

  • New Features

    • Unified completion signaling with “TUNACODE DONE:”, improving detection in CLI and agent flow.
    • Clearer, earlier state/status messages during reasoning and tool execution; more reliable completion after tools.
  • Documentation

    • Updated system rules with a Completion Signaling section.
    • Expanded configuration guidance and added tunacode.json example.
    • CHANGELOG updated (0.0.70–0.0.72), plus new planning and research docs.
  • Tests

    • Updated tests to validate the new DONE marker and completion behavior.

sneaek tater added 3 commits September 11, 2025 14:07
- Add AgentState enum with 4 states: USER_INPUT, ASSISTANT, TOOL_EXECUTION, RESPONSE
- Create AgentStateMachine with thread-safe state transition validation
- Implement backward compatibility layer in ResponseState class
- Update node_processor.py to use state machine for completion detection
- Add transition rules to prevent invalid state changes
- Maintain full backward compatibility with existing boolean flags

This replaces the error-prone 4-boolean system with a robust state machine
that enforces valid transitions and eliminates premature completion issues.
- Add enum-based state machine implementation for v0.0.72
- Document configurable tool validation for v0.0.71
- Include model configuration updates for v0.0.70
- Fix test alignment with new completion marker format
- Update system prompt documentation and examples
@tunahorse tunahorse merged commit d936fbc into master Sep 11, 2025
1 check passed
@tunahorse tunahorse deleted the enhance-agent-loop-architecture branch September 11, 2025 20:05
Copy link

coderabbitai bot commented Sep 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces an enum-based agent state machine (USER_INPUT, ASSISTANT, TOOL_EXECUTION, RESPONSE), integrates transitions across node processing, updates completion detection to a “TUNACODE DONE:” marker, revises system prompts and agent config for plan mode, adjusts REPL detection, updates tests, adds planning/research docs, and an example config.

Changes

Cohort / File(s) Summary
State Machine Core
src/tunacode/types.py, src/tunacode/core/agents/agent_components/state_transition.py, src/tunacode/core/agents/agent_components/response_state.py
Adds AgentState enum; introduces thread-safe AgentStateMachine with rules; refactors ResponseState to use the state machine with compatibility properties and helpers.
Node Processing Integration
src/tunacode/core/agents/agent_components/node_processor.py
Wires explicit transitions (ASSISTANT → TOOL_EXECUTION → RESPONSE), replaces boolean completion with state-driven flow and UI logs, ensures RESPONSE after tool handling.
Completion Detection & Prompting
src/tunacode/core/agents/agent_components/task_completion.py, src/tunacode/prompts/system.md, src/tunacode/core/agents/main.py, src/tunacode/core/agents/agent_components/agent_helpers.py, src/tunacode/cli/repl.py, src/tunacode/core/agents/agent_components/agent_config.py
Switches completion marker to “TUNACODE DONE:”; regex-based detection; updates system rules and guidance; aligns prompts/help text; REPL anchor check; plan-mode system prompt filtering expanded.
Tests
tests/characterization/test_characterization_main.py, tests/test_prompt_changes_validation.py
Updates expectations to “TUNACODE DONE:” and validates prompt token presence.
Docs & Plans
CHANGELOG.md, memory-bank/plan/*, memory-bank/research/*
Adds CHANGELOG entries for 0.0.70–0.0.72; introduces architecture plans, enum implementation plan, CLI testing framework plan, and research analysis. Removes Unreleased section.
Example Config
tunacode.json.example
Adds sample configuration with models, env placeholders, settings, ripgrep, tutorial flags, and MCP servers.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Agent
  participant StateMachine as AgentStateMachine
  participant Tools
  participant REPL

  User->>Agent: Provide input
  Agent->>StateMachine: transition_to(ASSISTANT)
  Agent->>Agent: Generate response / tool-calls
  alt Tool calls present
    Agent->>StateMachine: transition_to(TOOL_EXECUTION)
    Agent->>Tools: Execute tool(s)
    Tools-->>Agent: Tool results
  end
  Agent->>StateMachine: transition_to(RESPONSE)
  Agent->>Agent: Check for "TUNACODE DONE:" (regex)
  alt DONE detected
    Agent->>StateMachine: set_completion_detected(True)
    Agent-->>User: Final response
  else Not done
    Agent->>StateMachine: transition_to(ASSISTANT)
    Agent-->>User: Follow-up / continue loop
  end
  REPL->>Agent: Monitor output
  REPL->>REPL: Detect anchored DONE marker
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

Poem

I hop through states: USER to ASSISTANT, so keen,
Then TOOL_EXECUTION—gears softly unseen.
I nibble on outputs, RESPONSE in my zone,
“TUNACODE DONE:” and the task is sewn.
Ears up, loops tight, transitions so clean—
A rabbit’s delight in a well-oiled machine. 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d19d3c and 07c0d2e.

📒 Files selected for processing (18)
  • CHANGELOG.md (1 hunks)
  • memory-bank/plan/2025-09-11_13-30-00_agent_loop_architecture_enhancement.md (1 hunks)
  • memory-bank/plan/2025-09-11_14-00-00_enum_state_machine_implementation.md (1 hunks)
  • memory-bank/plan/2025-09-11_14-15-00_automated_cli_tool_testing_framework.md (1 hunks)
  • memory-bank/research/2025-09-11_13-14-06_agent_loop_enhancement_analysis.md (1 hunks)
  • src/tunacode/cli/repl.py (2 hunks)
  • src/tunacode/core/agents/agent_components/agent_config.py (1 hunks)
  • src/tunacode/core/agents/agent_components/agent_helpers.py (1 hunks)
  • src/tunacode/core/agents/agent_components/node_processor.py (6 hunks)
  • src/tunacode/core/agents/agent_components/response_state.py (1 hunks)
  • src/tunacode/core/agents/agent_components/state_transition.py (1 hunks)
  • src/tunacode/core/agents/agent_components/task_completion.py (2 hunks)
  • src/tunacode/core/agents/main.py (4 hunks)
  • src/tunacode/prompts/system.md (1 hunks)
  • src/tunacode/types.py (1 hunks)
  • tests/characterization/test_characterization_main.py (1 hunks)
  • tests/test_prompt_changes_validation.py (1 hunks)
  • tunacode.json.example (1 hunks)
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhance-agent-loop-architecture

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载