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.
- xpander_sdk/__init__.py +76 -7793
- xpander_sdk/consts/__init__.py +0 -0
- xpander_sdk/consts/api_routes.py +63 -0
- xpander_sdk/core/__init__.py +0 -0
- xpander_sdk/core/module_base.py +164 -0
- xpander_sdk/core/state.py +10 -0
- xpander_sdk/core/xpander_api_client.py +119 -0
- xpander_sdk/exceptions/__init__.py +0 -0
- xpander_sdk/exceptions/module_exception.py +45 -0
- xpander_sdk/models/__init__.py +0 -0
- xpander_sdk/models/activity.py +65 -0
- xpander_sdk/models/configuration.py +92 -0
- xpander_sdk/models/events.py +70 -0
- xpander_sdk/models/frameworks.py +64 -0
- xpander_sdk/models/shared.py +102 -0
- xpander_sdk/models/user.py +21 -0
- xpander_sdk/modules/__init__.py +0 -0
- xpander_sdk/modules/agents/__init__.py +0 -0
- xpander_sdk/modules/agents/agents_module.py +164 -0
- xpander_sdk/modules/agents/models/__init__.py +0 -0
- xpander_sdk/modules/agents/models/agent.py +477 -0
- xpander_sdk/modules/agents/models/agent_list.py +107 -0
- xpander_sdk/modules/agents/models/knowledge_bases.py +33 -0
- xpander_sdk/modules/agents/sub_modules/__init__.py +0 -0
- xpander_sdk/modules/agents/sub_modules/agent.py +953 -0
- xpander_sdk/modules/agents/utils/__init__.py +0 -0
- xpander_sdk/modules/agents/utils/generic.py +2 -0
- xpander_sdk/modules/backend/__init__.py +0 -0
- xpander_sdk/modules/backend/backend_module.py +425 -0
- xpander_sdk/modules/backend/frameworks/__init__.py +0 -0
- xpander_sdk/modules/backend/frameworks/agno.py +627 -0
- xpander_sdk/modules/backend/frameworks/dispatch.py +36 -0
- xpander_sdk/modules/backend/utils/__init__.py +0 -0
- xpander_sdk/modules/backend/utils/mcp_oauth.py +95 -0
- xpander_sdk/modules/events/__init__.py +0 -0
- xpander_sdk/modules/events/decorators/__init__.py +0 -0
- xpander_sdk/modules/events/decorators/on_boot.py +94 -0
- xpander_sdk/modules/events/decorators/on_shutdown.py +94 -0
- xpander_sdk/modules/events/decorators/on_task.py +203 -0
- xpander_sdk/modules/events/events_module.py +629 -0
- xpander_sdk/modules/events/models/__init__.py +0 -0
- xpander_sdk/modules/events/models/deployments.py +25 -0
- xpander_sdk/modules/events/models/events.py +57 -0
- xpander_sdk/modules/events/utils/__init__.py +0 -0
- xpander_sdk/modules/events/utils/generic.py +56 -0
- xpander_sdk/modules/events/utils/git_init.py +32 -0
- xpander_sdk/modules/knowledge_bases/__init__.py +0 -0
- xpander_sdk/modules/knowledge_bases/knowledge_bases_module.py +217 -0
- xpander_sdk/modules/knowledge_bases/models/__init__.py +0 -0
- xpander_sdk/modules/knowledge_bases/models/knowledge_bases.py +11 -0
- xpander_sdk/modules/knowledge_bases/sub_modules/__init__.py +0 -0
- xpander_sdk/modules/knowledge_bases/sub_modules/knowledge_base.py +107 -0
- xpander_sdk/modules/knowledge_bases/sub_modules/knowledge_base_document_item.py +40 -0
- xpander_sdk/modules/knowledge_bases/utils/__init__.py +0 -0
- xpander_sdk/modules/tasks/__init__.py +0 -0
- xpander_sdk/modules/tasks/models/__init__.py +0 -0
- xpander_sdk/modules/tasks/models/task.py +153 -0
- xpander_sdk/modules/tasks/models/tasks_list.py +107 -0
- xpander_sdk/modules/tasks/sub_modules/__init__.py +0 -0
- xpander_sdk/modules/tasks/sub_modules/task.py +887 -0
- xpander_sdk/modules/tasks/tasks_module.py +492 -0
- xpander_sdk/modules/tasks/utils/__init__.py +0 -0
- xpander_sdk/modules/tasks/utils/files.py +114 -0
- xpander_sdk/modules/tools_repository/__init__.py +0 -0
- xpander_sdk/modules/tools_repository/decorators/__init__.py +0 -0
- xpander_sdk/modules/tools_repository/decorators/register_tool.py +108 -0
- xpander_sdk/modules/tools_repository/models/__init__.py +0 -0
- xpander_sdk/modules/tools_repository/models/mcp.py +68 -0
- xpander_sdk/modules/tools_repository/models/tool_invocation_result.py +14 -0
- xpander_sdk/modules/tools_repository/sub_modules/__init__.py +0 -0
- xpander_sdk/modules/tools_repository/sub_modules/tool.py +578 -0
- xpander_sdk/modules/tools_repository/tools_repository_module.py +259 -0
- xpander_sdk/modules/tools_repository/utils/__init__.py +0 -0
- xpander_sdk/modules/tools_repository/utils/generic.py +57 -0
- xpander_sdk/modules/tools_repository/utils/local_tools.py +52 -0
- xpander_sdk/modules/tools_repository/utils/schemas.py +308 -0
- xpander_sdk/utils/__init__.py +0 -0
- xpander_sdk/utils/env.py +44 -0
- xpander_sdk/utils/event_loop.py +67 -0
- xpander_sdk/utils/tools.py +32 -0
- xpander_sdk-2.0.155.dist-info/METADATA +538 -0
- xpander_sdk-2.0.155.dist-info/RECORD +85 -0
- {xpander_sdk-1.60.4.dist-info → xpander_sdk-2.0.155.dist-info}/WHEEL +1 -1
- {xpander_sdk-1.60.4.dist-info → xpander_sdk-2.0.155.dist-info/licenses}/LICENSE +0 -1
- xpander_sdk/_jsii/__init__.py +0 -39
- xpander_sdk/_jsii/xpander-sdk@1.60.4.jsii.tgz +0 -0
- xpander_sdk/py.typed +0 -1
- xpander_sdk-1.60.4.dist-info/METADATA +0 -368
- xpander_sdk-1.60.4.dist-info/RECORD +0 -9
- {xpander_sdk-1.60.4.dist-info → xpander_sdk-2.0.155.dist-info}/top_level.txt +0 -0
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from os import getenv
|
|
3
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from xpander_sdk.core.module_base import ModuleBase
|
|
6
|
+
from xpander_sdk.models.configuration import Configuration
|
|
7
|
+
from xpander_sdk.models.shared import OutputFormat, Tokens
|
|
8
|
+
from xpander_sdk.models.user import User
|
|
9
|
+
from xpander_sdk.modules.agents.agents_module import Agents
|
|
10
|
+
from xpander_sdk.modules.agents.sub_modules.agent import Agent
|
|
11
|
+
from xpander_sdk.modules.backend.frameworks.dispatch import dispatch_get_args
|
|
12
|
+
from xpander_sdk.modules.tasks.sub_modules.task import Task
|
|
13
|
+
from xpander_sdk.modules.tasks.tasks_module import Tasks
|
|
14
|
+
from xpander_sdk.utils.event_loop import run_sync
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Backend(ModuleBase):
|
|
18
|
+
"""
|
|
19
|
+
Backend module for agent runtime management and task execution.
|
|
20
|
+
|
|
21
|
+
This module provides comprehensive functionality for interacting with agents
|
|
22
|
+
in the xpander.ai platform, including:
|
|
23
|
+
- Direct agent invocation with task creation
|
|
24
|
+
- Runtime argument resolution for agent execution
|
|
25
|
+
- External task result reporting
|
|
26
|
+
- Support for multiple execution frameworks
|
|
27
|
+
|
|
28
|
+
The module follows the singleton pattern inherited from ModuleBase,
|
|
29
|
+
ensuring consistent configuration across all backend operations.
|
|
30
|
+
Provides both asynchronous and synchronous APIs for flexibility.
|
|
31
|
+
|
|
32
|
+
Example:
|
|
33
|
+
>>> backend = Backend()
|
|
34
|
+
>>> # Direct agent invocation
|
|
35
|
+
>>> task = backend.invoke_agent(agent_id="agent-123", prompt="Hello world")
|
|
36
|
+
>>> # Runtime argument resolution
|
|
37
|
+
>>> args = backend.get_args(agent_id="agent-123")
|
|
38
|
+
>>> # External task reporting
|
|
39
|
+
>>> reported_task = backend.report_external_task(agent_id="agent-123", result="Success")
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, configuration: Optional[Configuration] = None):
|
|
43
|
+
"""
|
|
44
|
+
Initialize the Backend module.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
configuration (Optional[Configuration]): Optional SDK configuration.
|
|
48
|
+
"""
|
|
49
|
+
super().__init__(configuration)
|
|
50
|
+
|
|
51
|
+
async def ainvoke_agent(
|
|
52
|
+
self,
|
|
53
|
+
agent_id: Optional[str] = None,
|
|
54
|
+
prompt: Optional[str] = "",
|
|
55
|
+
existing_task_id: Optional[str] = None,
|
|
56
|
+
file_urls: Optional[List[str]] = None,
|
|
57
|
+
user_details: Optional[User] = None,
|
|
58
|
+
agent_version: Optional[str] = None,
|
|
59
|
+
tool_call_payload_extension: Optional[dict] = None,
|
|
60
|
+
source: Optional[str] = "sdk",
|
|
61
|
+
worker_id: Optional[str] = None,
|
|
62
|
+
run_locally: Optional[bool] = False,
|
|
63
|
+
output_format: Optional[OutputFormat] = None,
|
|
64
|
+
output_schema: Optional[Dict] = None,
|
|
65
|
+
events_streaming: Optional[bool] = False,
|
|
66
|
+
additional_context: Optional[str] = None,
|
|
67
|
+
expected_output: Optional[str] = None,
|
|
68
|
+
) -> Task:
|
|
69
|
+
"""
|
|
70
|
+
Asynchronously invoke an agent to create and execute a task.
|
|
71
|
+
|
|
72
|
+
This method directly invokes an agent by creating a new task with the specified
|
|
73
|
+
parameters. It supports comprehensive task configuration including file uploads,
|
|
74
|
+
user context, output formatting, and execution preferences.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
agent_id (Optional[str]): Unique identifier of the agent to invoke.
|
|
78
|
+
If not provided, will attempt to use XPANDER_AGENT_ID environment variable.
|
|
79
|
+
prompt (Optional[str]): The input prompt or message for the agent. Defaults to empty string.
|
|
80
|
+
existing_task_id (Optional[str]): ID of an existing task to continue or reference.
|
|
81
|
+
file_urls (Optional[List[str]]): List of file URLs to provide as context to the agent.
|
|
82
|
+
user_details (Optional[User]): User information and context for personalized responses.
|
|
83
|
+
agent_version (Optional[str]): Specific version of the agent to invoke.
|
|
84
|
+
If not provided, uses the latest version.
|
|
85
|
+
tool_call_payload_extension (Optional[dict]): Additional parameters for tool calls.
|
|
86
|
+
source (Optional[str]): Source identifier for task tracking. Defaults to "sdk".
|
|
87
|
+
worker_id (Optional[str]): Specific worker ID for task execution.
|
|
88
|
+
run_locally (Optional[bool]): Whether to execute the task locally. Defaults to False.
|
|
89
|
+
output_format (Optional[OutputFormat]): Desired output format (e.g., JSON, XML, etc.).
|
|
90
|
+
output_schema (Optional[Dict]): Schema definition for structured output validation.
|
|
91
|
+
events_streaming (Optional[bool]): Enable real-time event streaming. Defaults to False.
|
|
92
|
+
additional_context (Optional[str]): Additional context or instructions for the agent.
|
|
93
|
+
expected_output (Optional[str]): Description of expected output format or content.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
Task: The created and potentially executed task object containing results,
|
|
97
|
+
metadata, and execution status.
|
|
98
|
+
|
|
99
|
+
Raises:
|
|
100
|
+
ValueError: If agent_id is not provided and XPANDER_AGENT_ID environment
|
|
101
|
+
variable is not set.
|
|
102
|
+
ModuleException: If agent invocation fails due to API errors or invalid parameters.
|
|
103
|
+
|
|
104
|
+
Example:
|
|
105
|
+
>>> backend = Backend()
|
|
106
|
+
>>> task = await backend.ainvoke_agent(
|
|
107
|
+
... agent_id="agent-123",
|
|
108
|
+
... prompt="Analyze this data and provide insights",
|
|
109
|
+
... file_urls=["https://example.com/data.csv"],
|
|
110
|
+
... output_format=OutputFormat.JSON
|
|
111
|
+
... )
|
|
112
|
+
>>> print(f"Task completed: {task.result}")
|
|
113
|
+
"""
|
|
114
|
+
if not agent_id:
|
|
115
|
+
agent_id = getenv("XPANDER_AGENT_ID", None)
|
|
116
|
+
|
|
117
|
+
# try to parse prompt if its json and extract task id if sent
|
|
118
|
+
try:
|
|
119
|
+
parsed_prompt = json.loads(prompt)
|
|
120
|
+
if parsed_prompt and "xpander_task_id" in parsed_prompt:
|
|
121
|
+
return await Tasks(configuration=self.configuration).aget(task_id=parsed_prompt["xpander_task_id"])
|
|
122
|
+
except:
|
|
123
|
+
pass
|
|
124
|
+
|
|
125
|
+
return await (await Agents(configuration=self.configuration).aget(agent_id=agent_id)).acreate_task(
|
|
126
|
+
prompt=prompt,
|
|
127
|
+
existing_task_id=existing_task_id,
|
|
128
|
+
file_urls=file_urls,
|
|
129
|
+
user_details=user_details,
|
|
130
|
+
agent_version=agent_version,
|
|
131
|
+
tool_call_payload_extension=tool_call_payload_extension,
|
|
132
|
+
source=source,
|
|
133
|
+
worker_id=worker_id,
|
|
134
|
+
run_locally=run_locally,
|
|
135
|
+
output_format=output_format,
|
|
136
|
+
output_schema=output_schema,
|
|
137
|
+
events_streaming=events_streaming,
|
|
138
|
+
additional_context=additional_context,
|
|
139
|
+
expected_output=expected_output,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def invoke_agent(
|
|
143
|
+
self,
|
|
144
|
+
agent_id: Optional[str] = None,
|
|
145
|
+
prompt: Optional[str] = "",
|
|
146
|
+
existing_task_id: Optional[str] = None,
|
|
147
|
+
file_urls: Optional[List[str]] = None,
|
|
148
|
+
user_details: Optional[User] = None,
|
|
149
|
+
agent_version: Optional[str] = None,
|
|
150
|
+
tool_call_payload_extension: Optional[dict] = None,
|
|
151
|
+
source: Optional[str] = "sdk",
|
|
152
|
+
worker_id: Optional[str] = None,
|
|
153
|
+
run_locally: Optional[bool] = False,
|
|
154
|
+
output_format: Optional[OutputFormat] = None,
|
|
155
|
+
output_schema: Optional[Dict] = None,
|
|
156
|
+
events_streaming: Optional[bool] = False,
|
|
157
|
+
additional_context: Optional[str] = None,
|
|
158
|
+
expected_output: Optional[str] = None,
|
|
159
|
+
) -> Task:
|
|
160
|
+
"""
|
|
161
|
+
Synchronously invoke an agent to create and execute a task.
|
|
162
|
+
|
|
163
|
+
This is the blocking version of `ainvoke_agent()`. It provides a direct,
|
|
164
|
+
synchronous interface for agent invocation when asynchronous execution
|
|
165
|
+
is not required or not available.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
agent_id (Optional[str]): Unique identifier of the agent to invoke.
|
|
169
|
+
If not provided, will attempt to use XPANDER_AGENT_ID environment variable.
|
|
170
|
+
prompt (Optional[str]): The input prompt or message for the agent. Defaults to empty string.
|
|
171
|
+
existing_task_id (Optional[str]): ID of an existing task to continue or reference.
|
|
172
|
+
file_urls (Optional[List[str]]): List of file URLs to provide as context to the agent.
|
|
173
|
+
user_details (Optional[User]): User information and context for personalized responses.
|
|
174
|
+
agent_version (Optional[str]): Specific version of the agent to invoke.
|
|
175
|
+
If not provided, uses the latest version.
|
|
176
|
+
tool_call_payload_extension (Optional[dict]): Additional parameters for tool calls.
|
|
177
|
+
source (Optional[str]): Source identifier for task tracking. Defaults to "sdk".
|
|
178
|
+
worker_id (Optional[str]): Specific worker ID for task execution.
|
|
179
|
+
run_locally (Optional[bool]): Whether to execute the task locally. Defaults to False.
|
|
180
|
+
output_format (Optional[OutputFormat]): Desired output format (e.g., JSON, XML, etc.).
|
|
181
|
+
output_schema (Optional[Dict]): Schema definition for structured output validation.
|
|
182
|
+
events_streaming (Optional[bool]): Enable real-time event streaming. Defaults to False.
|
|
183
|
+
additional_context (Optional[str]): Additional context or instructions for the agent.
|
|
184
|
+
expected_output (Optional[str]): Description of expected output format or content.
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
Task: The created and executed task object containing results,
|
|
188
|
+
metadata, and execution status.
|
|
189
|
+
|
|
190
|
+
Raises:
|
|
191
|
+
ValueError: If agent_id is not provided and XPANDER_AGENT_ID environment
|
|
192
|
+
variable is not set.
|
|
193
|
+
ModuleException: If agent invocation fails due to API errors or invalid parameters.
|
|
194
|
+
|
|
195
|
+
Example:
|
|
196
|
+
>>> backend = Backend()
|
|
197
|
+
>>> task = backend.invoke_agent(
|
|
198
|
+
... agent_id="agent-123",
|
|
199
|
+
... prompt="Generate a summary of recent sales data",
|
|
200
|
+
... file_urls=["https://example.com/sales.xlsx"],
|
|
201
|
+
... output_format=OutputFormat.JSON,
|
|
202
|
+
... additional_context="Focus on Q4 2023 trends"
|
|
203
|
+
... )
|
|
204
|
+
>>> print(f"Task result: {task.result}")
|
|
205
|
+
>>> print(f"Task status: {task.status}")
|
|
206
|
+
"""
|
|
207
|
+
return run_sync(self.ainvoke_agent(
|
|
208
|
+
agent_id=agent_id,
|
|
209
|
+
prompt=prompt,
|
|
210
|
+
existing_task_id=existing_task_id,
|
|
211
|
+
file_urls=file_urls,
|
|
212
|
+
user_details=user_details,
|
|
213
|
+
agent_version=agent_version,
|
|
214
|
+
tool_call_payload_extension=tool_call_payload_extension,
|
|
215
|
+
source=source,
|
|
216
|
+
worker_id=worker_id,
|
|
217
|
+
run_locally=run_locally,
|
|
218
|
+
output_format=output_format,
|
|
219
|
+
output_schema=output_schema,
|
|
220
|
+
events_streaming=events_streaming,
|
|
221
|
+
additional_context=additional_context,
|
|
222
|
+
expected_output=expected_output,
|
|
223
|
+
))
|
|
224
|
+
|
|
225
|
+
async def aget_args(
|
|
226
|
+
self,
|
|
227
|
+
agent_id: Optional[str] = None,
|
|
228
|
+
agent: Optional[Agent] = None,
|
|
229
|
+
agent_version: Optional[int] = None,
|
|
230
|
+
task: Optional[Task] = None,
|
|
231
|
+
override: Optional[Dict[str, Any]] = None,
|
|
232
|
+
tools: Optional[List[Callable]] = None,
|
|
233
|
+
is_async: Optional[bool] = True,
|
|
234
|
+
) -> Dict[str, Any]:
|
|
235
|
+
"""
|
|
236
|
+
Asynchronously resolve runtime arguments for the specified agent.
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
agent_id (Optional[str]): ID of the agent. Required if 'agent' is not provided.
|
|
240
|
+
agent (Optional[Agent]): Preloaded Agent instance. Takes precedence over 'agent_id'.
|
|
241
|
+
agent_version (Optional[int]): Optional version to resolve.
|
|
242
|
+
task (Optional[Task]): Optional Task object providing runtime input/output context.
|
|
243
|
+
override (Optional[Dict[str, Any]]): Optional overrides for final arguments.
|
|
244
|
+
tools (Optional[List[Callable]]): Optional additional tools to be added to the agent arguments.
|
|
245
|
+
is_async (Optional[bool]): Is in Async Context?.
|
|
246
|
+
|
|
247
|
+
Returns:
|
|
248
|
+
Dict[str, Any]: Resolved argument dictionary to use with the agent.
|
|
249
|
+
|
|
250
|
+
Raises:
|
|
251
|
+
ValueError: If neither 'agent' nor 'agent_id' is provided.
|
|
252
|
+
"""
|
|
253
|
+
# Attempt to take agent_id from environment if not provided
|
|
254
|
+
if not agent and not agent_id:
|
|
255
|
+
agent_id = getenv("XPANDER_AGENT_ID", None)
|
|
256
|
+
|
|
257
|
+
if agent:
|
|
258
|
+
xpander_agent = agent
|
|
259
|
+
elif agent_id:
|
|
260
|
+
xpander_agent = await Agents(configuration=self.configuration).aget(
|
|
261
|
+
agent_id=agent_id,
|
|
262
|
+
version=agent_version
|
|
263
|
+
)
|
|
264
|
+
else:
|
|
265
|
+
raise ValueError(
|
|
266
|
+
"Missing agent context: either 'agent' or 'agent_id' must be provided explicitly "
|
|
267
|
+
"or set via the 'XPANDER_AGENT_ID' environment variable."
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
return await dispatch_get_args(agent=xpander_agent, task=task, override=override, tools=tools, is_async=is_async)
|
|
271
|
+
|
|
272
|
+
def get_args(
|
|
273
|
+
self,
|
|
274
|
+
agent_id: Optional[str] = None,
|
|
275
|
+
agent: Optional[Agent] = None,
|
|
276
|
+
agent_version: Optional[int] = None,
|
|
277
|
+
task: Optional[Task] = None,
|
|
278
|
+
override: Optional[Dict[str, Any]] = None,
|
|
279
|
+
tools: Optional[List[Callable]] = None,
|
|
280
|
+
) -> Dict[str, Any]:
|
|
281
|
+
"""
|
|
282
|
+
Synchronously resolve runtime arguments for the specified agent.
|
|
283
|
+
|
|
284
|
+
This is the blocking version of `aget_args()`. It will block the event loop
|
|
285
|
+
until the arguments are resolved.
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
agent_id (Optional[str]): ID of the agent. Required if 'agent' is not provided.
|
|
289
|
+
agent (Optional[Agent]): Preloaded Agent instance. Takes precedence over 'agent_id'.
|
|
290
|
+
agent_version (Optional[int]): Optional version to resolve.
|
|
291
|
+
task (Optional[Task]): Optional Task object providing runtime input/output context.
|
|
292
|
+
override (Optional[Dict[str, Any]]): Optional overrides for final arguments.
|
|
293
|
+
tools (Optional[List[Callable]]): Optional additional tools to be added to the agent arguments.
|
|
294
|
+
|
|
295
|
+
Returns:
|
|
296
|
+
Dict[str, Any]: Resolved argument dictionary to use with the agent.
|
|
297
|
+
|
|
298
|
+
Raises:
|
|
299
|
+
ValueError: If neither 'agent_id' nor 'agent' is provided.
|
|
300
|
+
"""
|
|
301
|
+
return run_sync(
|
|
302
|
+
self.aget_args(
|
|
303
|
+
agent_id=agent_id,
|
|
304
|
+
agent=agent,
|
|
305
|
+
agent_version=agent_version,
|
|
306
|
+
task=task,
|
|
307
|
+
override=override,
|
|
308
|
+
tools=tools,
|
|
309
|
+
is_async=False
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
async def areport_external_task(
|
|
314
|
+
self,
|
|
315
|
+
agent_id: Optional[str] = None,
|
|
316
|
+
agent: Optional[Agent] = None,
|
|
317
|
+
id: Optional[str] = None,
|
|
318
|
+
input: Optional[str] = None,
|
|
319
|
+
llm_response: Optional[Any] = None,
|
|
320
|
+
tokens: Optional[Tokens] = None,
|
|
321
|
+
is_success: Optional[bool] = True,
|
|
322
|
+
result: Optional[str] = None,
|
|
323
|
+
duration: Optional[float] = 0,
|
|
324
|
+
used_tools: Optional[list] = None,
|
|
325
|
+
configuration: Optional[Configuration] = None,
|
|
326
|
+
) -> Task:
|
|
327
|
+
"""
|
|
328
|
+
Asynchronously report the result of an external task.
|
|
329
|
+
|
|
330
|
+
This method will use a provided agent or agent_id. If agent is not provided or not persisted,
|
|
331
|
+
it will load the agent using the agent_id (or from the environment variable).
|
|
332
|
+
|
|
333
|
+
Args:
|
|
334
|
+
agent_id (Optional[str]): The agent's ID.
|
|
335
|
+
agent (Optional[Agent]): Optional preloaded Agent instance (takes precedence).
|
|
336
|
+
id (Optional[str]): Task identifier.
|
|
337
|
+
input (Optional[str]): The input parameters or message for the task.
|
|
338
|
+
llm_response (Optional[Any]): The LLM's response object.
|
|
339
|
+
tokens (Optional[Tokens]): The tokens used.
|
|
340
|
+
is_success (Optional[bool]): Task success status.
|
|
341
|
+
result (Optional[str]): Final result string.
|
|
342
|
+
duration (Optional[float]): Execution duration (seconds).
|
|
343
|
+
used_tools (Optional[list]): List of tool names used.
|
|
344
|
+
configuration (Optional[Configuration]): Optional configuration override.
|
|
345
|
+
|
|
346
|
+
Returns:
|
|
347
|
+
Task: The reported Task object from the backend.
|
|
348
|
+
|
|
349
|
+
Raises:
|
|
350
|
+
ValueError: If neither agent nor agent_id is provided.
|
|
351
|
+
"""
|
|
352
|
+
used_tools = used_tools or []
|
|
353
|
+
configuration = configuration or self.configuration
|
|
354
|
+
|
|
355
|
+
agent_id = agent.id if agent else agent_id
|
|
356
|
+
agent_id = agent_id or getenv("XPANDER_AGENT_ID")
|
|
357
|
+
|
|
358
|
+
# Call Task.areport_external_task with all arguments.
|
|
359
|
+
return await Task.areport_external_task(
|
|
360
|
+
configuration=configuration,
|
|
361
|
+
agent_id=agent_id,
|
|
362
|
+
id=id,
|
|
363
|
+
input=input,
|
|
364
|
+
llm_response=llm_response,
|
|
365
|
+
tokens=tokens,
|
|
366
|
+
is_success=is_success,
|
|
367
|
+
result=result,
|
|
368
|
+
duration=duration,
|
|
369
|
+
used_tools=used_tools,
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
def report_external_task(
|
|
373
|
+
self,
|
|
374
|
+
agent_id: Optional[str] = None,
|
|
375
|
+
agent: Optional[Agent] = None,
|
|
376
|
+
id: Optional[str] = None,
|
|
377
|
+
input: Optional[str] = None,
|
|
378
|
+
llm_response: Optional[Any] = None,
|
|
379
|
+
tokens: Optional[Any] = None,
|
|
380
|
+
is_success: Optional[bool] = True,
|
|
381
|
+
result: Optional[str] = None,
|
|
382
|
+
duration: Optional[float] = 0,
|
|
383
|
+
used_tools: Optional[list] = None,
|
|
384
|
+
configuration: Optional[Configuration] = None,
|
|
385
|
+
) -> Task:
|
|
386
|
+
"""
|
|
387
|
+
Synchronously report the result of an external task.
|
|
388
|
+
|
|
389
|
+
This is the blocking version of areport_external_task(). It supports either a provided Agent
|
|
390
|
+
instance (preferred), or loads by agent_id as needed.
|
|
391
|
+
|
|
392
|
+
Args:
|
|
393
|
+
agent_id (Optional[str]): The agent's ID.
|
|
394
|
+
agent (Optional[Agent]): Optional preloaded Agent instance (takes precedence).
|
|
395
|
+
id (Optional[str]): Task identifier.
|
|
396
|
+
input (Optional[str]): The input parameters or message for the task.
|
|
397
|
+
llm_response (Optional[Any]): The LLM's response object.
|
|
398
|
+
tokens (Optional[Any]): The tokens used.
|
|
399
|
+
is_success (Optional[bool]): Task success status.
|
|
400
|
+
result (Optional[str]): Final result string.
|
|
401
|
+
duration (Optional[float]): Execution duration (seconds).
|
|
402
|
+
used_tools (Optional[list]): List of tool names used.
|
|
403
|
+
configuration (Optional[Configuration]): Optional configuration override.
|
|
404
|
+
|
|
405
|
+
Returns:
|
|
406
|
+
Task: The reported Task object from the backend.
|
|
407
|
+
|
|
408
|
+
Raises:
|
|
409
|
+
ValueError: If neither agent nor agent_id is provided.
|
|
410
|
+
"""
|
|
411
|
+
return run_sync(
|
|
412
|
+
self.areport_external_task(
|
|
413
|
+
agent_id=agent_id,
|
|
414
|
+
agent=agent,
|
|
415
|
+
id=id,
|
|
416
|
+
input=input,
|
|
417
|
+
llm_response=llm_response,
|
|
418
|
+
tokens=tokens,
|
|
419
|
+
is_success=is_success,
|
|
420
|
+
result=result,
|
|
421
|
+
duration=duration,
|
|
422
|
+
used_tools=used_tools,
|
|
423
|
+
configuration=configuration,
|
|
424
|
+
)
|
|
425
|
+
)
|
|
File without changes
|