Skip to content

Commit 2268950

Browse files
committed
fix issues with no tools for message array that contains tool calls
1 parent e7abcfb commit 2268950

3 files changed

Lines changed: 10 additions & 23 deletions

File tree

src/strands/agent/agent.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -748,18 +748,14 @@ async def _execute_event_loop_cycle(self, output_schema: Optional[OutputSchema],
748748
# Add output_schema for structured output support
749749
invocation_state["output_schema"] = output_schema
750750

751-
# Register structured output tools once per invocation (better architecture)
752-
registered_tool_names = []
753751
if output_schema:
754752
from ..output.modes import ToolMode
755753
if isinstance(output_schema.mode, ToolMode):
756754
structured_output_tool_instances = output_schema.mode.get_tool_instances(output_schema.type)
757755
for tool_instance in structured_output_tool_instances:
758756
tool_name = tool_instance.tool_spec["name"]
759-
# Check if tool is already registered to prevent duplicates
760757
if self.tool_registry.get_tool(tool_name) is None:
761758
self.tool_registry.register_dynamic_tool(tool_instance)
762-
registered_tool_names.append(tool_name)
763759
logger.debug(f"Registered structured output tool for invocation: {tool_name}")
764760

765761
try:
@@ -784,11 +780,6 @@ async def _execute_event_loop_cycle(self, output_schema: Optional[OutputSchema],
784780
async for event in events:
785781
yield event
786782

787-
finally:
788-
# Cleanup: Deregister structured output tools after invocation
789-
for tool_name in registered_tool_names:
790-
self.tool_registry.unregister_dynamic_tool(tool_name)
791-
logger.debug(f"Deregistered structured output tool after invocation: {tool_name}")
792783

793784
def _convert_prompt_to_messages(self, prompt: AgentInput) -> Messages:
794785
messages: Messages | None = None

src/strands/output/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from typing import Any, Type, Union, Optional, TYPE_CHECKING
55
from pydantic import BaseModel
66

7+
78
if TYPE_CHECKING:
89
from strands.models.model import Model
9-
from strands.tools.tool_spec import ToolSpec
10+
from strands.types.tools import ToolSpec
1011

1112

1213
class OutputMode(ABC):
@@ -56,8 +57,6 @@ def __init__(
5657
self,
5758
type: Type[BaseModel],
5859
mode: Optional[OutputMode] = None,
59-
name: Optional[str] = None,
60-
description: Optional[str] = None,
6160
):
6261
"""Initialize output schema.
6362
@@ -71,6 +70,4 @@ def __init__(
7170
if mode is None:
7271
from .modes import ToolMode
7372
mode = ToolMode()
74-
self.mode = mode
75-
self.name = name
76-
self.description = description
73+
self.mode = mode

src/strands/output/modes.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
if TYPE_CHECKING:
99
from strands.models.model import Model
10-
from strands.tools.tool_spec import ToolSpec
10+
from strands.types.tools import ToolSpec
1111
from strands.tools.structured_output_tool import StructuredOutputTool
1212

1313

@@ -54,16 +54,16 @@ class NativeMode(OutputMode):
5454

5555
def get_tool_specs(self, output_type: Type[BaseModel]) -> list["ToolSpec"]:
5656
"""Return empty list - will use native JSON schema instead."""
57-
return []
57+
raise NotImplementedError()
5858

5959
def extract_result(self, model_response: Any) -> Any:
6060
"""Extract result from native structured output."""
6161
# Implementation will be added when integrating with model providers
62-
return model_response
62+
raise NotImplementedError()
6363

6464
def is_supported_by_model(self, model: "Model") -> bool:
6565
"""Check if model supports native structured output."""
66-
return model.supports_native_structured_output()
66+
raise NotImplementedError()
6767

6868

6969
class PromptMode(OutputMode):
@@ -83,13 +83,12 @@ def __init__(self, template: Optional[str] = None):
8383

8484
def get_tool_specs(self, output_type: Type[BaseModel]) -> list["ToolSpec"]:
8585
"""Return empty list - will inject schema into system prompt instead."""
86-
return []
86+
raise NotImplementedError()
8787

8888
def extract_result(self, model_response: Any) -> Any:
8989
"""Extract result from prompted response."""
90-
# Implementation will be added when integrating with event loop
91-
return model_response
90+
raise NotImplementedError()
9291

9392
def is_supported_by_model(self, model: "Model") -> bool:
9493
"""Prompting-based output works with all models."""
95-
return True
94+
raise NotImplementedError()

0 commit comments

Comments
 (0)