Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions src/strands/hooks/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions src/strands/models/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
18 changes: 18 additions & 0 deletions src/strands/session/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
14 changes: 8 additions & 6 deletions src/strands/session/repository_session_manager.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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__)


Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions src/strands/telemetry/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}

Expand Down Expand Up @@ -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.
"""
Expand Down
8 changes: 5 additions & 3 deletions src/strands/types/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.")
Expand Down
Loading