Skip to content

feat/claude 1m context 20250822172021#23

Merged
jacsamell merged 2 commits into
mainfrom
feat/claude-1m-context-20250822172021
Aug 22, 2025
Merged

feat/claude 1m context 20250822172021#23
jacsamell merged 2 commits into
mainfrom
feat/claude-1m-context-20250822172021

Conversation

@jacsamell
Copy link
Copy Markdown
Owner

@jacsamell jacsamell commented Aug 22, 2025

User description

  • feat: auto-set Anthropic 1M-context beta header for Claude models; merge with user extra_headers; OpenAI type alias shim for LiteLLM
  • feat: switch defaults to claude-sonnet-4-20250514; add aliases and MAX_TOKENS entry; update docs and action inputs

PR Type

Enhancement


Description

• Automatically set Anthropic beta header for 1M context
• Switch default model to claude-sonnet-4-20250514
• Enhance header merging for LiteLLM integration
• Update model token limits and configurations


Changes walkthrough 📝

Relevant files
Configuration changes
__init__.py
Update model configuration to Sonnet 4                                     

pr_agent/algo/init.py

• Replace claude-3-7-sonnet-20250219 with claude-sonnet-4-20250514
• Update token limit from 200k to 1M context
• Fix trailing whitespace
in model list

+2/-2     
Enhancement
litellm_ai_handler.py
Enhanced Claude integration with 1M context                           

pr_agent/algo/ai_handlers/litellm_ai_handler.py

• Auto-set anthropic-beta header for Claude 1M context
• Merge user
extra_headers with existing headers
• Add error handling for header configuration
• Exclude Bedrock models
from beta header logic

+17/-2   

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • …rge with user extra_headers; OpenAI type alias shim for LiteLLM
    @github-actions
    Copy link
    Copy Markdown
    Contributor

    github-actions Bot commented Aug 22, 2025

    PR Reviewer Guide 🔍

    (Review updated until commit e948cce)

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
     AI Review Score: 76%
    🧪 No relevant tests
     Confidence score [1-100]: 85
     Complexity score [1-10]: 5
     Security score [1-10]: 7
     Auto approve recommendation: false
     Auto approve reasoning: The PR has a duplicate model entry that could cause issues, uses broad exception handling, and lacks tests for the new functionality. While the header merging logic is sound, these concerns prevent auto-approval.
     Requires human approval: Code Quality Issues
    💡 Code suggestions

    Improve Model Detection

    Use a more robust method for detecting Anthropic Claude models instead of string matching which could be error-prone.

    Existing code:

    if (
        ("claude" in model.lower() or model.lower().startswith("anthropic/"))
        and not model.lower().startswith("bedrock/")
    ):
    

    Improved code:

    # Define Claude model prefixes for better maintainability
    claude_prefixes = ["anthropic/claude", "claude-"]
    bedrock_prefixes = ["bedrock/"]
    
    model_lower = model.lower()
    is_claude = any(model_lower.startswith(prefix) for prefix in claude_prefixes)
    is_bedrock = any(model_lower.startswith(prefix) for prefix in bedrock_prefixes)
    
    if is_claude and not is_bedrock:
    
    Specific Exception Handling

    Use more specific exception handling to better identify and log potential issues with header setting.

    Existing code:

    except Exception as e:
        get_logger().debug(f"Unable to set Anthropic beta header: {e}")
    

    Improved code:

    except (KeyError, TypeError, ValueError) as e:
        get_logger().debug(f"Unable to set Anthropic beta header: {e}")
    except Exception as e:
        get_logger().warning(f"Unexpected error setting Anthropic beta header: {e}")
    
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Duplicate Entry

    The model anthropic/claude-sonnet-4-20250514 is being added to MAX_TOKENS but it already exists on line 78. This creates a duplicate key in the dictionary which may cause unexpected behavior.

    'anthropic/claude-sonnet-4-20250514': 1000000,
    Broad Exception

    The exception handling for setting Anthropic beta header catches all exceptions with a generic Exception. This could mask important errors and make debugging difficult.

    except Exception as e:
        get_logger().debug(f"Unable to set Anthropic beta header: {e}")

    🔍 Manual review required

    Reason: Manual review required: Code Quality Issues

    …X_TOKENS entry; update docs and action inputs
    @jacsamell jacsamell force-pushed the feat/claude-1m-context-20250822172021 branch from 64de3ad to e948cce Compare August 22, 2025 07:57
    @jacsamell jacsamell merged commit 3ab0c2e into main Aug 22, 2025
    2 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant