Skip to content

Fix agent reconciliation to allow agent_context updates#1371

Merged
xingyaoww merged 3 commits intomainfrom
jps/fix-agent-context-reconciliation
Dec 9, 2025
Merged

Fix agent reconciliation to allow agent_context updates#1371
xingyaoww merged 3 commits intomainfrom
jps/fix-agent-context-reconciliation

Conversation

@jpshackelford
Copy link
Contributor

@jpshackelford jpshackelford commented Dec 9, 2025

Problem

When resuming a conversation from a different directory or switching between ACP and regular CLI mode, the agent state validation fails with a ValueError showing differences in:

  • Skill paths (absolute paths change with working directory)
  • Skills list (ACP mode adds user_provided_resources skill)
  • System message suffix (contains working directory)

This prevents users from resuming conversations across different environments.

Solution

Modified resolve_diff_from_deserialized() in agent/base.py to reconcile agent_context during conversation resume, similar to how LLM configuration is already handled. The reconciliation now:

  1. Updates agent_context to use the current environment's values
  2. Allows skill changes between sessions
  3. Handles working directory changes gracefully

Testing

Added comprehensive test test_conversation_restart_with_different_agent_context() that simulates:

  • Creating a conversation in ACP mode with specific skills
  • Resuming the conversation in regular CLI mode with different skills
  • Verifying the agent_context is properly reconciled

Test validates the fix

Without the fix (code commented out), the test fails with the exact error from the bug report:

FAILED - ValueError: The Agent provided is different from the one in persisted state.
Diff: agent_context:
  skills:
    0:
      content: 'Information about the current project' -> 'You may encounter...'
      name: 'project_info' -> 'user_provided_resources'
  system_message_suffix: 'You current working directory is: /Users/jpshack' -> '.../all-hands'

With the fix, the test passes along with all other reconciliation tests.

All 44 tests in the cross directory pass ✓

Impact

  • ✅ Users can now resume conversations from any directory
  • ✅ Switching between ACP and regular CLI mode works seamlessly
  • ✅ Backward compatible - existing conversations continue to work
  • ✅ No breaking changes to the API

jpshackelford and others added 2 commits December 9, 2025 15:18
Allow agent_context to be updated during conversation resume. This fixes
the issue where resuming a conversation from a different directory or
switching between ACP and regular CLI mode would fail due to:
- Different skill paths (absolute paths change with working directory)
- Different skills (e.g., ACP mode adds user_provided_resources skill)
- Different system_message_suffix (contains working directory)

The reconciliation now uses the current environment's agent_context,
similar to how it handles LLM updates.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/agent
   base.py1591888%154, 160, 204–205, 211–213, 226, 234–235, 269, 316, 323, 336, 373–374, 384–385
TOTAL12427561254% 

Remove redundant if/elif branches that performed the same operation.
The simplified logic is clearer: always use the current environment's
agent_context when it exists.

Co-authored-by: openhands <openhands@all-hands.dev>
@jpshackelford jpshackelford marked this pull request as ready for review December 9, 2025 20:40
Copy link
Collaborator

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@xingyaoww xingyaoww merged commit bae0093 into main Dec 9, 2025
22 checks passed
@xingyaoww xingyaoww deleted the jps/fix-agent-context-reconciliation branch December 9, 2025 20:44
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