Skip to content

Comments

fix: ComprehendFilterAgent client initialization and on_llm_start docstring#437

Open
abhu85 wants to merge 1 commit intoawslabs:mainfrom
abhu85:fix/comprehend-agent-and-docs-359-360/2026-02-19
Open

fix: ComprehendFilterAgent client initialization and on_llm_start docstring#437
abhu85 wants to merge 1 commit intoawslabs:mainfrom
abhu85:fix/comprehend-agent-and-docs-359-360/2026-02-19

Conversation

@abhu85
Copy link

@abhu85 abhu85 commented Feb 19, 2026

Summary

This PR fixes two bugs reported in issues #359 and #360:

Issue #359 - ComprehendFilterAgent missing client initialization

When creating a ComprehendFilterAgent without passing an explicit client (relying on boto3 to create one), the agent would fail with AttributeError: 'ComprehendFilterAgent' object has no attribute 'comprehend_client'.

Root cause: Lines 34 and 39 in comprehend_filter_agent.py incorrectly assigned the boto3 client to self.client instead of self.comprehend_client.

Fix: Changed self.client to self.comprehend_client in both branches of the initialization logic.

Issue #360 - Documentation bug in on_llm_start callback

The docstring for on_llm_start in agent.py documented parameters that didn't match the actual method signature:

  • agent_name (should be name)
  • messages (not a parameter of this method)

Fix: Updated docstring to accurately reflect the method signature and context (LLM vs agent).

Test plan

  • Added regression test test_initialization_without_client_uses_comprehend_client to verify comprehend_client is properly set when initializing without explicit client
  • All 11 tests in test_comprehend_agent.py pass
  • Verified docstring now matches method signature

Reproduction (Issue #359)

Before this fix, the following code would fail:

filter_agent = ComprehendFilterAgent(
    ComprehendFilterAgentOptions(
        name="Filter agent",
        description="Analyzes content",
        client=None,
        region="us-east-1"
    )
)
await filter_agent.process_request("test", "user", "session", [])
# AttributeError: 'ComprehendFilterAgent' object has no attribute 'comprehend_client'

After this fix, the agent correctly initializes and processes requests.

Fixes #359
Fixes #360

…string

Issue awslabs#359: Fixed bug where ComprehendFilterAgent incorrectly assigned
boto3 client to self.client instead of self.comprehend_client when
no client was provided. This caused an AttributeError when calling
process_request on an agent initialized without explicit client.

Issue awslabs#360: Fixed docstring for on_llm_start callback method:
- Changed 'agent_name' to 'name' to match actual parameter
- Removed non-existent 'messages' parameter from docs
- Updated context from 'agent' to 'LLM' for consistency

Added regression test to verify comprehend_client is properly set
when agent is initialized without an explicit client.

Fixes awslabs#359
Fixes awslabs#360

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Bug: Agent callback - on_llm_start documentation Bug: Comprehend filter agent - no client exception

1 participant