Skip to content

Latest commit

 

History

History
101 lines (75 loc) · 3.11 KB

context-manager.md

File metadata and controls

101 lines (75 loc) · 3.11 KB

ContextManager API Reference

The ContextManager class provides functionality for managing contexts within a session. It enables you to interact with the contexts that are synchronized to the session, including reading and writing data, and managing file operations.

Properties

session  # The Session instance that this ContextManager belongs to

Data Types

class ContextStatusData:
    context_id: str     # The ID of the context
    path: str           # The path where the context is mounted
    error_message: str  # Error message if the operation failed
    status: str         # Status of the synchronization task
    start_time: int     # Start time of the task (Unix timestamp)
    finish_time: int    # Finish time of the task (Unix timestamp)
    task_type: str      # Type of the task (e.g., "upload", "download")

Methods

info

Gets information about context synchronization status.

info(context_id: Optional[str] = None, path: Optional[str] = None, task_type: Optional[str] = None) -> ContextInfoResult

Parameters:

  • context_id (str, optional): The ID of the context to get information for.
  • path (str, optional): The path where the context is mounted.
  • task_type (str, optional): The type of task to get information for.

Returns:

  • ContextInfoResult: A result object containing the context status data, success status, and request ID. This class inherits from ApiResponse.
    • context_status_data (List[ContextStatusData]): A list of context status data objects.

Example:

from agentbay import AgentBay

# Initialize the SDK
agent_bay = AgentBay(api_key="your_api_key")

# Create a session
result = agent_bay.create()
if result.success:
    session = result.session
    
    # Get context synchronization information
    info_result = session.context.info()
    if info_result.context_status_data:
        for item in info_result.context_status_data:
            print(f"Context {item.context_id} status: {item.status}")
    else:
        print("No context synchronization tasks found")

sync

Synchronizes a context with the session.

sync(context_id: Optional[str] = None, path: Optional[str] = None, mode: Optional[str] = None) -> ContextSyncResult

Parameters:

  • context_id (str, optional): The ID of the context to synchronize.
  • path (str, optional): The path where the context should be mounted.
  • mode (str, optional): The synchronization mode.

Returns:

  • ContextSyncResult: A result object containing success status and request ID.
    • success (bool): Indicates whether the synchronization was successful.

Example:

from agentbay import AgentBay

# Initialize the SDK
agent_bay = AgentBay(api_key="your_api_key")

# Create a session
result = agent_bay.create()
if result.success:
    session = result.session
    
    # Trigger context synchronization
    sync_result = session.context.sync()
    
    if sync_result.success:
        print(f"Context synchronization triggered successfully, request ID: {sync_result.request_id}")
    else:
        print(f"Failed to trigger context synchronization")