agentgit.sessions package

Submodules

agentgit.sessions.external_session module

External session model for the LangGraph rollback agent system.

Represents user-visible sessions that contain multiple internal LangGraph sessions.

class agentgit.sessions.external_session.ExternalSession(id=None, user_id=0, session_name='', created_at=None, updated_at=None, is_active=True, internal_session_ids=<factory>, current_internal_session_id=None, metadata=<factory>, branch_count=0, total_checkpoints=0)[source]

Bases: object

External session model visible to users.

External sessions are the main conversation containers that users interact with. Each external session can contain multiple internal sessions created during rollback operations, forming a branching timeline structure.

id

Unique identifier for the session.

user_id

ID of the user who owns this session.

session_name

User-friendly name for the session.

created_at

When the session was created.

updated_at

When the session was last updated.

is_active

Whether the session is currently active.

internal_session_ids

List of internal session IDs (supports LangGraph IDs).

current_internal_session_id

The currently active internal session ID.

metadata

Additional session metadata (model config, preferences, etc.).

branch_count

Number of branches created from rollbacks.

total_checkpoints

Total number of checkpoints across all internal sessions.

Example

>>> session = ExternalSession(
...     user_id=1,
...     session_name="Project Discussion",
...     created_at=datetime.now()
... )
>>> session.add_internal_session("langgraph_session_123")
add_internal_session(session_id, is_branch=False)[source]

Add a new internal session ID to this external session.

Parameters:
  • session_id (str) – The internal session ID to add.

  • is_branch (bool) – Whether this is a branch from a rollback.

branch_count: int = 0
created_at: Optional[datetime] = None
current_internal_session_id: Optional[str] = None
classmethod from_dict(data)[source]

Create an ExternalSession from dictionary data.

Parameters:

data (dict) – Dictionary containing session data.

Return type:

ExternalSession

Returns:

ExternalSession instance.

get_branch_info()[source]

Get information about session branches.

Return type:

Dict[str, Any]

Returns:

Dictionary with branch statistics.

get_session_age()[source]

Get the age of the session in hours.

Return type:

Optional[float]

Returns:

Age in hours if created_at is set, None otherwise.

id: Optional[int] = None
increment_checkpoint_count()[source]

Increment the total checkpoint count.

internal_session_ids: List[str]
is_active: bool = True
metadata: Dict[str, Any]
session_name: str = ''
set_current_internal_session(session_id)[source]

Set the current active internal session.

Parameters:

session_id (str) – The internal session ID to set as current.

Return type:

bool

Returns:

True if the session ID exists and was set, False otherwise.

to_dict()[source]

Convert session to dictionary representation.

Return type:

dict

Returns:

Dictionary with session data.

total_checkpoints: int = 0
update_metadata(metadata)[source]

Update session metadata.

Parameters:

metadata (Dict[str, Any]) – Metadata to merge with existing metadata.

updated_at: Optional[datetime] = None
user_id: int = 0

agentgit.sessions.internal_session module

Internal session model for the LangGraph rollback agent system.

Represents the actual LangGraph agent sessions within an external session.

class agentgit.sessions.internal_session.InternalSession(id=None, external_session_id=0, langgraph_session_id='', session_state=<factory>, conversation_history=<factory>, created_at=None, is_current=True, checkpoint_count=0, parent_session_id=None, branch_point_checkpoint_id=None, tool_invocation_count=0, metadata=<factory>)[source]

Bases: object

Internal session model for LangGraph agents.

Represents an actual LangGraph agent session that runs within an external session. Stores the session state and conversation history with support for branching timelines.

id

Unique identifier for the internal session.

external_session_id

ID of the parent external session.

langgraph_session_id

The session ID (supports LangGraph IDs).

session_state

The agent’s session state dictionary.

conversation_history

List of conversation messages.

created_at

When this internal session was created.

is_current

Whether this is the current active session.

checkpoint_count

Number of checkpoints created from this session.

parent_session_id

ID of parent internal session (for branches).

branch_point_checkpoint_id

ID of checkpoint this was branched from.

tool_invocation_count

Total number of tool invocations in this session.

metadata

Additional session metadata.

Example

>>> session = InternalSession(
...     external_session_id=1,
...     langgraph_session_id="langgraph_abc123",
...     session_state={"counter": 0}
... )
add_message(role, content, **kwargs)[source]

Add a message to the conversation history.

Parameters:
  • role (str) – The role of the message sender (user, assistant, system).

  • content (str) – The message content.

  • **kwargs – Additional message metadata.

branch_point_checkpoint_id: Optional[int] = None
checkpoint_count: int = 0
conversation_history: List[Dict[str, Any]]
classmethod create_branch_from_checkpoint(checkpoint, external_session_id, parent_session_id)[source]

Create a new internal session branched from a checkpoint.

Parameters:
  • checkpoint – The checkpoint to branch from.

  • external_session_id (int) – ID of the external session.

  • parent_session_id (int) – ID of the parent internal session.

Return type:

InternalSession

Returns:

New InternalSession branched from the checkpoint.

created_at: Optional[datetime] = None
external_session_id: int = 0
classmethod from_dict(data)[source]

Create an InternalSession from dictionary data.

Parameters:

data (dict) – Dictionary containing session data.

Return type:

InternalSession

Returns:

InternalSession instance.

get_branch_info()[source]

Get branch information for this session.

Return type:

Dict[str, Any]

Returns:

Dictionary with branch details.

get_statistics()[source]

Get session statistics.

Return type:

Dict[str, Any]

Returns:

Dictionary with session statistics.

id: Optional[int] = None
increment_tool_count(count=1)[source]

Increment the tool invocation counter.

Parameters:

count (int) – Number to increment by.

is_branch()[source]

Check if this session is a branch from another session.

Return type:

bool

Returns:

True if this is a branched session.

is_current: bool = True
langgraph_session_id: str = ''
metadata: Dict[str, Any]
parent_session_id: Optional[int] = None
session_state: Dict[str, Any]
to_dict()[source]

Convert internal session to dictionary representation.

Return type:

dict

Returns:

Dictionary with session data.

tool_invocation_count: int = 0
update_metadata(metadata)[source]

Update session metadata.

Parameters:

metadata (Dict[str, Any]) – Metadata to merge with existing metadata.

update_state(new_state)[source]

Update the session state.

Parameters:

new_state (Dict[str, Any]) – Dictionary with state updates.

Module contents