xpander-sdk 1.60.8__py3-none-any.whl → 2.0.155__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. xpander_sdk/__init__.py +76 -7793
  2. xpander_sdk/consts/__init__.py +0 -0
  3. xpander_sdk/consts/api_routes.py +63 -0
  4. xpander_sdk/core/__init__.py +0 -0
  5. xpander_sdk/core/module_base.py +164 -0
  6. xpander_sdk/core/state.py +10 -0
  7. xpander_sdk/core/xpander_api_client.py +119 -0
  8. xpander_sdk/exceptions/__init__.py +0 -0
  9. xpander_sdk/exceptions/module_exception.py +45 -0
  10. xpander_sdk/models/__init__.py +0 -0
  11. xpander_sdk/models/activity.py +65 -0
  12. xpander_sdk/models/configuration.py +92 -0
  13. xpander_sdk/models/events.py +70 -0
  14. xpander_sdk/models/frameworks.py +64 -0
  15. xpander_sdk/models/shared.py +102 -0
  16. xpander_sdk/models/user.py +21 -0
  17. xpander_sdk/modules/__init__.py +0 -0
  18. xpander_sdk/modules/agents/__init__.py +0 -0
  19. xpander_sdk/modules/agents/agents_module.py +164 -0
  20. xpander_sdk/modules/agents/models/__init__.py +0 -0
  21. xpander_sdk/modules/agents/models/agent.py +477 -0
  22. xpander_sdk/modules/agents/models/agent_list.py +107 -0
  23. xpander_sdk/modules/agents/models/knowledge_bases.py +33 -0
  24. xpander_sdk/modules/agents/sub_modules/__init__.py +0 -0
  25. xpander_sdk/modules/agents/sub_modules/agent.py +953 -0
  26. xpander_sdk/modules/agents/utils/__init__.py +0 -0
  27. xpander_sdk/modules/agents/utils/generic.py +2 -0
  28. xpander_sdk/modules/backend/__init__.py +0 -0
  29. xpander_sdk/modules/backend/backend_module.py +425 -0
  30. xpander_sdk/modules/backend/frameworks/__init__.py +0 -0
  31. xpander_sdk/modules/backend/frameworks/agno.py +627 -0
  32. xpander_sdk/modules/backend/frameworks/dispatch.py +36 -0
  33. xpander_sdk/modules/backend/utils/__init__.py +0 -0
  34. xpander_sdk/modules/backend/utils/mcp_oauth.py +95 -0
  35. xpander_sdk/modules/events/__init__.py +0 -0
  36. xpander_sdk/modules/events/decorators/__init__.py +0 -0
  37. xpander_sdk/modules/events/decorators/on_boot.py +94 -0
  38. xpander_sdk/modules/events/decorators/on_shutdown.py +94 -0
  39. xpander_sdk/modules/events/decorators/on_task.py +203 -0
  40. xpander_sdk/modules/events/events_module.py +629 -0
  41. xpander_sdk/modules/events/models/__init__.py +0 -0
  42. xpander_sdk/modules/events/models/deployments.py +25 -0
  43. xpander_sdk/modules/events/models/events.py +57 -0
  44. xpander_sdk/modules/events/utils/__init__.py +0 -0
  45. xpander_sdk/modules/events/utils/generic.py +56 -0
  46. xpander_sdk/modules/events/utils/git_init.py +32 -0
  47. xpander_sdk/modules/knowledge_bases/__init__.py +0 -0
  48. xpander_sdk/modules/knowledge_bases/knowledge_bases_module.py +217 -0
  49. xpander_sdk/modules/knowledge_bases/models/__init__.py +0 -0
  50. xpander_sdk/modules/knowledge_bases/models/knowledge_bases.py +11 -0
  51. xpander_sdk/modules/knowledge_bases/sub_modules/__init__.py +0 -0
  52. xpander_sdk/modules/knowledge_bases/sub_modules/knowledge_base.py +107 -0
  53. xpander_sdk/modules/knowledge_bases/sub_modules/knowledge_base_document_item.py +40 -0
  54. xpander_sdk/modules/knowledge_bases/utils/__init__.py +0 -0
  55. xpander_sdk/modules/tasks/__init__.py +0 -0
  56. xpander_sdk/modules/tasks/models/__init__.py +0 -0
  57. xpander_sdk/modules/tasks/models/task.py +153 -0
  58. xpander_sdk/modules/tasks/models/tasks_list.py +107 -0
  59. xpander_sdk/modules/tasks/sub_modules/__init__.py +0 -0
  60. xpander_sdk/modules/tasks/sub_modules/task.py +887 -0
  61. xpander_sdk/modules/tasks/tasks_module.py +492 -0
  62. xpander_sdk/modules/tasks/utils/__init__.py +0 -0
  63. xpander_sdk/modules/tasks/utils/files.py +114 -0
  64. xpander_sdk/modules/tools_repository/__init__.py +0 -0
  65. xpander_sdk/modules/tools_repository/decorators/__init__.py +0 -0
  66. xpander_sdk/modules/tools_repository/decorators/register_tool.py +108 -0
  67. xpander_sdk/modules/tools_repository/models/__init__.py +0 -0
  68. xpander_sdk/modules/tools_repository/models/mcp.py +68 -0
  69. xpander_sdk/modules/tools_repository/models/tool_invocation_result.py +14 -0
  70. xpander_sdk/modules/tools_repository/sub_modules/__init__.py +0 -0
  71. xpander_sdk/modules/tools_repository/sub_modules/tool.py +578 -0
  72. xpander_sdk/modules/tools_repository/tools_repository_module.py +259 -0
  73. xpander_sdk/modules/tools_repository/utils/__init__.py +0 -0
  74. xpander_sdk/modules/tools_repository/utils/generic.py +57 -0
  75. xpander_sdk/modules/tools_repository/utils/local_tools.py +52 -0
  76. xpander_sdk/modules/tools_repository/utils/schemas.py +308 -0
  77. xpander_sdk/utils/__init__.py +0 -0
  78. xpander_sdk/utils/env.py +44 -0
  79. xpander_sdk/utils/event_loop.py +67 -0
  80. xpander_sdk/utils/tools.py +32 -0
  81. xpander_sdk-2.0.155.dist-info/METADATA +538 -0
  82. xpander_sdk-2.0.155.dist-info/RECORD +85 -0
  83. {xpander_sdk-1.60.8.dist-info → xpander_sdk-2.0.155.dist-info}/WHEEL +1 -1
  84. {xpander_sdk-1.60.8.dist-info → xpander_sdk-2.0.155.dist-info/licenses}/LICENSE +0 -1
  85. xpander_sdk/_jsii/__init__.py +0 -39
  86. xpander_sdk/_jsii/xpander-sdk@1.60.8.jsii.tgz +0 -0
  87. xpander_sdk/py.typed +0 -1
  88. xpander_sdk-1.60.8.dist-info/METADATA +0 -368
  89. xpander_sdk-1.60.8.dist-info/RECORD +0 -9
  90. {xpander_sdk-1.60.8.dist-info → xpander_sdk-2.0.155.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,64 @@
1
+ from enum import Enum
2
+ from typing import List, Optional
3
+ from pydantic import BaseModel
4
+
5
+
6
+ class Framework(str, Enum):
7
+ """
8
+ Enum representing supported frameworks within xpander.ai.
9
+
10
+ Attributes:
11
+ Agno (str): Agno framework identifier.
12
+ """
13
+
14
+ Agno = "agno"
15
+ GoogleADK = "google-adk"
16
+ LangChain = "langchain"
17
+ OpenAIAgents = "open-ai-agents"
18
+ Strands = "strands-agents"
19
+
20
+ class AgnoToolCallsCompressionSettings(BaseModel):
21
+ enabled: Optional[bool] = False
22
+ threshold: Optional[int] = 3
23
+ instructions: Optional[str] = ""
24
+
25
+ class AgnoSettings(BaseModel):
26
+ """
27
+ Configuration settings specific to the Agno framework.
28
+
29
+ Attributes:
30
+ session_storage (Optional[bool]): If True, enables session-level storage. Default is True.
31
+ user_memories (Optional[bool]): If True, enables memory of user interactions. Default is True.
32
+ session_summaries (Optional[bool]): If True, enables generation of session summaries. Default is False.
33
+ num_history_runs (Optional[int]): Number of historical runs to retain or consider. Default is 3.
34
+ tool_call_limit (Optional[int]): Max tool calls per run.
35
+ coordinate_mode (Optional[bool]): If True, The agent will be loaded as a Team. Default is False.
36
+ pii_detection_enabled (Optional[bool]): If True, enables PII detection guardrail on agent input. Default is False.
37
+ pii_detection_mask (Optional[bool]): If True, masks detected PII instead of blocking. Default is False.
38
+ prompt_injection_detection_enabled (Optional[bool]): If True, enables prompt injection detection guardrail. Default is False.
39
+ openai_moderation_enabled (Optional[bool]): If True, enables OpenAI content moderation guardrail. Default is False.
40
+ openai_moderation_categories (Optional[List[str]]): List of specific OpenAI moderation categories to enforce. If None, all categories are checked.
41
+ reasoning_tools_enabled (Optional[bool]): If True, enables Agno's reasoning tools (analyze, think, instructions and few shot). Default is False.
42
+ """
43
+
44
+ session_storage: Optional[bool] = True
45
+
46
+ user_memories: Optional[bool] = False
47
+ agentic_memory: Optional[bool] = False
48
+
49
+ agent_memories: Optional[bool] = False
50
+ agentic_culture: Optional[bool] = False
51
+
52
+ session_summaries: Optional[bool] = False
53
+ num_history_runs: Optional[int] = 3
54
+ max_tool_calls_from_history: Optional[int] = 0
55
+ tool_call_limit: Optional[int] = None
56
+ coordinate_mode: Optional[bool] = False
57
+ pii_detection_enabled: Optional[bool] = False
58
+ pii_detection_mask: Optional[bool] = True
59
+ prompt_injection_detection_enabled: Optional[bool] = False
60
+ openai_moderation_enabled: Optional[bool] = False
61
+ openai_moderation_categories: Optional[List[str]] = None
62
+ reasoning_tools_enabled: Optional[bool] = False
63
+
64
+ tool_calls_compression: Optional[AgnoToolCallsCompressionSettings] = None
@@ -0,0 +1,102 @@
1
+ """
2
+ Shared models and utilities for the xpander.ai SDK.
3
+
4
+ This module contains common base classes, enums, and type definitions used
5
+ across the entire SDK for consistent data handling and serialization.
6
+ """
7
+
8
+ from abc import ABC
9
+ from enum import Enum
10
+ import json
11
+ from typing import Optional
12
+ from pydantic import BaseModel, computed_field
13
+
14
+
15
+ class XPanderSharedModel(BaseModel):
16
+ """
17
+ Base model class for all xpander.ai SDK models.
18
+
19
+ This class extends Pydantic's BaseModel with additional functionality
20
+ for safe serialization of complex data types including Enums.
21
+
22
+ Methods:
23
+ model_dump_safe: Safely serialize the model with proper Enum handling.
24
+ """
25
+
26
+ def model_dump_safe(self, **kwargs) -> dict:
27
+ """
28
+ Safely serialize the model to a dictionary with proper Enum handling.
29
+
30
+ This method ensures that Enum values are properly serialized as their
31
+ string representations rather than Enum objects, making the output
32
+ JSON-compatible and suitable for API requests.
33
+
34
+ Args:
35
+ **kwargs: Additional keyword arguments passed to model_dump_json().
36
+
37
+ Returns:
38
+ dict: A dictionary representation of the model with all values
39
+ properly serialized for JSON compatibility.
40
+
41
+ Example:
42
+ >>> class MyModel(XPanderSharedModel):
43
+ ... format: OutputFormat = OutputFormat.Json
44
+ >>> model = MyModel()
45
+ >>> model.model_dump_safe()
46
+ {'format': 'json'}
47
+ """
48
+ return json.loads(self.model_dump_json(**kwargs))
49
+
50
+
51
+ class OutputFormat(str, Enum):
52
+ """
53
+ Enumeration of supported output formats for xpander.ai operations.
54
+
55
+ This enum defines the various output formats that can be used when
56
+ requesting data from xpander.ai services, allowing for flexible
57
+ response formatting based on use case requirements.
58
+
59
+ Values:
60
+ Text: Plain text format for simple string responses.
61
+ Markdown: Markdown format for rich text with formatting.
62
+ Json: JSON format for structured data responses.
63
+
64
+ Example:
65
+ >>> format_type = OutputFormat.Markdown
66
+ >>> print(format_type.value)
67
+ 'markdown'
68
+ """
69
+
70
+ Text = "text"
71
+ Markdown = "markdown"
72
+ Json = "json"
73
+
74
+
75
+ # Type alias for Language Model types
76
+ LLMModelT = type[ABC]
77
+ """
78
+ Type alias for Language Model types.
79
+
80
+ This type alias is used throughout the SDK to represent different
81
+ LLM (Large Language Model) implementations that can be used with xpander.ai.
82
+ The models should inherit from ABC (Abstract Base Class) to ensure
83
+ proper interface implementation.
84
+ """
85
+
86
+ class Tokens(BaseModel):
87
+ completion_tokens: Optional[int] = 0
88
+ prompt_tokens: Optional[int] = 0
89
+
90
+ @computed_field
91
+ @property
92
+ def total_tokens(self) -> int:
93
+ return self.completion_tokens+self.prompt_tokens
94
+
95
+
96
+ class ExecutionTokens(BaseModel):
97
+ inner: Optional[Tokens] = Tokens()
98
+ worker: Optional[Tokens] = Tokens()
99
+
100
+ class ThinkMode(str, Enum):
101
+ Default = "default"
102
+ Harder = "harder"
@@ -0,0 +1,21 @@
1
+ from typing import Optional
2
+ from pydantic import BaseModel
3
+
4
+
5
+ class User(BaseModel):
6
+ """
7
+ Represents the details of a user.
8
+
9
+ Attributes:
10
+ id (Optional[str]): The unique identifier of the user. Defaults to None.
11
+ first_name (Optional[str]): The first name of the user. Defaults to None.
12
+ last_name (Optional[str]): The last name of the user. Defaults to None.
13
+ email (str): The email address of the user. This field is required.
14
+ additional_attributes (Optional[dict]): Possible additional parameters for the assistant's service.
15
+ """
16
+
17
+ id: Optional[str] = None
18
+ first_name: Optional[str] = None
19
+ last_name: Optional[str] = None
20
+ email: str
21
+ additional_attributes: Optional[dict] = None
File without changes
File without changes
@@ -0,0 +1,164 @@
1
+ """
2
+ Agents module for managing AI agents in the xpander.ai platform.
3
+
4
+ This module provides functionality to list, retrieve, and manage AI agents
5
+ within the xpander.ai Backend-as-a-Service platform.
6
+ """
7
+
8
+ from typing import List, Optional
9
+ from os import getenv
10
+ from httpx import HTTPStatusError
11
+
12
+ from xpander_sdk.consts.api_routes import APIRoute
13
+ from xpander_sdk.core.module_base import ModuleBase
14
+ from xpander_sdk.core.xpander_api_client import APIClient
15
+ from xpander_sdk.exceptions.module_exception import ModuleException
16
+ from xpander_sdk.models.configuration import Configuration
17
+ from xpander_sdk.modules.agents.models.agent_list import AgentsListItem
18
+ from xpander_sdk.modules.agents.sub_modules.agent import Agent
19
+ from xpander_sdk.utils.event_loop import run_sync
20
+
21
+
22
+ class Agents(ModuleBase):
23
+ """
24
+ Main module for managing AI agents in xpander.ai.
25
+
26
+ This class provides both synchronous and asynchronous methods for listing
27
+ and retrieving AI agents from the xpander.ai platform. It handles agent
28
+ discovery, versioning, and provides access to individual agent instances.
29
+
30
+ The module follows the singleton pattern inherited from ModuleBase,
31
+ ensuring consistent configuration across all agent operations.
32
+
33
+ Example:
34
+ >>> agents = Agents()
35
+ >>> agent_list = agents.list()
36
+ >>> specific_agent = agents.get("agent-id-123")
37
+ >>> specific_version = agents.get("agent-id-123", version=2)
38
+ """
39
+
40
+ def __init__(self, configuration: Optional[Configuration] = None):
41
+ """
42
+ Initialize the Agents module.
43
+
44
+ Args:
45
+ configuration (Optional[Configuration]): SDK configuration. If None,
46
+ will use default configuration from environment variables.
47
+ """
48
+ super().__init__(configuration)
49
+
50
+ async def alist(self) -> List[AgentsListItem]:
51
+ """
52
+ Asynchronously list all available agents.
53
+
54
+ Retrieves a list of all agents accessible to the current user/organization.
55
+ Each item in the list contains basic agent information including ID, name,
56
+ status, and metadata.
57
+
58
+ Returns:
59
+ List[AgentsListItem]: List of agent summary objects containing
60
+ basic information about each agent.
61
+
62
+ Raises:
63
+ ModuleException: If the API request fails or returns an error.
64
+ The exception will contain the HTTP status code and error message.
65
+
66
+ Example:
67
+ >>> agents = Agents()
68
+ >>> agent_list = await agents.alist()
69
+ >>> for agent in agent_list:
70
+ ... print(f"Agent: {agent.name} (ID: {agent.id})")
71
+ """
72
+ try:
73
+ client = APIClient(configuration=self.configuration)
74
+ agents = await client.make_request(path=APIRoute.ListAgent)
75
+ return [AgentsListItem(**agent) for agent in agents]
76
+ except Exception as e:
77
+ if isinstance(e, HTTPStatusError):
78
+ raise ModuleException(e.response.status_code, e.response.text)
79
+ raise ModuleException(500, f"Failed to list agents - {str(e)}")
80
+
81
+ def list(self) -> List[AgentsListItem]:
82
+ """
83
+ Synchronously list all available agents.
84
+
85
+ This is the synchronous version of alist(). It internally calls the
86
+ asynchronous method and waits for completion.
87
+
88
+ Returns:
89
+ List[AgentsListItem]: List of agent summary objects containing
90
+ basic information about each agent.
91
+
92
+ Raises:
93
+ ModuleException: If the API request fails or returns an error.
94
+
95
+ Example:
96
+ >>> agents = Agents()
97
+ >>> agent_list = agents.list()
98
+ >>> print(f"Found {len(agent_list)} agents")
99
+ """
100
+ return run_sync(self.alist())
101
+
102
+ async def aget(self, agent_id: Optional[str] = None, version: Optional[int] = None) -> Agent:
103
+ """
104
+ Asynchronously retrieve a specific agent by ID.
105
+
106
+ Loads and returns a full Agent object with complete configuration,
107
+ graph definitions, and all associated metadata. Optionally loads
108
+ a specific version of the agent.
109
+
110
+ Args:
111
+ agent_id (Optional[str]): Unique identifier of the agent to retrieve, Fallback to XPANDER_AGENT_ID.
112
+ version (Optional[int]): Specific version number to load. If None,
113
+ loads the latest version.
114
+
115
+ Returns:
116
+ Agent: Complete agent object with full configuration and capabilities.
117
+
118
+ Raises:
119
+ ModuleException: If the agent is not found, access is denied,
120
+ or the API request fails.
121
+
122
+ Example:
123
+ >>> agents = Agents()
124
+ >>> agent = await agents.aget("agent-123")
125
+ >>> print(f"Loaded agent: {agent.name}")
126
+
127
+ >>> # Load specific version
128
+ >>> agent_v2 = await agents.aget("agent-123", version=2)
129
+ """
130
+ return await Agent.aload(
131
+ agent_id=agent_id or self.configuration.agent_id or getenv("XPANDER_AGENT_ID"),
132
+ configuration=self.configuration, version=version
133
+ )
134
+
135
+ def get(self, agent_id: Optional[str] = None, version: Optional[int] = None) -> Agent:
136
+ """
137
+ Synchronously retrieve a specific agent by ID.
138
+
139
+ This is the synchronous version of aget(). It internally calls the
140
+ asynchronous method and waits for completion.
141
+
142
+ Args:
143
+ agent_id (Optional[str]): Unique identifier of the agent to retrieve, Fallback to XPANDER_AGENT_ID.
144
+ version (Optional[int]): Specific version number to load. If None,
145
+ loads the latest version.
146
+
147
+ Returns:
148
+ Agent: Complete agent object with full configuration and capabilities.
149
+
150
+ Raises:
151
+ ModuleException: If the agent is not found, access is denied,
152
+ or the API request fails.
153
+
154
+ Example:
155
+ >>> agents = Agents()
156
+ >>> agent = agents.get("agent-123")
157
+ >>> result = agent.execute("What is the weather today?")
158
+ """
159
+ return run_sync(
160
+ self.aget(
161
+ agent_id=agent_id,
162
+ version=version
163
+ )
164
+ )
File without changes