diff --git a/src/strands/hooks/registry.py b/src/strands/hooks/registry.py index 96b218c8a..bcc4427df 100644 --- a/src/strands/hooks/registry.py +++ b/src/strands/hooks/registry.py @@ -184,14 +184,12 @@ def invoke_callbacks(self, event: TInvokeEvent) -> TInvokeEvent: This method finds all callbacks registered for the event's type and invokes them in the appropriate order. For events with should_reverse_callbacks=True, - callbacks are invoked in reverse registration order. + callbacks are invoked in reverse registration order. Any exceptions raised by callback + functions will propagate to the caller. Args: event: The event to dispatch to registered callbacks. - Raises: - Any exceptions raised by callback functions will propagate to the caller. - Returns: The event dispatched to registered callbacks. diff --git a/src/strands/models/writer.py b/src/strands/models/writer.py index 1a87ee8f0..f6a3da3d8 100644 --- a/src/strands/models/writer.py +++ b/src/strands/models/writer.py @@ -427,8 +427,8 @@ async def structured_output( """Get structured output from the model. Args: - output_model(Type[BaseModel]): The output model to use for the agent. - prompt(Messages): The prompt messages to use for the agent. + output_model: The output model to use for the agent. + prompt: The prompt messages to use for the agent. system_prompt: System prompt to provide context to the model. **kwargs: Additional keyword arguments for future extensibility. """ diff --git a/src/strands/session/__init__.py b/src/strands/session/__init__.py new file mode 100644 index 000000000..7b5310190 --- /dev/null +++ b/src/strands/session/__init__.py @@ -0,0 +1,18 @@ +"""Session module. + +This module provides session management functionality. +""" + +from .file_session_manager import FileSessionManager +from .repository_session_manager import RepositorySessionManager +from .s3_session_manager import S3SessionManager +from .session_manager import SessionManager +from .session_repository import SessionRepository + +__all__ = [ + "FileSessionManager", + "RepositorySessionManager", + "S3SessionManager", + "SessionManager", + "SessionRepository", +] diff --git a/src/strands/session/repository_session_manager.py b/src/strands/session/repository_session_manager.py index 59f47866b..487335ac9 100644 --- a/src/strands/session/repository_session_manager.py +++ b/src/strands/session/repository_session_manager.py @@ -1,9 +1,8 @@ """Repository session manager implementation.""" import logging -from typing import Any, Optional +from typing import TYPE_CHECKING, Any, Optional -from ..agent.agent import Agent from ..agent.state import AgentState from ..types.content import Message from ..types.exceptions import SessionException @@ -16,6 +15,9 @@ from .session_manager import SessionManager from .session_repository import SessionRepository +if TYPE_CHECKING: + from ..agent.agent import Agent + logger = logging.getLogger(__name__) @@ -49,7 +51,7 @@ def __init__(self, session_id: str, session_repository: SessionRepository, **kwa # Keep track of the latest message of each agent in case we need to redact it. self._latest_agent_message: dict[str, Optional[SessionMessage]] = {} - def append_message(self, message: Message, agent: Agent, **kwargs: Any) -> None: + def append_message(self, message: Message, agent: "Agent", **kwargs: Any) -> None: """Append a message to the agent's session. Args: @@ -68,7 +70,7 @@ def append_message(self, message: Message, agent: Agent, **kwargs: Any) -> None: self._latest_agent_message[agent.agent_id] = session_message self.session_repository.create_message(self.session_id, agent.agent_id, session_message) - def redact_latest_message(self, redact_message: Message, agent: Agent, **kwargs: Any) -> None: + def redact_latest_message(self, redact_message: Message, agent: "Agent", **kwargs: Any) -> None: """Redact the latest message appended to the session. Args: @@ -82,7 +84,7 @@ def redact_latest_message(self, redact_message: Message, agent: Agent, **kwargs: latest_agent_message.redact_message = redact_message return self.session_repository.update_message(self.session_id, agent.agent_id, latest_agent_message) - def sync_agent(self, agent: Agent, **kwargs: Any) -> None: + def sync_agent(self, agent: "Agent", **kwargs: Any) -> None: """Serialize and update the agent into the session repository. Args: @@ -94,7 +96,7 @@ def sync_agent(self, agent: Agent, **kwargs: Any) -> None: SessionAgent.from_agent(agent), ) - def initialize(self, agent: Agent, **kwargs: Any) -> None: + def initialize(self, agent: "Agent", **kwargs: Any) -> None: """Initialize an agent with a session. Args: diff --git a/src/strands/telemetry/tracer.py b/src/strands/telemetry/tracer.py index ff8b23169..f060c7f6e 100644 --- a/src/strands/telemetry/tracer.py +++ b/src/strands/telemetry/tracer.py @@ -473,7 +473,6 @@ def end_agent_span( span: The span to end. response: The response from the agent. error: Any error that occurred. - metrics: Metrics data to add to the span. """ attributes: Dict[str, AttributeValue] = {} @@ -541,9 +540,6 @@ def end_swarm_span( def get_tracer() -> Tracer: """Get or create the global tracer. - Args: - service_name: Name of the service for OpenTelemetry. - Returns: The global tracer instance. """ diff --git a/src/strands/types/session.py b/src/strands/types/session.py index 9330d1203..259ab1171 100644 --- a/src/strands/types/session.py +++ b/src/strands/types/session.py @@ -5,11 +5,13 @@ from dataclasses import asdict, dataclass, field from datetime import datetime, timezone from enum import Enum -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict, Optional -from ..agent.agent import Agent from .content import Message +if TYPE_CHECKING: + from ..agent.agent import Agent + class SessionType(str, Enum): """Enumeration of session types. @@ -111,7 +113,7 @@ class SessionAgent: updated_at: str = field(default_factory=lambda: datetime.now(timezone.utc).isoformat()) @classmethod - def from_agent(cls, agent: Agent) -> "SessionAgent": + def from_agent(cls, agent: "Agent") -> "SessionAgent": """Convert an Agent to a SessionAgent.""" if agent.agent_id is None: raise ValueError("agent_id needs to be defined.")