xpander-sdk 1.59.0__tar.gz → 2.0.219__tar.gz

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 (125) hide show
  1. {xpander_sdk-1.59.0 → xpander_sdk-2.0.219}/LICENSE +0 -1
  2. xpander_sdk-2.0.219/PKG-INFO +622 -0
  3. xpander_sdk-2.0.219/README.md +572 -0
  4. xpander_sdk-2.0.219/pyproject.toml +19 -0
  5. xpander_sdk-2.0.219/setup.py +39 -0
  6. xpander_sdk-2.0.219/src/xpander_sdk/__init__.py +92 -0
  7. xpander_sdk-2.0.219/src/xpander_sdk/consts/__init__.py +0 -0
  8. xpander_sdk-2.0.219/src/xpander_sdk/consts/api_routes.py +76 -0
  9. xpander_sdk-2.0.219/src/xpander_sdk/core/__init__.py +0 -0
  10. xpander_sdk-2.0.219/src/xpander_sdk/core/module_base.py +164 -0
  11. xpander_sdk-2.0.219/src/xpander_sdk/core/state.py +10 -0
  12. xpander_sdk-2.0.219/src/xpander_sdk/core/xpander_api_client.py +119 -0
  13. xpander_sdk-2.0.219/src/xpander_sdk/exceptions/__init__.py +0 -0
  14. xpander_sdk-2.0.219/src/xpander_sdk/exceptions/module_exception.py +45 -0
  15. xpander_sdk-2.0.219/src/xpander_sdk/models/__init__.py +0 -0
  16. xpander_sdk-2.0.219/src/xpander_sdk/models/activity.py +65 -0
  17. xpander_sdk-2.0.219/src/xpander_sdk/models/compactization.py +112 -0
  18. xpander_sdk-2.0.219/src/xpander_sdk/models/configuration.py +92 -0
  19. xpander_sdk-2.0.219/src/xpander_sdk/models/deep_planning.py +18 -0
  20. xpander_sdk-2.0.219/src/xpander_sdk/models/events.py +76 -0
  21. xpander_sdk-2.0.219/src/xpander_sdk/models/frameworks.py +64 -0
  22. xpander_sdk-2.0.219/src/xpander_sdk/models/generic.py +27 -0
  23. xpander_sdk-2.0.219/src/xpander_sdk/models/notifications.py +111 -0
  24. xpander_sdk-2.0.219/src/xpander_sdk/models/orchestrations.py +368 -0
  25. xpander_sdk-2.0.219/src/xpander_sdk/models/shared.py +102 -0
  26. xpander_sdk-2.0.219/src/xpander_sdk/models/user.py +21 -0
  27. xpander_sdk-2.0.219/src/xpander_sdk/modules/__init__.py +0 -0
  28. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/__init__.py +0 -0
  29. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/agents_module.py +164 -0
  30. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/models/__init__.py +0 -0
  31. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/models/agent.py +510 -0
  32. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/models/agent_list.py +107 -0
  33. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/models/knowledge_bases.py +33 -0
  34. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/sub_modules/__init__.py +0 -0
  35. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/sub_modules/agent.py +970 -0
  36. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/utils/__init__.py +0 -0
  37. xpander_sdk-2.0.219/src/xpander_sdk/modules/agents/utils/generic.py +2 -0
  38. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/__init__.py +8 -0
  39. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/backend_module.py +470 -0
  40. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/decorators/__init__.py +7 -0
  41. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/decorators/on_auth_event.py +131 -0
  42. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/events_registry.py +172 -0
  43. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/frameworks/__init__.py +0 -0
  44. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/frameworks/agno.py +1020 -0
  45. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/frameworks/dispatch.py +38 -0
  46. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/utils/__init__.py +0 -0
  47. xpander_sdk-2.0.219/src/xpander_sdk/modules/backend/utils/mcp_oauth.py +107 -0
  48. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/__init__.py +0 -0
  49. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/decorators/__init__.py +3 -0
  50. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/decorators/on_boot.py +94 -0
  51. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/decorators/on_shutdown.py +94 -0
  52. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/decorators/on_task.py +203 -0
  53. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/decorators/on_tool.py +384 -0
  54. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/events_module.py +713 -0
  55. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/models/__init__.py +0 -0
  56. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/models/deployments.py +25 -0
  57. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/models/events.py +63 -0
  58. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/utils/__init__.py +0 -0
  59. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/utils/generic.py +56 -0
  60. xpander_sdk-2.0.219/src/xpander_sdk/modules/events/utils/git_init.py +32 -0
  61. xpander_sdk-2.0.219/src/xpander_sdk/modules/knowledge_bases/__init__.py +0 -0
  62. xpander_sdk-2.0.219/src/xpander_sdk/modules/knowledge_bases/knowledge_bases_module.py +217 -0
  63. xpander_sdk-2.0.219/src/xpander_sdk/modules/knowledge_bases/models/__init__.py +0 -0
  64. xpander_sdk-2.0.219/src/xpander_sdk/modules/knowledge_bases/models/knowledge_bases.py +11 -0
  65. xpander_sdk-2.0.219/src/xpander_sdk/modules/knowledge_bases/sub_modules/__init__.py +0 -0
  66. xpander_sdk-2.0.219/src/xpander_sdk/modules/knowledge_bases/sub_modules/knowledge_base.py +107 -0
  67. xpander_sdk-2.0.219/src/xpander_sdk/modules/knowledge_bases/sub_modules/knowledge_base_document_item.py +40 -0
  68. xpander_sdk-2.0.219/src/xpander_sdk/modules/knowledge_bases/utils/__init__.py +0 -0
  69. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/__init__.py +0 -0
  70. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/models/__init__.py +0 -0
  71. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/models/task.py +142 -0
  72. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/models/tasks_list.py +107 -0
  73. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/sub_modules/__init__.py +0 -0
  74. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/sub_modules/task.py +995 -0
  75. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/tasks_module.py +495 -0
  76. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/utils/__init__.py +0 -0
  77. xpander_sdk-2.0.219/src/xpander_sdk/modules/tasks/utils/files.py +114 -0
  78. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/__init__.py +0 -0
  79. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/decorators/__init__.py +0 -0
  80. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/decorators/register_tool.py +108 -0
  81. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/models/__init__.py +0 -0
  82. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/models/mcp.py +69 -0
  83. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/models/tool_invocation_result.py +14 -0
  84. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/sub_modules/__init__.py +0 -0
  85. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/sub_modules/tool.py +609 -0
  86. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/tools_repository_module.py +321 -0
  87. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/utils/__init__.py +0 -0
  88. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/utils/generic.py +60 -0
  89. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/utils/local_tools.py +52 -0
  90. xpander_sdk-2.0.219/src/xpander_sdk/modules/tools_repository/utils/schemas.py +321 -0
  91. xpander_sdk-2.0.219/src/xpander_sdk/utils/__init__.py +0 -0
  92. xpander_sdk-2.0.219/src/xpander_sdk/utils/agents/__init__.py +0 -0
  93. xpander_sdk-2.0.219/src/xpander_sdk/utils/agents/compactization_agent.py +257 -0
  94. xpander_sdk-2.0.219/src/xpander_sdk/utils/env.py +44 -0
  95. xpander_sdk-2.0.219/src/xpander_sdk/utils/event_loop.py +67 -0
  96. xpander_sdk-2.0.219/src/xpander_sdk/utils/generic.py +5 -0
  97. xpander_sdk-2.0.219/src/xpander_sdk/utils/tools.py +32 -0
  98. xpander_sdk-2.0.219/src/xpander_sdk.egg-info/PKG-INFO +622 -0
  99. xpander_sdk-2.0.219/src/xpander_sdk.egg-info/SOURCES.txt +111 -0
  100. xpander_sdk-2.0.219/src/xpander_sdk.egg-info/requires.txt +27 -0
  101. xpander_sdk-2.0.219/tests/test_agents_module.py +92 -0
  102. xpander_sdk-2.0.219/tests/test_api_client.py +34 -0
  103. xpander_sdk-2.0.219/tests/test_backend_module.py +213 -0
  104. xpander_sdk-2.0.219/tests/test_boot_shutdown_handlers.py +489 -0
  105. xpander_sdk-2.0.219/tests/test_configuration.py +47 -0
  106. xpander_sdk-2.0.219/tests/test_final_validation.py +74 -0
  107. xpander_sdk-2.0.219/tests/test_knowledge_bases_module.py +118 -0
  108. xpander_sdk-2.0.219/tests/test_tasks_module.py +277 -0
  109. xpander_sdk-2.0.219/tests/test_tool_schema_enhancements.py +105 -0
  110. xpander_sdk-2.0.219/tests/test_tools_repository.py +238 -0
  111. xpander_sdk-1.59.0/MANIFEST.in +0 -1
  112. xpander_sdk-1.59.0/PKG-INFO +0 -368
  113. xpander_sdk-1.59.0/README.md +0 -342
  114. xpander_sdk-1.59.0/pyproject.toml +0 -9
  115. xpander_sdk-1.59.0/setup.py +0 -63
  116. xpander_sdk-1.59.0/src/xpander_sdk/__init__.py +0 -7803
  117. xpander_sdk-1.59.0/src/xpander_sdk/_jsii/__init__.py +0 -39
  118. xpander_sdk-1.59.0/src/xpander_sdk/_jsii/xpander-sdk@1.59.0.jsii.tgz +0 -0
  119. xpander_sdk-1.59.0/src/xpander_sdk/py.typed +0 -1
  120. xpander_sdk-1.59.0/src/xpander_sdk.egg-info/PKG-INFO +0 -368
  121. xpander_sdk-1.59.0/src/xpander_sdk.egg-info/SOURCES.txt +0 -14
  122. xpander_sdk-1.59.0/src/xpander_sdk.egg-info/requires.txt +0 -3
  123. {xpander_sdk-1.59.0 → xpander_sdk-2.0.219}/setup.cfg +0 -0
  124. {xpander_sdk-1.59.0 → xpander_sdk-2.0.219}/src/xpander_sdk.egg-info/dependency_links.txt +0 -0
  125. {xpander_sdk-1.59.0 → xpander_sdk-2.0.219}/src/xpander_sdk.egg-info/top_level.txt +0 -0
@@ -1,4 +1,3 @@
1
-
2
1
  Apache License
3
2
  Version 2.0, January 2004
4
3
  http://www.apache.org/licenses/
@@ -0,0 +1,622 @@
1
+ Metadata-Version: 2.4
2
+ Name: xpander-sdk
3
+ Version: 2.0.219
4
+ Summary: xpander.ai Backend-as-a-service for AI Agents - SDK
5
+ Home-page: https://www.xpander.ai
6
+ Author: xpanderAI
7
+ Author-email: dev@xpander.ai
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: python-dotenv>=1.2.1
15
+ Requires-Dist: packaging>=25.0
16
+ Requires-Dist: pydantic>=2.12.5
17
+ Requires-Dist: loguru>=0.7.3
18
+ Requires-Dist: httpx>=0.28.1
19
+ Requires-Dist: httpx_sse>=0.4.3
20
+ Requires-Dist: nest-asyncio>=1.6.0
21
+ Requires-Dist: strands-agents>=1.20.0
22
+ Requires-Dist: openai-agents>=0.6.4
23
+ Requires-Dist: python-toon>=0.1.3
24
+ Provides-Extra: agno
25
+ Requires-Dist: agno==2.3.26; extra == "agno"
26
+ Requires-Dist: sqlalchemy; extra == "agno"
27
+ Requires-Dist: psycopg[binary,pool]; extra == "agno"
28
+ Requires-Dist: greenlet; extra == "agno"
29
+ Provides-Extra: dev
30
+ Requires-Dist: black; extra == "dev"
31
+ Requires-Dist: pre-commit; extra == "dev"
32
+ Requires-Dist: pytest; extra == "dev"
33
+ Requires-Dist: anthropic; extra == "dev"
34
+ Requires-Dist: mcp; extra == "dev"
35
+ Requires-Dist: openai; extra == "dev"
36
+ Requires-Dist: fireworks-ai; extra == "dev"
37
+ Requires-Dist: aioboto3; extra == "dev"
38
+ Requires-Dist: google-genai; extra == "dev"
39
+ Dynamic: author
40
+ Dynamic: author-email
41
+ Dynamic: classifier
42
+ Dynamic: description
43
+ Dynamic: description-content-type
44
+ Dynamic: home-page
45
+ Dynamic: license-file
46
+ Dynamic: provides-extra
47
+ Dynamic: requires-dist
48
+ Dynamic: requires-python
49
+ Dynamic: summary
50
+
51
+ # xpander.ai SDK
52
+
53
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Documentation](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://docs.xpander.ai) [![PyPI Version](https://img.shields.io/pypi/v/xpander-sdk?label=PyPI)](https://pypi.org/project/xpander-sdk/) [![Downloads](https://pepy.tech/badge/xpander-sdk)](https://pepy.tech/project/xpander-sdk)
54
+
55
+ The official Python SDK for xpander.ai - a powerful Backend-as-a-Service (BaaS) platform for building, deploying, and managing AI agents at scale.
56
+
57
+ ## 🚀 Overview
58
+
59
+ xpander.ai SDK provides comprehensive tools for:
60
+
61
+ - **Agent Management**: Create, configure, and manage AI agents
62
+ - **Task Execution**: Handle complex task workflows and execution
63
+ - **Tools Repository**: Integrate external tools and services
64
+ - **Knowledge Bases**: Manage and search knowledge repositories
65
+ - **Event Handling**: Event-driven programming with decorators
66
+ - **Real-time Monitoring**: Track agent performance and execution
67
+
68
+ ## 📦 Installation
69
+
70
+ ```bash
71
+ pip install xpander-sdk
72
+ ```
73
+
74
+ ### With Optional Dependencies
75
+
76
+ ```bash
77
+ # For Agno framework support (2.0+)
78
+ pip install xpander-sdk[agno]
79
+
80
+ # For development
81
+ pip install xpander-sdk[dev]
82
+ ```
83
+
84
+ ## 🔧 Quick Start
85
+
86
+ ### 1. Configuration
87
+
88
+ ```python
89
+ from xpander_sdk import Configuration
90
+
91
+ # Using environment variables (recommended)
92
+ config = Configuration()
93
+
94
+ # Or explicit configuration
95
+ config = Configuration(
96
+ api_key="your-api-key",
97
+ organization_id="your-org-id",
98
+ base_url="https://inbound.xpander.ai"
99
+ )
100
+ ```
101
+
102
+ ### 2. Basic Agent Operations
103
+
104
+ ```python
105
+ from xpander_sdk import Agents, Agent, Tasks, AgentDeploymentType
106
+
107
+ # Initialize agents module
108
+ agents = Agents(configuration=config)
109
+
110
+ # List all agents
111
+ agent_list = await agents.alist()
112
+
113
+ # Load existing agent
114
+ agent = await agents.aget("agent-id")
115
+
116
+ # Create and execute a task
117
+ task = await agent.acreate_task(
118
+ prompt="Help me analyze this data",
119
+ file_urls=["https://example.com/data.csv"]
120
+ )
121
+ ```
122
+
123
+ ### 3. Task Management
124
+
125
+ ```python
126
+ from xpander_sdk import Tasks, Task
127
+
128
+ # Initialize tasks module
129
+ tasks = Tasks(configuration=config)
130
+
131
+ # Load and manage tasks
132
+ task = await tasks.aget("task-id")
133
+ await task.aset_status(AgentExecutionStatus.Running)
134
+ await task.asave()
135
+
136
+ # Retrieve task activity log
137
+ activity_log = await task.aget_activity_log()
138
+ for message in activity_log.messages:
139
+ print(f"{message.role}: {message.content.text}")
140
+ ```
141
+
142
+ ### 4. Tools Integration
143
+
144
+ ```python
145
+ from xpander_sdk import register_tool, ToolsRepository
146
+
147
+ # Register a local tool
148
+ @register_tool
149
+ def check_weather(location: str) -> str:
150
+ """Check weather for a given location."""
151
+ return f"Weather in {location}: Sunny, 25°C"
152
+
153
+ # Register a tool with graph synchronization
154
+ @register_tool(add_to_graph=True)
155
+ async def analyze_data(data: list, analysis_type: str) -> dict:
156
+ """Analyze data from multiple sources."""
157
+ return {
158
+ "analysis_type": analysis_type,
159
+ "data_points": len(data),
160
+ "status": "completed"
161
+ }
162
+
163
+ # Use tools repository
164
+ tools = ToolsRepository(configuration=config)
165
+ weather_tool = tools.get_tool_by_id("check_weather")
166
+ result = await weather_tool.ainvoke(
167
+ agent_id="agent-id",
168
+ payload={"location": "New York"}
169
+ )
170
+ ```
171
+
172
+ ### 5. Knowledge Base Operations
173
+
174
+ ```python
175
+ from xpander_sdk import KnowledgeBases, KnowledgeBase
176
+
177
+ # Initialize knowledge bases
178
+ kb_module = KnowledgeBases(configuration=config)
179
+
180
+ # Create knowledge base
181
+ kb = await kb_module.acreate(
182
+ name="Company Docs",
183
+ description="Internal documentation"
184
+ )
185
+
186
+ # Add documents
187
+ documents = await kb.aadd_documents([
188
+ "https://example.com/doc1.pdf",
189
+ "https://example.com/doc2.txt"
190
+ ])
191
+
192
+ # Search knowledge base
193
+ results = await kb.asearch(
194
+ search_query="product pricing",
195
+ top_k=5
196
+ )
197
+ ```
198
+
199
+ ### 6. Event-Driven Programming
200
+
201
+ ```python
202
+ from xpander_sdk import on_task, Events
203
+
204
+ # Basic task handler
205
+ @on_task
206
+ async def handle_task(task):
207
+ print(f"Processing task: {task.id}")
208
+ # Task processing logic here
209
+ task.result = "Task processed successfully"
210
+ return task
211
+
212
+ # Task handler with configuration
213
+ @on_task(configuration=config)
214
+ def sync_task_handler(task):
215
+ print(f"Handling task synchronously: {task.id}")
216
+ task.result = "Sync processing complete"
217
+ return task
218
+
219
+ ```
220
+
221
+ ## 📚 Core Modules
222
+
223
+ | Module | Description | Documentation |
224
+ | ------------------- | ----------------------------------------- | ---------------------------------------------------------------------------------------- |
225
+ | **Agents** | Agent creation, management, and execution | [Agents Guide](https://github.com/xpander-ai/xpander-sdk/blob/main/docs/AGENTS.md) |
226
+ | **Tasks** | Task lifecycle and execution management | [Tasks Guide](https://github.com/xpander-ai/xpander-sdk/blob/main/docs/TASKS.md) |
227
+ | **ToolsRepository** | External tools and integrations | [Tools Guide](https://github.com/xpander-ai/xpander-sdk/blob/main/docs/TOOLS.md) |
228
+ | **KnowledgeBases** | Knowledge management and search | [Knowledge Guide](https://github.com/xpander-ai/xpander-sdk/blob/main/docs/KNOWLEDGE.md) |
229
+ | **Events** | Event-driven programming | [Events Guide](https://github.com/xpander-ai/xpander-sdk/blob/main/docs/EVENTS.md) |
230
+ | **Backend** | Agent runtime arguments for frameworks | [Backend Guide](https://github.com/xpander-ai/xpander-sdk/blob/main/docs/BACKEND.md) |
231
+
232
+ ## 🔄 Async/Sync Support
233
+
234
+ The SDK provides both asynchronous and synchronous interfaces:
235
+
236
+ ```python
237
+ # Asynchronous (recommended for production)
238
+ agent = await Agent.aload("agent-id")
239
+ task = await agent.acreate_task(prompt="input data")
240
+
241
+ # Synchronous (convenient for scripts)
242
+ agent = Agent.load("agent-id")
243
+ task = agent.create_task(prompt="input data")
244
+ ```
245
+
246
+ ## 📖 Advanced Examples
247
+
248
+ ### Multi-Agent Orchestration
249
+
250
+ ```python
251
+ # Load multiple specialized agents
252
+ agents_list = await agents.alist()
253
+ data_agent = await agents.aget("data-agent-id")
254
+ writer_agent = await agents.aget("writer-agent-id")
255
+
256
+ # Chain agent executions
257
+ analysis_task = await data_agent.acreate_task(prompt="Analyze sales data")
258
+ report_task = await writer_agent.acreate_task(
259
+ prompt=f"Write a report based on: {analysis_task.result}"
260
+ )
261
+ ```
262
+
263
+ ### Tool Integration with MCP Servers
264
+
265
+ ```python
266
+ from xpander_sdk import MCPServerDetails, MCPServerType
267
+
268
+ # Configure MCP server
269
+ mcp_server = MCPServerDetails(
270
+ name="data-server",
271
+ type=MCPServerType.STDIO,
272
+ command="python",
273
+ args=["-m", "mcp_server"],
274
+ env={"API_KEY": "your-key"}
275
+ )
276
+
277
+ # MCP servers are configured at the platform level
278
+ # and tools become available through ToolsRepository
279
+ ```
280
+
281
+ ### Streaming Task Execution
282
+
283
+ ```python
284
+ # Create a task with event streaming enabled
285
+ task = await agent.acreate_task(
286
+ prompt="complex analysis task",
287
+ events_streaming=True
288
+ )
289
+
290
+ # Stream events from the task
291
+ async for event in task.aevents():
292
+ print(f"Event Type: {event.type}")
293
+ print(f"Event Data: {event.data}")
294
+ ```
295
+
296
+ ### Authentication Events Callback
297
+
298
+ Handle authentication events in real-time. This callback is triggered only for authentication flows (e.g., MCP OAuth requiring user login).
299
+
300
+ **You can use both approaches simultaneously** - decorated handlers will always be invoked, and you can also pass an explicit callback for additional handling.
301
+
302
+ You can provide the callback in two ways:
303
+
304
+ #### Option 1: Direct Function
305
+
306
+ ```python
307
+ from xpander_sdk import Backend
308
+ from xpander_sdk.modules.agents.sub_modules.agent import Agent
309
+ from xpander_sdk.modules.tasks.sub_modules.task import Task, TaskUpdateEvent
310
+ from agno.agent import Agent as AgnoAgent
311
+
312
+ # Define event callback (async or sync)
313
+ async def my_event_callback(agent: Agent, task: Task, event: TaskUpdateEvent):
314
+ """Called for authentication events only"""
315
+ # event.type will always be "auth_event"
316
+ print(f"Authentication required: {event.data}")
317
+ # Display login URL or handle OAuth flow
318
+
319
+ # Get args with callback
320
+ backend = Backend(configuration=config)
321
+ args = await backend.aget_args(
322
+ agent_id="agent-123",
323
+ task=my_task,
324
+ auth_events_callback=my_event_callback
325
+ )
326
+ ```
327
+
328
+ #### Option 2: Decorator (Auto-registered)
329
+
330
+ ```python
331
+ from xpander_sdk import Backend, on_auth_event
332
+ from xpander_sdk.modules.agents.sub_modules.agent import Agent
333
+ from xpander_sdk.modules.tasks.sub_modules.task import Task, TaskUpdateEvent
334
+ from agno.agent import Agent as AgnoAgent
335
+
336
+ # Use decorator - auto-registers globally
337
+ @on_auth_event
338
+ async def handle_auth(agent: Agent, task: Task, event: TaskUpdateEvent):
339
+ # event.type will always be "auth_event"
340
+ print(f"Authentication required for {agent.name}")
341
+ print(f"Auth data: {event.data}")
342
+
343
+ # Decorated handler is automatically invoked - no need to pass it
344
+ backend = Backend(configuration=config)
345
+ args = await backend.aget_args(
346
+ agent_id="agent-123",
347
+ task=my_task
348
+ )
349
+ ```
350
+
351
+ #### Option 3: Combine Both
352
+
353
+ ```python
354
+ from xpander_sdk import Backend, on_auth_event
355
+
356
+ # Global handler for all auth events
357
+ @on_auth_event
358
+ async def log_auth(agent, task, event):
359
+ print(f"[GLOBAL] Auth event for {agent.name}")
360
+
361
+ # Additional one-time handler
362
+ async def custom_handler(agent, task, event):
363
+ print(f"[CUSTOM] Specific handling for this call")
364
+
365
+ # Both handlers will be invoked
366
+ args = await backend.aget_args(
367
+ agent_id="agent-123",
368
+ auth_events_callback=custom_handler # Optional additional callback
369
+ )
370
+
371
+ # Use with Agno
372
+ agno_agent = AgnoAgent(**args)
373
+ result = await agno_agent.arun(
374
+ input="Process this data",
375
+ stream=True
376
+ )
377
+ ```
378
+
379
+ ### Task Activity Monitoring
380
+
381
+ ```python
382
+ from xpander_sdk import Task
383
+ from xpander_sdk.models.activity import (
384
+ AgentActivityThreadMessage,
385
+ AgentActivityThreadToolCall,
386
+ AgentActivityThreadReasoning
387
+ )
388
+
389
+ # Load a completed task
390
+ task = await Task.aload("task-id")
391
+
392
+ # Get detailed activity log
393
+ activity_log = await task.aget_activity_log()
394
+
395
+ # Analyze messages between user and agent
396
+ for message in activity_log.messages:
397
+ if isinstance(message, AgentActivityThreadMessage):
398
+ print(f"{message.role}: {message.content.text}")
399
+ elif isinstance(message, AgentActivityThreadToolCall):
400
+ # Tool call
401
+ print(f"Tool: {message.tool_name}")
402
+ print(f"Payload: {message.payload}")
403
+ print(f"Result: {message.result}")
404
+ elif isinstance(message, AgentActivityThreadReasoning):
405
+ # Reasoning step
406
+ print(f"Reasoning ({message.type}): {message.thought}")
407
+
408
+ # Synchronous version
409
+ task = Task.load("task-id")
410
+ activity_log = task.get_activity_log()
411
+ ```
412
+
413
+ ### Local Task Testing
414
+
415
+ ```python
416
+ from xpander_sdk.modules.tasks.models.task import LocalTaskTest, AgentExecutionInput
417
+ from xpander_sdk.models.shared import OutputFormat
418
+ from xpander_sdk import on_task
419
+
420
+ # Define a local test task
421
+ local_task = LocalTaskTest(
422
+ input=AgentExecutionInput(text="What can you do?"),
423
+ output_format=OutputFormat.Json,
424
+ output_schema={"capabilities": "list of capabilities"}
425
+ )
426
+
427
+ # Test with local task
428
+ @on_task(test_task=local_task)
429
+ async def handle_test_task(task):
430
+ task.result = {
431
+ "capabilities": [
432
+ "Data analysis",
433
+ "Text processing",
434
+ "API integration"
435
+ ]
436
+ }
437
+ return task
438
+ ```
439
+
440
+ ## 🧪 Testing
441
+
442
+ ```bash
443
+ # Run tests
444
+ pytest tests/
445
+
446
+ # Run with coverage
447
+ pytest tests/ --cov=xpander_sdk
448
+
449
+ # Run specific test
450
+ pytest tests/test_agents.py::test_agent_creation
451
+ ```
452
+
453
+ ## 🏗️ Architecture
454
+
455
+ ```plaintext
456
+ xpander_sdk/
457
+ ├── core/ # Core API client and base classes
458
+ ├── models/ # Pydantic models and configurations
459
+ ├── modules/
460
+ │ ├── agents/ # Agent management
461
+ │ ├── tasks/ # Task execution
462
+ │ ├── tools_repository/ # Tools and integrations
463
+ │ ├── knowledge_bases/ # Knowledge management
464
+ │ ├── events/ # Event handling
465
+ │ └── backend/ # Agent runtime arguments for frameworks
466
+ └── utils/ # Utility functions
467
+ ```
468
+
469
+ ## 🔒 Authentication
470
+
471
+ The SDK supports multiple authentication methods:
472
+
473
+ ### Environment Variables (Recommended)
474
+
475
+ ```bash
476
+ export XPANDER_API_KEY="your-api-key"
477
+ export XPANDER_ORGANIZATION_ID="your-org-id"
478
+ export XPANDER_BASE_URL="https://inbound.xpander.ai" # Optional
479
+ export XPANDER_AGENT_ID="your-agent-id" # Optional for Backend module
480
+ ```
481
+
482
+ ### Configuration Object
483
+
484
+ ```python
485
+ config = Configuration(
486
+ api_key="your-api-key",
487
+ organization_id="your-org-id"
488
+ )
489
+ ```
490
+
491
+ ### From File
492
+
493
+ ```python
494
+ # .env file
495
+ XPANDER_API_KEY=your-api-key
496
+ XPANDER_ORGANIZATION_ID=your-org-id
497
+
498
+ # Python code
499
+ from dotenv import load_dotenv
500
+ load_dotenv()
501
+ config = Configuration()
502
+ ```
503
+
504
+ ## 🏢 Self-Hosted Deployment
505
+
506
+ If you're using a self-hosted xpander.ai deployment, configure the SDK to point to your Agent Controller endpoint.
507
+
508
+ **Important**: Use the **Agent Controller API key** generated during Helm installation, not your xpander.ai cloud API key.
509
+
510
+ ### Configuration
511
+
512
+ ```bash
513
+ # Set environment variables
514
+ export XPANDER_API_KEY="your-agent-controller-api-key" # From Helm installation
515
+ export XPANDER_ORGANIZATION_ID="your-org-id"
516
+ export XPANDER_BASE_URL="https://agent-controller.my-company.com"
517
+ ```
518
+
519
+ Or configure explicitly:
520
+
521
+ ```python
522
+ from xpander_sdk import Configuration
523
+
524
+ config = Configuration(
525
+ api_key="your-agent-controller-api-key", # From Helm installation
526
+ organization_id="your-org-id",
527
+ base_url="https://agent-controller.my-company.com"
528
+ )
529
+ ```
530
+
531
+ ### Using with Agno Framework
532
+
533
+ ```python
534
+ from xpander_sdk import Backend, Configuration
535
+ from agno.agent import Agent
536
+
537
+ # Configure for self-hosted
538
+ config = Configuration(
539
+ api_key="your-agent-controller-api-key", # From Helm installation
540
+ organization_id="your-org-id",
541
+ base_url="https://agent-controller.my-company.com"
542
+ )
543
+
544
+ # Initialize Backend with self-hosted config
545
+ backend = Backend(configuration=config)
546
+
547
+ # Create agent - it will use your self-hosted infrastructure
548
+ agno_agent = Agent(**backend.get_args(agent_id="agent-123"))
549
+
550
+ # Run agent
551
+ result = await agno_agent.arun(
552
+ input="What can you help me with?",
553
+ stream=True
554
+ )
555
+ ```
556
+
557
+ ### Complete Self-Hosted Example
558
+
559
+ ```python
560
+ import asyncio
561
+ from xpander_sdk import Configuration, Agent
562
+
563
+ async def main():
564
+ # Configure for self-hosted deployment
565
+ config = Configuration(
566
+ api_key="your-agent-controller-api-key", # From Helm installation
567
+ organization_id="your-org-id",
568
+ base_url="https://agent-controller.my-company.com"
569
+ )
570
+
571
+ # Load agent from self-hosted deployment
572
+ agent = await Agent.aload("agent-123", configuration=config)
573
+ print(f"Agent: {agent.name}")
574
+
575
+ # Create and execute task
576
+ task = await agent.acreate_task(
577
+ prompt="Analyze Q4 sales data",
578
+ file_urls=["https://example.com/sales-q4.csv"]
579
+ )
580
+ print(f"Task created: {task.id}")
581
+ print(f"Status: {task.status}")
582
+
583
+ if __name__ == "__main__":
584
+ asyncio.run(main())
585
+ ```
586
+
587
+ **Important**: Make sure your `base_url` points to the Agent Controller endpoint (e.g., `https://agent-controller.{your-domain}`), not the root domain.
588
+
589
+ 📖 **Full Guide**: [Self-Hosted Configuration Documentation](https://docs.xpander.ai/api-reference/configuration/self-hosted)
590
+
591
+ ## 🔄 Error Handling
592
+
593
+ ```python
594
+ from xpander_sdk.exceptions import ModuleException
595
+
596
+ try:
597
+ agent = await Agent.aload("invalid-agent-id")
598
+ except ModuleException as e:
599
+ print(f"Error {e.status_code}: {e.description}")
600
+ ```
601
+
602
+ ## 🤝 Contributing
603
+
604
+ 1. Fork the repository
605
+ 2. Create a feature branch (`git checkout -b feature/{base_branch}/amazing-feature`)
606
+ 3. Commit your changes (`git commit -m 'feat/chore/fix: Add amazing feature'`)
607
+ 4. Push to the branch (`git push origin feature/{base_branch}/amazing-feature`)
608
+ 5. Open a Pull Request
609
+
610
+ ## 📄 License
611
+
612
+ This project is licensed under the MIT License - see the LICENSE file for details.
613
+
614
+ ## 🆘 Support
615
+
616
+ - **Documentation**: [https://docs.xpander.ai](https://docs.xpander.ai)
617
+ - **Issues**: [GitHub Issues](https://github.com/xpander-ai/xpander-sdk/issues)
618
+ - **Email**: support@xpander.ai
619
+
620
+ ---
621
+
622
+ Built with ❤️ by the xpander.ai team