Skip to content
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

89 bedrock agent required arguments documented as optional #92

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/agenteval/targets/bedrock_agent/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import uuid

from typing import Optional
from agenteval.targets import Boto3Target, TargetResponse

_SERVICE_NAME = "bedrock-agent-runtime"
Expand All @@ -12,28 +12,29 @@ class BedrockAgentTarget(Boto3Target):
"""A target encapsulating an Amazon Bedrock agent."""

def __init__(
self,
bedrock_agent_id: str,
bedrock_agent_alias_id: str,
bedrock_session_attributes: dict,
bedrock_prompt_session_attributes: dict,
**kwargs
self,
bedrock_agent_id: str,
bedrock_agent_alias_id: str,
bedrock_session_attributes: Optional[dict] = {},
bedrock_prompt_session_attributes: Optional[dict] = {},
**kwargs
):
"""Initialize the target.

Args:
bedrock_agent_id (str): The unique identifier of the Bedrock agent.
bedrock_agent_alias_id (str): The alias of the Bedrock agent.
bedrock_session_attributes (dict): The dictionary of attributes that persist over a session between a user and agent
bedrock_prompt_session_attributes (dict): The dictionary of attributes that persist over a single turn (one InvokeAgent call)
bedrock_session_attributes Optional (dict): The dictionary of attributes that persist over a session between a user and agent
bedrock_prompt_session_attributes Optional (dict): The dictionary of attributes that persist over a single turn (one InvokeAgent call)
"""
super().__init__(boto3_service_name=_SERVICE_NAME, **kwargs)
self._bedrock_agent_id = bedrock_agent_id
self._bedrock_agent_alias_id = bedrock_agent_alias_id
self._bedrock_session_state = {
"sessionAttributes": bedrock_session_attributes,
"promptSessionAttributes": bedrock_prompt_session_attributes,
}
self._session_state = {}
if bedrock_session_attributes:
self._session_state["sessionAttributes"] = bedrock_session_attributes
if bedrock_prompt_session_attributes:
self._session_state["promptSessionAttributes"] = bedrock_prompt_session_attributes
self._session_id: str = str(uuid.uuid4())

def invoke(self, prompt: str) -> TargetResponse:
Expand All @@ -48,8 +49,8 @@ def invoke(self, prompt: str) -> TargetResponse:
args = {
"agentId": self._bedrock_agent_id,
"agentAliasId": self._bedrock_agent_alias_id,
"sessionState": self._bedrock_session_state,
"sessionId": self._session_id,
"sessionState": self._session_state,
"inputText": prompt,
"enableTrace": True,
}
Expand Down
Loading