Skip to content

Conversation: make state.events.append a default callback; remove manual appends in CodeActAgent - #57

Merged
xingyaoww merged 3 commits into
mainfrom
openhands/fix-issue-51
Sep 2, 2025
Merged

xingyaoww merged 3 commits into
mainfrom
openhands/fix-issue-51

Conversation

@xingyaoww

Copy link
Copy Markdown
Contributor

Summary

  • Make state.events.append a default callback in Conversation so agents can just call on_event(event)
  • Remove manual state.events.append calls in CodeActAgent to avoid duplication and confusion
  • Add unit tests verifying events are appended exactly once

What/Why
This change simplifies event handling and ensures consistent behavior across the codebase. Agents now emit events via on_event, and Conversation persists them to state by default. This addresses readability concerns and removes scattered state mutations.

Changes

  • Conversation
    • Add default event appender callback
    • Compose callbacks as [visualizer, user callbacks..., default appender] to preserve existing ordering semantics
    • send_message no longer appends directly; it only emits the event
  • CodeActAgent
    • init_state: stop manual append of SystemPromptEvent
    • step: stop manual appends of MessageEvent; rely on on_event
    • _get_action_events: stop manual appends on error paths; rely on on_event
    • _execute_action_events: rely on on_event for ObservationEvent persistence
  • Tests
    • New tests under openhands/core/tests/conversation/test_conversation_default_callback.py verifying:
      • Default callback persists init system event
      • User message is appended exactly once and callbacks receive events

Backward compatibility

  • No breaking changes. Event lifecycle remains the same externally; only internal wiring is simplified. Visualizer callbacks and user-provided callbacks continue to operate normally.

Validation

  • Ran pre-commit (ruff + pyright) on changed files – passed
  • Ran core tests and tools tests separately due to environment memory limits; all passed
  • Ran integration test test_hello_world_integration_with_mocked_llm – passed

Fixes

Notes

  • Full test suite occasionally OOMs in this environment unrelated to these changes; running in segments avoids this and shows green across relevant areas.

Co-authored-by: openhands openhands@all-hands.dev

@xingyaoww can click here to continue refining the PR

…ual appends in CodeActAgent; add tests

- Compose callbacks to include default state appender
- Stop duplicative state.events.append calls
- Add unit tests ensuring single append behavior

Fixes #51

Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww xingyaoww added the openhands Solving the issue with OpenHands. label Sep 2, 2025 — with OpenHands AI
@xingyaoww
xingyaoww merged commit add2579 into main Sep 2, 2025
@xingyaoww
xingyaoww deleted the openhands/fix-issue-51 branch September 2, 2025 14:57
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
…ual appends in CodeActAgent (OpenHands#57)

Co-authored-by: openhands <openhands@all-hands.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

openhands Solving the issue with OpenHands.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build state.events.append as a default callback function in Conversation

2 participants