Skip to content

[REFACTOR] Unify Model Interface Around Single Entry Point (model.stream) #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 10, 2025

Conversation

mkmeral
Copy link
Contributor

@mkmeral mkmeral commented Jul 9, 2025

Pull Request: Unify Model Interface Around Single Entry Point (model.stream)

Description

This PR refactors the model interface to use a unified, stream-first architecture that simplifies the model layer while maintaining external API compatibility.

Key Changes:

Interface Unification:

  • Replace dual converse/stream pattern with unified stream method as single entry point
  • Update stream method signature to accept (messages, tool_specs, system_prompt) directly
  • Remove abstract format_request and format_chunk methods from base Model class
  • Move request formatting and chunk processing inside individual stream implementations

Implementation Updates:

  • Update all 7 model implementations: Anthropic, Bedrock, LiteLLM, LlamaAPI, Mistral, Ollama, OpenAI
  • Add comprehensive debug logging to all stream methods (request formatting, invocation, completion)
  • Eliminate converse method from Model base class
  • Update event loop and streaming components to use unified interface

Testing & Quality:

  • Add new logging test in test_bedrock.py to verify debug functionality
  • Update all existing tests to use new interface
  • Maintain backward compatibility of Agent

Benefits:

  • Simplified Interface: Single method handles complete request lifecycle internally
  • Better Observability: Consistent debug logging across all model implementations
  • Easier Maintenance: Unified pattern makes adding new models more straightforward

Related Issues

Documentation PR

Type of Change

Breaking change

Note: While this is technically a breaking change to the model interface, it maintains full backward compatibility for external consumers (Agent class, event loops, etc.)

Testing

How have you tested the change?

  • Unit Tests: All 46 existing Bedrock tests pass + new logging test added
  • Model Coverage: Verified all 7 model implementations updated correctly
  • Integration Tests: 20/24 integration tests pass (4 failures due to Meta model regional access restrictions, unrelated to code changes)
  • Debug Logging: Verified comprehensive logging works across all models
  • Interface Consistency: Confirmed unified stream method signature across all implementations
  • I ran hatch run prepare

Test Results:

# Unit tests - all pass
hatch test tests/strands/models/test_bedrock.py  # 46 passed
hatch test tests/strands/models/               # All model tests pass

# Integration tests - 20 passed, 4 failed due to external access issues
hatch run test-integ  # Failures are Meta model regional restrictions, not code issues

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • [] I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed (No new external features)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published (No dependencies)

@mkmeral mkmeral requested a deployment to manual-approval July 9, 2025 22:13 — with GitHub Actions Waiting
@mkmeral mkmeral changed the title Unify Model Interface Around Single Entry Point (model.stream) [REFACTOR] Unify Model Interface Around Single Entry Point (model.stream) Jul 10, 2025
@mkmeral mkmeral temporarily deployed to manual-approval July 10, 2025 17:14 — with GitHub Actions Inactive
@pgrayy pgrayy merged commit 2baacdf into strands-agents:main Jul 10, 2025
21 of 22 checks passed
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.

3 participants