Skip to content

session

Class info

Classes

Name Children Inherits
MemoryConfig
llmling_agent.models.session
Configuration for agent memory and history handling.
    SessionQuery
    llmling_agent.models.session
    Query configuration for session recovery.

      🛈 DocStrings

      MemoryConfig

      Bases: BaseModel

      Configuration for agent memory and history handling.

      Source code in src/llmling_agent/models/session.py
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      class MemoryConfig(BaseModel):
          """Configuration for agent memory and history handling."""
      
          enable: bool = True
          """Whether to enable history tracking."""
      
          max_tokens: int | None = None
          """Maximum number of tokens to keep in context window."""
      
          max_messages: int | None = None
          """Maximum number of messages to keep in context window."""
      
          session: SessionQuery | None = None
          """Query configuration for loading previous session."""
      
          provider: str | None = None
          """Override default storage provider for this agent.
          If None, uses manifest's default provider or first available."""
      
          model_config = ConfigDict(frozen=True, use_attribute_docstrings=True, extra="forbid")
      
          @classmethod
          def from_value(cls, value: bool | int | str | SessionQuery | UUID | None) -> Self:
              """Create MemoryConfig from any value."""
              match value:
                  case False:
                      return cls(max_messages=0)
                  case int():
                      return cls(max_tokens=value)
                  case str() | UUID():
                      return cls(session=SessionQuery(name=str(value)))
                  case SessionQuery():
                      return cls(session=value)
                  case None | True:
                      return cls()
                  case _:
                      msg = f"Invalid memory configuration: type: {value}"
                      raise ValueError(msg)
      

      enable class-attribute instance-attribute

      enable: bool = True
      

      Whether to enable history tracking.

      max_messages class-attribute instance-attribute

      max_messages: int | None = None
      

      Maximum number of messages to keep in context window.

      max_tokens class-attribute instance-attribute

      max_tokens: int | None = None
      

      Maximum number of tokens to keep in context window.

      provider class-attribute instance-attribute

      provider: str | None = None
      

      Override default storage provider for this agent. If None, uses manifest's default provider or first available.

      session class-attribute instance-attribute

      session: SessionQuery | None = None
      

      Query configuration for loading previous session.

      from_value classmethod

      from_value(value: bool | int | str | SessionQuery | UUID | None) -> Self
      

      Create MemoryConfig from any value.

      Source code in src/llmling_agent/models/session.py
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      @classmethod
      def from_value(cls, value: bool | int | str | SessionQuery | UUID | None) -> Self:
          """Create MemoryConfig from any value."""
          match value:
              case False:
                  return cls(max_messages=0)
              case int():
                  return cls(max_tokens=value)
              case str() | UUID():
                  return cls(session=SessionQuery(name=str(value)))
              case SessionQuery():
                  return cls(session=value)
              case None | True:
                  return cls()
              case _:
                  msg = f"Invalid memory configuration: type: {value}"
                  raise ValueError(msg)
      

      SessionQuery

      Bases: BaseModel

      Query configuration for session recovery.

      Source code in src/llmling_agent/models/session.py
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      class SessionQuery(BaseModel):
          """Query configuration for session recovery."""
      
          name: str | None = None
          """Session identifier to match."""
      
          agents: set[str] | None = None
          """Filter by agent names."""
      
          since: str | None = None
          """Time period to look back (e.g. "1h", "2d")."""
      
          until: str | None = None
          """Time period to look up to."""
      
          contains: str | None = None
          """Filter by message content."""
      
          roles: set[MessageRole] | None = None
          """Only include specific message roles."""
      
          limit: int | None = None
          """Maximum number of messages to return."""
      
          include_forwarded: bool = True
          """Whether to include messages forwarded through agents."""
      
          model_config = ConfigDict(frozen=True, use_attribute_docstrings=True, extra="forbid")
      
          def get_time_cutoff(self) -> datetime | None:
              """Get datetime from time period string."""
              if not self.since:
                  return None
              delta = parse_time_period(self.since)
              return datetime.now() - delta
      

      agents class-attribute instance-attribute

      agents: set[str] | None = None
      

      Filter by agent names.

      contains class-attribute instance-attribute

      contains: str | None = None
      

      Filter by message content.

      include_forwarded class-attribute instance-attribute

      include_forwarded: bool = True
      

      Whether to include messages forwarded through agents.

      limit class-attribute instance-attribute

      limit: int | None = None
      

      Maximum number of messages to return.

      name class-attribute instance-attribute

      name: str | None = None
      

      Session identifier to match.

      roles class-attribute instance-attribute

      roles: set[MessageRole] | None = None
      

      Only include specific message roles.

      since class-attribute instance-attribute

      since: str | None = None
      

      Time period to look back (e.g. "1h", "2d").

      until class-attribute instance-attribute

      until: str | None = None
      

      Time period to look up to.

      get_time_cutoff

      get_time_cutoff() -> datetime | None
      

      Get datetime from time period string.

      Source code in src/llmling_agent/models/session.py
      82
      83
      84
      85
      86
      87
      def get_time_cutoff(self) -> datetime | None:
          """Get datetime from time period string."""
          if not self.since:
              return None
          delta = parse_time_period(self.since)
          return datetime.now() - delta