Skip to content

Conversation

@zastrowm
Copy link
Member

@zastrowm zastrowm commented Nov 20, 2025

Resolves: #210

Summary

This PR refactors conversation management to use the hook system as an internal implementation mechanism while maintaining conversationManager as a first-class configuration option. The key architectural change is that conversation managers now implement HookProvider and register callbacks for lifecycle events, but this is an implementation detail hidden from users who continue to configure conversation management through the dedicated conversationManager field.

Motivation

The original implementation had Agent directly calling conversation manager methods at specific points in the execution flow. This created tight coupling between the Agent class and the conversation manager interface. By leveraging the existing hook system, we achieve better separation of concerns while maintaining the same user-facing API.

The hook-based approach provides natural extension points for observability and custom behavior without requiring changes to the core Agent implementation. It also enables future enhancements like composable conversation strategies or pluggable context management policies.

Functionally, there should be no change in behavior from the customer's perspective.

Design Rationale

Conversation management is a fundamental agent capability, not an optional extension. By keeping it as a first-class configuration option, we provide better discoverability, IntelliSense support, and the ability to set sensible defaults without explicit configuration.

@github-actions github-actions bot added strands-running <strands-managed> Whether or not an agent is currently running and removed strands-running <strands-managed> Whether or not an agent is currently running labels Nov 20, 2025
- Use hooks.addHook() instead of manual registerCallbacks()
- Create createMockAgent() helper in fixtures
- Simplify test helpers to use invokeCallbacks directly
- Update all tests to use createMockAgent helper
- Make all tests properly async with await

Addresses PR review feedback.
refactor: keep conversationManager as first-class config option

- Restore conversationManager to AgentConfig and Agent class
- Agent automatically registers conversation manager hooks internally
- Update tests to use HookRegistryImplementation and focus on behavior
- Remove public mentions of hooks from conversation manager docs
- Simplify NullConversationManager tests to focus on behavior

This maintains conversationManager as a top-level concept while using
hooks internally as an implementation detail.
refactor!: convert conversation managers to hook providers

BREAKING CHANGE: Removed ConversationManager base class and Agent.conversationManager field.
Conversation managers are now hook providers that must be registered via the hooks config.

Changes:
- Added retryModelCall field to AfterModelCallEvent for retry control
- Converted NullConversationManager to HookProvider (0 hooks registered)
- Converted SlidingWindowConversationManager to HookProvider with AfterInvocationEvent and AfterModelCallEvent callbacks
- Removed Agent.conversationManager field and related config
- Updated Agent retry logic to use retryModelCall flag instead of catching ContextWindowOverflowError
- Added messages field to AgentData interface for hook access
- Deleted ConversationManager base class and ConversationContext interface
- Updated public API exports to remove ConversationManager

Migration:
Before: new Agent({ conversationManager: new SlidingWindowConversationManager() })
After: new Agent({ hooks: [new SlidingWindowConversationManager()] })

Resolves: #210
@github-actions github-actions bot added the strands-running <strands-managed> Whether or not an agent is currently running label Nov 20, 2025
- Create MockAgentData interface with optional messages and state
- Update createMockAgent to accept interface-based parameter
- Update all test usages to use object syntax
- Add retryModelCall tests to agent.hook.test.ts
- Update test helpers to use registry.addHook(manager)

Addresses review comments on PR #222
@github-actions github-actions bot removed the strands-running <strands-managed> Whether or not an agent is currently running label Nov 20, 2025
@zastrowm zastrowm closed this Nov 20, 2025
@zastrowm zastrowm reopened this Nov 20, 2025
@zastrowm zastrowm marked this pull request as ready for review November 20, 2025 03:20
@zastrowm zastrowm self-assigned this Nov 20, 2025
@Unshure Unshure added this pull request to the merge queue Nov 20, 2025
Merged via the queue into main with commit f43172a Nov 20, 2025
11 of 17 checks passed
@Unshure Unshure deleted the agent-tasks/210 branch November 20, 2025 14:27
@zastrowm zastrowm mentioned this pull request Nov 28, 2025
14 tasks
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.

Re-implement conversation-manager as a hook provider

3 participants