Skip to content

Commit c657ee8

Browse files
committed
Refactor implementation of strands agents migration.
- Split `chat()` into common and framework specific implementation. 1. (Common preprocess) Setup messages and LLM parameters. 2. (Framework specific) Converse with LLM and build response messages. 3. (Common postprocess) Update conversation and store into database. - Consolidate the code for converting between application-defined models (messages, contents and tools) and Strands models into `converters` module. - Fix some bugs in streaming processing - Fail to continue generation based on a message with `ReasoningContent`. - Not handling `redactedContent` correctly.
1 parent 1263fa2 commit c657ee8

33 files changed

+1510
-1871
lines changed

backend/app/agents/utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import logging
22
from typing import Dict
3+
from typing_extensions import deprecated
34

45
from app.agents.tools.agent_tool import AgentTool
56
from app.agents.tools.bedrock_agent import BedrockAgent, bedrock_agent_tool
67
from app.agents.tools.calculator import calculator_tool
78
from app.agents.tools.internet_search import internet_search_tool
89
from app.agents.tools.knowledge import create_knowledge_tool
910
from app.agents.tools.simple_list import simple_list_tool
11+
from app.bedrock import is_tooluse_supported
1012
from app.repositories.models.custom_bot import BotModel
11-
from typing_extensions import deprecated
13+
from app.routes.schemas.conversation import type_model_name
1214

1315
logger = logging.getLogger(__name__)
1416
logger.setLevel(logging.INFO)
@@ -23,7 +25,9 @@ def get_available_tools() -> list[AgentTool]:
2325

2426

2527
@deprecated("Use get_strands_tools() instead")
26-
def get_tools(bot: BotModel | None) -> Dict[str, AgentTool]:
28+
def get_tools(
29+
bot: BotModel | None, model_name: type_model_name
30+
) -> Dict[str, AgentTool]:
2731
"""Get a dictionary of tools based on bot's tool configuration
2832
2933
Args:
@@ -34,6 +38,12 @@ def get_tools(bot: BotModel | None) -> Dict[str, AgentTool]:
3438
"""
3539
tools: Dict[str, AgentTool] = {}
3640

41+
if not is_tooluse_supported(model_name):
42+
logger.warning(
43+
f"Tool use is not supported for model {model_name}. Returning empty tool list."
44+
)
45+
return tools
46+
3747
# Return empty dictionary if bot is None or agent is not enabled
3848
if not bot or not bot.is_agent_enabled():
3949
return tools

0 commit comments

Comments
 (0)