Skip to content

Bug: Comprehend filter agent - no client exception #359

Description

@michelebelmonte

Expected Behaviour

When I use a ComprehendFilterAgent with no client in the configuration options, it should work without throwing exceptions, when the process_request method is called.

Current Behaviour

When no client is passed to the ComprehendContentFilterAgent, an exception is thrown when process_request is executed:
ERROR:agent_squad.utils.logger:Error in ComprehendContentFilterAgent:'ComprehendFilterAgent' object has no attribute 'comprehend_client'
ERROR:agent_squad.utils.logger:Error processing request with agent Filter agent:'ComprehendFilterAgent' object has no attribute 'comprehend_client'

Code snippet

filter_agent = ComprehendFilterAgent(
                ComprehendFilterAgentOptions(
                    name="Filter agent",
                    description="Analyzes and filters content using Amazon Comprehend",
                    enable_sentiment_check=True,
                    enable_toxicity_check=True,
                    enable_pii_check=False,
                    region=os.getenv("AWS_REGION"),
                    client=None,
                )
            )

chain_agent = ChainAgent(
                ChainAgentOptions(
                    name="A chain agent",
                    description="A simple chain agent",
                    agents=[filter_agent],
                )
            )

orchestrator.add_agent(chain_agent)

orchestrator.route_request(
                "any message", "user_id", "session_id"
            )

Possible Solution

in the ComprehendContentFilterAgent set the comprehend_client when no client is passed

if options.client:
self.comprehend_client = options.client
else:
if options.region:
self.comprehend_client = boto3.client(
'comprehend',
region_name=options.region or os.environ.get('AWS_REGION')
)
else:
self.comprehend_client = boto3.client('comprehend')

Steps to Reproduce

  1. create a comprehedfilteragent with no client
  2. create another agent, any agent is fine
  3. create a chain agent and pass it the other agents
  4. create a orchestrator and pass it the chain agent
  5. route a message using the orchestrator

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions