xpander-sdk 1.60.4__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.4.dist-info → xpander_sdk-2.0.155.dist-info}/WHEEL +1 -1
  84. {xpander_sdk-1.60.4.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.4.jsii.tgz +0 -0
  87. xpander_sdk/py.typed +0 -1
  88. xpander_sdk-1.60.4.dist-info/METADATA +0 -368
  89. xpander_sdk-1.60.4.dist-info/RECORD +0 -9
  90. {xpander_sdk-1.60.4.dist-info → xpander_sdk-2.0.155.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,108 @@
1
+ """
2
+ Decorator for registering local tools in the xpander.ai SDK.
3
+
4
+ This module provides the @register_tool decorator that allows developers to
5
+ register Python functions as tools that can be used by AI agents in the
6
+ xpander.ai platform.
7
+ """
8
+
9
+ import inspect
10
+ from typing import Callable, Any, Optional, get_type_hints, Union
11
+ from pydantic import create_model
12
+ from xpander_sdk.modules.tools_repository.sub_modules.tool import Tool
13
+ from xpander_sdk.modules.tools_repository.tools_repository_module import ToolsRepository
14
+
15
+
16
+ def register_tool(
17
+ func: Optional[Callable] = None,
18
+ *,
19
+ add_to_graph: Optional[bool] = False
20
+ ) -> Union[Callable, Tool]:
21
+ """
22
+ Decorator to register a Python function as a tool for xpander.ai agents.
23
+
24
+ This decorator automatically creates a Tool object from a Python function,
25
+ extracting type hints and docstrings to generate a proper tool schema that
26
+ can be used by AI agents. The decorated function becomes available in the
27
+ tools repository and can optionally be added to agent execution graphs.
28
+
29
+ Args:
30
+ func (Optional[Callable]): The function to register (used for @register_tool syntax).
31
+ add_to_graph (Optional[bool]): Whether to automatically add this tool to
32
+ agent execution graphs. Defaults to False.
33
+
34
+ Returns:
35
+ Union[Callable, Tool]: The original function (preserves functionality) or
36
+ a partial decorator when used with arguments.
37
+
38
+ Raises:
39
+ TypeError: If the decorated object is not a callable function.
40
+
41
+ Example:
42
+ >>> @register_tool
43
+ ... def calculate_sum(a: int, b: int) -> int:
44
+ ... return a + b
45
+
46
+ >>> @register_tool(add_to_graph=True)
47
+ ... def fetch_weather(city: str, country: str = "US") -> str:
48
+ ... # Implementation here
49
+ ... return f"Weather for {city}, {country}"
50
+
51
+ >>> # The functions remain callable as normal
52
+ >>> result = calculate_sum(5, 3) # Returns 8
53
+
54
+ >>> # But are also available as tools
55
+ >>> tools = ToolsRepository()
56
+ >>> tool = tools.get_tool_by_id("calculate_sum")
57
+ """
58
+
59
+ def decorator(inner_func: Callable) -> Callable:
60
+ """
61
+ Inner decorator that processes the function and creates a tool.
62
+
63
+ Args:
64
+ inner_func (Callable): The function to be registered as a tool.
65
+
66
+ Returns:
67
+ Callable: The original function, unchanged in functionality.
68
+ """
69
+ # Extract function signature and type hints
70
+ sig = inspect.signature(inner_func)
71
+ hints = get_type_hints(inner_func)
72
+
73
+ # Build Pydantic model for function arguments
74
+ fields = {}
75
+ for name, param in sig.parameters.items():
76
+ annotation = hints.get(name, Any)
77
+ default = param.default if param.default is not inspect.Parameter.empty else ...
78
+ fields[name] = (annotation, default)
79
+
80
+ # Create a Pydantic model class for argument validation
81
+ ArgsModel = create_model(f"{inner_func.__name__.title()}Args", **fields) # type: ignore
82
+
83
+ # Create Tool object with extracted metadata
84
+ tool = Tool(
85
+ id=inner_func.__name__,
86
+ name=inner_func.__name__,
87
+ method="POST",
88
+ path=f"/tools/{inner_func.__name__}",
89
+ description=inspect.getdoc(inner_func) or "",
90
+ parameters=ArgsModel.model_json_schema(mode="serialization"),
91
+ fn=inner_func,
92
+ is_local=True,
93
+ should_add_to_graph=add_to_graph
94
+ )
95
+
96
+ # Register the tool in the global repository
97
+ ToolsRepository.register_tool(tool)
98
+
99
+ # Return the original function unchanged
100
+ return inner_func
101
+
102
+ # Handle both @register_tool and @register_tool(...) syntax
103
+ if func is None:
104
+ # Called with arguments: @register_tool(add_to_graph=True)
105
+ return decorator
106
+ else:
107
+ # Called without parentheses: @register_tool
108
+ return decorator(func)
@@ -0,0 +1,68 @@
1
+ from enum import Enum
2
+ from typing import Dict, List, Optional, Union
3
+
4
+ from pydantic import BaseModel
5
+
6
+ from xpander_sdk.models.shared import XPanderSharedModel
7
+
8
+
9
+ class MCPServerType(str, Enum):
10
+ Local = "local"
11
+ Remote = "remote"
12
+
13
+ class MCPServerAuthType(str, Enum):
14
+ APIKey = "api_key"
15
+ OAuth2 = "oauth2"
16
+ CustomHeaders = "custom_headers"
17
+ _None = "none"
18
+
19
+ class MCPServerTransport(str, Enum):
20
+ STDIO = "stdio"
21
+ SSE = "sse"
22
+ HTTP_Transport = "streamable-http"
23
+
24
+ class MCPServerDetails(BaseModel):
25
+ type: Optional[MCPServerType] = MCPServerType.Remote
26
+ name: Optional[str] = None
27
+ command: Optional[str] = None
28
+ url: Optional[str] = None
29
+ transport: Optional[MCPServerTransport] = MCPServerTransport.HTTP_Transport
30
+ auth_type: Optional[MCPServerAuthType] = MCPServerAuthType._None
31
+ api_key: Optional[str] = None
32
+ client_id: Optional[str] = None
33
+ client_secret: Optional[str] = None
34
+ headers: Optional[Dict] = {}
35
+ env_vars: Optional[Dict] = {}
36
+ allowed_tools: Optional[List[str]] = []
37
+ additional_scopes: Optional[List[str]] = []
38
+ share_user_token_across_other_agents: Optional[bool] = True
39
+
40
+
41
+ class MCPOAuthResponseType(str, Enum):
42
+ NOT_SUPPORTED = "not_supported"
43
+ LOGIN_REQUIRED = "login_required"
44
+ TOKEN_ISSUE = "token_issue"
45
+ TOKEN_READY = "token_ready"
46
+
47
+
48
+ class MCPOAuthGetTokenGenericResponse(XPanderSharedModel):
49
+ message: str
50
+
51
+
52
+ class MCPOAuthGetTokenLoginRequiredResponse(XPanderSharedModel):
53
+ url: str
54
+ server_url: str
55
+ server_name: str
56
+
57
+
58
+ class MCPOAuthGetTokenTokenReadyResponse(XPanderSharedModel):
59
+ access_token: str
60
+
61
+
62
+ class MCPOAuthGetTokenResponse(XPanderSharedModel):
63
+ type: MCPOAuthResponseType
64
+ data: Union[
65
+ MCPOAuthGetTokenTokenReadyResponse,
66
+ MCPOAuthGetTokenLoginRequiredResponse,
67
+ MCPOAuthGetTokenGenericResponse,
68
+ ]
@@ -0,0 +1,14 @@
1
+ from typing import Any, Optional
2
+ from xpander_sdk.models.shared import XPanderSharedModel
3
+
4
+
5
+ class ToolInvocationResult(XPanderSharedModel):
6
+ tool_id: str
7
+ tool_call_id: Optional[str] = None
8
+ task_id: Optional[str] = None
9
+ payload: Optional[Any] = None
10
+ status_code: Optional[int] = 200
11
+ result: Optional[Any] = None
12
+ is_success: Optional[bool] = False
13
+ is_error: Optional[bool] = False
14
+ is_local: Optional[bool] = False