MCPcopy Create free account
hub / github.com/aliyun/data-agent-skill / create_session

Method create_session

scripts/data_agent/client.py:643–744  ·  view source on GitHub ↗

Create a new Data Agent session. Args: database_id: Optional database ID to bind to the session. title: Session title (required by API). mode: Optional session mode, such as "ASK_DATA", "ANALYSIS", "INSIGHT". enable_search: Whether to enable s

(
        self,
        database_id: Optional[str] = None,
        title: str = "data-agent-session",
        mode: Optional[str] = None,
        enable_search: bool = False,
        file_id: Optional[str] = None,  # 添加文件ID参数
        workspace_id: Optional[str] = None,
        custom_agent_id: Optional[str] = None,
        client_token: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

641
642 @retry_on_error(max_retries=3)
643 def create_session(
644 self,
645 database_id: Optional[str] = None,
646 title: str = "data-agent-session",
647 mode: Optional[str] = None,
648 enable_search: bool = False,
649 file_id: Optional[str] = None,
650 workspace_id: Optional[str] = None,
651 custom_agent_id: Optional[str] = None,
652 client_token: Optional[str] = None,
653 plan_mode: Optional[str] = "force",
654 ) -> SessionInfo:
655 """Create a new Data Agent session.
656
657 Args:
658 database_id: Optional database ID to bind to the session.
659 title: Session title (required by API).
660 mode: Optional session mode: "auto", "lite", "pro", "ultra".
661 enable_search: Whether to enable search capability in the session.
662 file_id: Optional file ID for file-based analysis session.
663 workspace_id: Optional workspace ID to bind to the session.
664 custom_agent_id: Optional custom agent ID to use for the session.
665 client_token: Optional idempotency token, auto-generated for retries.
666 plan_mode: Plan mode: "force" (default, always plan) or "disable" (skip planning).
667
668 Returns:
669 SessionInfo with agent_id and session_id.
670
671 Raises:
672 SessionCreationError: If session creation fails.
673 """
674 params = {
675 "Title": title,
676 "DMSUnit": self._resolve_dms_unit(),
677 }
678 if database_id:
679 params["DatabaseId"] = database_id
680 if mode:
681 params["Mode"] = mode
682 if file_id:
683 # 当指定了文件ID时,会话将是基于文件的分析
684 params["File"] = file_id
685 if workspace_id:
686 params["WorkspaceId"] = workspace_id
687 if client_token:
688 params["ClientToken"] = client_token
689
690 # Ensure session configuration (language/mode/search) is persisted on server
691 session_config = {"Language": "CHINESE", "EnableSearch": enable_search}
692 if mode:
693 session_config["Mode"] = mode
694 if plan_mode:
695 session_config["PlanMode"] = plan_mode
696 if custom_agent_id:
697 session_config["CustomAgentId"] = custom_agent_id
698 session_config["CustomAgentStage"] = "prod"
699
700 # For API_KEY auth, SessionConfig should be a JSON object, not string

Callers 2

create_or_reuseMethod · 0.45
create_or_reuseMethod · 0.45

Calls 4

_resolve_dms_unitMethod · 0.95
_call_apiMethod · 0.95
SessionInfoClass · 0.90

Tested by

no test coverage detected