From 439dc627caae70b8104e47eed7a71e07713fa474 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 29 Jan 2025 10:50:17 -0800 Subject: [PATCH] Address comments first batch --- python/pyproject.toml | 2 +- .../agents/bedrock_agent/bedrock_agent_simple_chat.py | 4 ++-- .../bedrock_agent_simple_chat_with_code_interpreter.py | 4 ++-- .../bedrock_agent_simple_chat_with_kernel_function.py | 4 ++-- python/semantic_kernel/agents/bedrock/README.md | 2 +- python/semantic_kernel/agents/bedrock/bedrock_agent.py | 7 ++++--- .../semantic_kernel/agents/bedrock/bedrock_agent_base.py | 3 ++- .../agents/bedrock/models/bedrock_agent_event_type.py | 5 ++--- python/uv.lock | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 66760d0f0187..23cd8682034b 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -116,7 +116,7 @@ pandas = [ "pandas ~= 2.2" ] aws = [ - "boto3>=1.36.4", + "boto3~=1.36.4", ] dapr = [ "dapr>=1.14.0", diff --git a/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat.py b/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat.py index 2ea152e0238a..307a0cf9345a 100644 --- a/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat.py +++ b/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat.py @@ -22,7 +22,7 @@ AGENT_NAME = "semantic-kernel-bedrock-agent-simple-chat-sample" # If creating a new agent, you need to specify the following: -INSTRUCTION = "You are a fridenly assistant. You help people find information." +INSTRUCTION = "You are a friendly assistant. You help people find information." # If using an existing agent, you need to specify the following: AGENT_ID = "" @@ -34,7 +34,7 @@ async def main(): else: bedrock_agent = await use_existing_agent(AGENT_ID, AGENT_NAME) - # Use an uiud as the session id + # Use a uiud as the session id new_session_id = str(uuid.uuid4()) # Invoke the agent diff --git a/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat_with_code_interpreter.py b/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat_with_code_interpreter.py index 57d23faac00e..eb9cb5800f3f 100644 --- a/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat_with_code_interpreter.py +++ b/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat_with_code_interpreter.py @@ -29,7 +29,7 @@ AGENT_NAME = "semantic-kernel-bedrock-agent-simple-chat-code-interpreter-sample" # If creating a new agent, you need to specify the following: -INSTRUCTION = "You are a fridenly assistant. You help people find information." +INSTRUCTION = "You are a friendly assistant. You help people find information." # If using an existing agent, you need to specify the following: AGENT_ID = "" @@ -51,7 +51,7 @@ async def main(): else: bedrock_agent = await use_existing_agent(AGENT_ID, AGENT_NAME) - # Use an uiud as the session id + # Use a uiud as the session id new_session_id = str(uuid.uuid4()) # Placeholder for the file generated by the code interpreter diff --git a/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat_with_kernel_function.py b/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat_with_kernel_function.py index e26ce1745be1..344e50c2f90b 100644 --- a/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat_with_kernel_function.py +++ b/python/samples/concepts/agents/bedrock_agent/bedrock_agent_simple_chat_with_kernel_function.py @@ -28,7 +28,7 @@ AGENT_NAME = "semantic-kernel-bedrock-agent-simple-chat-kernel-function-sample" # If creating a new agent, you need to specify the following: -INSTRUCTION = "You are a fridenly assistant. You help people find information." +INSTRUCTION = "You are a friendly assistant. You help people find information." # If using an existing agent, you need to specify the following: AGENT_ID = "" @@ -64,7 +64,7 @@ async def main(): else: bedrock_agent = await use_existing_agent(AGENT_ID, AGENT_NAME, kernel=kernel) - # Use an uiud as the session id + # Use a uiud as the session id new_session_id = str(uuid.uuid4()) # Invoke the agent diff --git a/python/semantic_kernel/agents/bedrock/README.md b/python/semantic_kernel/agents/bedrock/README.md index be2609e76143..d1e17f9245c3 100644 --- a/python/semantic_kernel/agents/bedrock/README.md +++ b/python/semantic_kernel/agents/bedrock/README.md @@ -2,7 +2,7 @@ ## Overview -AWS Bedrock Agents is a managed service that allows users to stand up and run AI agents in the cloud quickly. +AWS Bedrock Agents is a managed service that allows users to stand up and run AI agents in the AWS cloud quickly. ## Tools/Functions diff --git a/python/semantic_kernel/agents/bedrock/bedrock_agent.py b/python/semantic_kernel/agents/bedrock/bedrock_agent.py index ef7109e19e73..218c7972f91f 100644 --- a/python/semantic_kernel/agents/bedrock/bedrock_agent.py +++ b/python/semantic_kernel/agents/bedrock/bedrock_agent.py @@ -251,12 +251,13 @@ async def invoke_stream( full_message: StreamingChatMessageContent = reduce(lambda x, y: x + y, all_function_call_messages) function_calls = [item for item in full_message.items if isinstance(item, FunctionCallContent)] - chat_history = ChatHistory() + # Create a temporary chat history to store the function call results. + temp_chat_history = ChatHistory() await asyncio.gather( *[ self.kernel.invoke_function_call( function_call=function_call, - chat_history=chat_history, + chat_history=temp_chat_history, function_call_count=len(function_calls), request_index=request_index, ) @@ -265,7 +266,7 @@ async def invoke_stream( ) function_result_contents = [ item - for chat_message in chat_history.messages + for chat_message in temp_chat_history.messages for item in chat_message.items if isinstance(item, FunctionResultContent) ] diff --git a/python/semantic_kernel/agents/bedrock/bedrock_agent_base.py b/python/semantic_kernel/agents/bedrock/bedrock_agent_base.py index 7ae3f31777e1..80489f7ab382 100644 --- a/python/semantic_kernel/agents/bedrock/bedrock_agent_base.py +++ b/python/semantic_kernel/agents/bedrock/bedrock_agent_base.py @@ -2,6 +2,7 @@ import asyncio import logging +from collections.abc import Callable from functools import partial from typing import Any, ClassVar @@ -74,7 +75,7 @@ def validate_function_choice_behavior( raise ValueError("Only FunctionChoiceType.AUTO is supported.") return function_choice_behavior - async def _run_in_executor(self, executor, func, *args, **kwargs) -> Any: + async def _run_in_executor(self, executor: Any, func: Callable, *args, **kwargs) -> Any: """Run a function in an executor.""" return await asyncio.get_event_loop().run_in_executor(executor, partial(func, *args, **kwargs)) diff --git a/python/semantic_kernel/agents/bedrock/models/bedrock_agent_event_type.py b/python/semantic_kernel/agents/bedrock/models/bedrock_agent_event_type.py index 5d4fda9d817e..9803418292b2 100644 --- a/python/semantic_kernel/agents/bedrock/models/bedrock_agent_event_type.py +++ b/python/semantic_kernel/agents/bedrock/models/bedrock_agent_event_type.py @@ -1,13 +1,12 @@ # Copyright (c) Microsoft. All rights reserved. - -from enum import StrEnum +from enum import Enum from semantic_kernel.utils.experimental_decorator import experimental_class @experimental_class -class BedrockAgentEventType(StrEnum): +class BedrockAgentEventType(str, Enum): """Bedrock Agent Event Type.""" # Contains the text response from the agent. diff --git a/python/uv.lock b/python/uv.lock index 6a0e6fbf33cf..dc9756fbe1b5 100644 --- a/python/uv.lock +++ b/python/uv.lock @@ -4835,7 +4835,7 @@ requires-dist = [ { name = "azure-identity", specifier = "~=1.13" }, { name = "azure-identity", marker = "extra == 'azure'", specifier = "~=1.13" }, { name = "azure-search-documents", marker = "extra == 'azure'", specifier = ">=11.6.0b4" }, - { name = "boto3", marker = "extra == 'aws'", specifier = ">=1.36.4" }, + { name = "boto3", marker = "extra == 'aws'", specifier = "~=1.36.4" }, { name = "chromadb", marker = "extra == 'chroma'", specifier = ">=0.5,<0.7" }, { name = "cloudevents", specifier = "~=1.0" }, { name = "dapr", marker = "extra == 'dapr'", specifier = ">=1.14.0" },