xpander-sdk 2.0.166__tar.gz → 2.0.168__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 (103) hide show
  1. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/PKG-INFO +1 -1
  2. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/setup.py +1 -1
  3. xpander_sdk-2.0.168/src/xpander_sdk/models/compactization.py +101 -0
  4. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/models/frameworks.py +2 -2
  5. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/backend/frameworks/agno.py +119 -41
  6. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/events_module.py +2 -2
  7. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/sub_modules/task.py +30 -16
  8. xpander_sdk-2.0.168/src/xpander_sdk/utils/agents/__init__.py +0 -0
  9. xpander_sdk-2.0.168/src/xpander_sdk/utils/agents/compactization_agent.py +189 -0
  10. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk.egg-info/PKG-INFO +1 -1
  11. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk.egg-info/SOURCES.txt +3 -0
  12. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/LICENSE +0 -0
  13. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/README.md +0 -0
  14. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/pyproject.toml +0 -0
  15. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/setup.cfg +0 -0
  16. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/__init__.py +0 -0
  17. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/consts/__init__.py +0 -0
  18. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/consts/api_routes.py +0 -0
  19. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/core/__init__.py +0 -0
  20. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/core/module_base.py +0 -0
  21. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/core/state.py +0 -0
  22. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/core/xpander_api_client.py +0 -0
  23. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/exceptions/__init__.py +0 -0
  24. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/exceptions/module_exception.py +0 -0
  25. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/models/__init__.py +0 -0
  26. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/models/activity.py +0 -0
  27. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/models/configuration.py +0 -0
  28. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/models/deep_planning.py +0 -0
  29. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/models/events.py +0 -0
  30. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/models/shared.py +0 -0
  31. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/models/user.py +0 -0
  32. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/__init__.py +0 -0
  33. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/__init__.py +0 -0
  34. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/agents_module.py +0 -0
  35. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/models/__init__.py +0 -0
  36. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/models/agent.py +0 -0
  37. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/models/agent_list.py +0 -0
  38. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/models/knowledge_bases.py +0 -0
  39. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/sub_modules/__init__.py +0 -0
  40. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/sub_modules/agent.py +0 -0
  41. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/utils/__init__.py +0 -0
  42. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/agents/utils/generic.py +0 -0
  43. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/backend/__init__.py +0 -0
  44. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/backend/backend_module.py +0 -0
  45. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/backend/frameworks/__init__.py +0 -0
  46. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/backend/frameworks/dispatch.py +0 -0
  47. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/backend/utils/__init__.py +0 -0
  48. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/backend/utils/mcp_oauth.py +0 -0
  49. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/__init__.py +0 -0
  50. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/decorators/__init__.py +0 -0
  51. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/decorators/on_boot.py +0 -0
  52. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/decorators/on_shutdown.py +0 -0
  53. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/decorators/on_task.py +0 -0
  54. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/models/__init__.py +0 -0
  55. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/models/deployments.py +0 -0
  56. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/models/events.py +0 -0
  57. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/utils/__init__.py +0 -0
  58. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/utils/generic.py +0 -0
  59. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/events/utils/git_init.py +0 -0
  60. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/knowledge_bases/__init__.py +0 -0
  61. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/knowledge_bases/knowledge_bases_module.py +0 -0
  62. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/knowledge_bases/models/__init__.py +0 -0
  63. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/knowledge_bases/models/knowledge_bases.py +0 -0
  64. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/knowledge_bases/sub_modules/__init__.py +0 -0
  65. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/knowledge_bases/sub_modules/knowledge_base.py +0 -0
  66. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/knowledge_bases/sub_modules/knowledge_base_document_item.py +0 -0
  67. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/knowledge_bases/utils/__init__.py +0 -0
  68. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/__init__.py +0 -0
  69. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/models/__init__.py +0 -0
  70. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/models/task.py +0 -0
  71. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/models/tasks_list.py +0 -0
  72. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/sub_modules/__init__.py +0 -0
  73. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/tasks_module.py +0 -0
  74. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/utils/__init__.py +0 -0
  75. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tasks/utils/files.py +0 -0
  76. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/__init__.py +0 -0
  77. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/decorators/__init__.py +0 -0
  78. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/decorators/register_tool.py +0 -0
  79. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/models/__init__.py +0 -0
  80. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/models/mcp.py +0 -0
  81. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/models/tool_invocation_result.py +0 -0
  82. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/sub_modules/__init__.py +0 -0
  83. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/sub_modules/tool.py +0 -0
  84. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/tools_repository_module.py +0 -0
  85. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/utils/__init__.py +0 -0
  86. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/utils/generic.py +0 -0
  87. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/utils/local_tools.py +0 -0
  88. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/modules/tools_repository/utils/schemas.py +0 -0
  89. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/utils/__init__.py +0 -0
  90. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/utils/env.py +0 -0
  91. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/utils/event_loop.py +0 -0
  92. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk/utils/tools.py +0 -0
  93. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk.egg-info/dependency_links.txt +0 -0
  94. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk.egg-info/requires.txt +0 -0
  95. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/src/xpander_sdk.egg-info/top_level.txt +0 -0
  96. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/tests/test_agents_module.py +0 -0
  97. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/tests/test_api_client.py +0 -0
  98. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/tests/test_backend_module.py +0 -0
  99. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/tests/test_boot_shutdown_handlers.py +0 -0
  100. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/tests/test_configuration.py +0 -0
  101. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/tests/test_knowledge_bases_module.py +0 -0
  102. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/tests/test_tasks_module.py +0 -0
  103. {xpander_sdk-2.0.166 → xpander_sdk-2.0.168}/tests/test_tools_repository.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xpander-sdk
3
- Version: 2.0.166
3
+ Version: 2.0.168
4
4
  Summary: xpander.ai Backend-as-a-service for AI Agents - SDK
5
5
  Home-page: https://www.xpander.ai
6
6
  Author: xpanderAI
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="xpander-sdk",
8
- version="2.0.166",
8
+ version="2.0.168",
9
9
  author="xpanderAI",
10
10
  author_email="dev@xpander.ai",
11
11
  description="xpander.ai Backend-as-a-service for AI Agents - SDK",
@@ -0,0 +1,101 @@
1
+ from typing import List
2
+
3
+ from pydantic import Field
4
+ from xpander_sdk.models.deep_planning import DeepPlanningItem
5
+ from xpander_sdk.models.shared import XPanderSharedModel
6
+ from xpander_sdk.modules.agents.models.agent import AgentInstructions
7
+ from xpander_sdk.modules.tasks.models.task import AgentExecutionInput
8
+
9
+
10
+ class TaskCompactizationInput(XPanderSharedModel):
11
+ user_input: AgentExecutionInput = Field(
12
+ ...,
13
+ description=(
14
+ "Original user input that initiated the task, including text, optional file URLs, "
15
+ "and optional user details."
16
+ ),
17
+ )
18
+ agent_instructions: AgentInstructions = Field(
19
+ ...,
20
+ description="Agent instructions (role, goals, and general guidance) that were active during execution."
21
+ )
22
+ task_context_and_messages: str = Field(
23
+ ...,
24
+ description=(
25
+ "Complete execution context including message history, tool calls, and session state. "
26
+ "This contains all information about what was attempted and what was achieved."
27
+ )
28
+ )
29
+ uncompleted_tasks: List["DeepPlanningItem"] = Field(
30
+ default_factory=list,
31
+ description=(
32
+ "List of planned tasks that remain incomplete. Each task has an id, title, and completed status. "
33
+ "ALL of these tasks MUST be completed and marked as completed=true in the continuation."
34
+ )
35
+ )
36
+
37
+ class TaskCompactizationOutput(XPanderSharedModel):
38
+ new_task_prompt: str = Field(
39
+ ...,
40
+ min_length=1,
41
+ description=(
42
+ "A continuation prompt that seamlessly continues the running execution. "
43
+ "This is NOT a new task - it's the next message in an ongoing conversation. "
44
+ "The prompt must:\n"
45
+ "1. Resume from where the execution left off (do NOT repeat completed work)\n"
46
+ "2. Focus on completing ALL remaining uncompleted tasks\n"
47
+ "3. Include specific instructions to mark each task as completed after finishing it\n"
48
+ "4. Be written as if you're continuing mid-conversation, not starting fresh\n"
49
+ "5. Reference the current state and what still needs to be done\n"
50
+ "Example: 'Continuing from where we left off, we still need to complete tasks X, Y, and Z. "
51
+ "Let's proceed with task X first, then mark it complete using the appropriate tool.'"
52
+ ),
53
+ )
54
+
55
+ task_context: str = Field(
56
+ ...,
57
+ min_length=1,
58
+ description=(
59
+ "Comprehensive context for continuing the execution. This context will be injected "
60
+ "into the agent's system prompt to maintain execution continuity.\n\n"
61
+ "REQUIRED FORMAT (use these exact headings, in this order):\n"
62
+ "1) ORIGINAL USER REQUEST\n"
63
+ "- Verbatim user_input text and any file references.\n\n"
64
+ "2) AGENT INSTRUCTIONS IN EFFECT\n"
65
+ "- General description from agent instructions.\n"
66
+ "- Role instructions (bullet list).\n"
67
+ "- Goals (bullet list).\n"
68
+ "- Any constraints or special requirements.\n\n"
69
+ "3) EXECUTION SUMMARY\n"
70
+ "- What actions were taken (facts only, no speculation).\n"
71
+ "- What outputs were produced (facts only).\n\n"
72
+ "4) CURRENT STATE AND ARTIFACTS\n"
73
+ "- All created artifacts with their identifiers, paths, URLs, or references.\n"
74
+ "- Current state of variables, decisions, configurations, and assumptions.\n"
75
+ "- Active session or database state if relevant.\n\n"
76
+ "5) MESSAGES AND KEY EVIDENCE\n"
77
+ "- Compact chronological summary of the conversation flow.\n"
78
+ "- Up to 5 verbatim quotes (max 25 words each) capturing critical details.\n\n"
79
+ "6) TOOL CALLS AND OBSERVATIONS\n"
80
+ "- For each tool call: tool name/id, purpose, key inputs, key outputs, errors.\n"
81
+ "- Include plan tool calls (create/get/complete) if they occurred.\n"
82
+ "- If no tools used: 'No tool calls were made.'\n\n"
83
+ "7) COMPLETED VS UNCOMPLETED TASKS\n"
84
+ "- Completed: List with task IDs and titles that are done.\n"
85
+ "- Uncompleted: List each task ID, title, and specific reason it's incomplete.\n"
86
+ "- CRITICAL: All uncompleted tasks MUST be finished in the continuation.\n\n"
87
+ "8) OPEN QUESTIONS AND UNKNOWNS\n"
88
+ "- Missing information needed to complete remaining tasks.\n"
89
+ "- Blockers or dependencies preventing progress.\n"
90
+ "- If none: 'No open questions.'\n\n"
91
+ "9) NEXT ACTIONS TO COMPLETE ALL TASKS\n"
92
+ "- Ordered list of specific actions to complete each uncompleted task.\n"
93
+ "- Each action should reference the task ID it completes.\n"
94
+ "- Final action must be to mark all tasks as completed using the plan tools.\n\n"
95
+ "ACCURACY REQUIREMENTS:\n"
96
+ "- Do NOT invent details. Use 'Unknown' if information is missing.\n"
97
+ "- Preserve exact names, IDs, numbers, file paths, and user wording.\n"
98
+ "- Task completion status must match reality - no implied completion.\n"
99
+ "- Focus on actionable, specific continuation steps.\n"
100
+ ),
101
+ )
@@ -30,7 +30,7 @@ class AgnoSettings(BaseModel):
30
30
  session_storage (Optional[bool]): If True, enables session-level storage. Default is True.
31
31
  user_memories (Optional[bool]): If True, enables memory of user interactions. Default is True.
32
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.
33
+ num_history_runs (Optional[int]): Number of historical runs to retain or consider. Default is 10.
34
34
  tool_call_limit (Optional[int]): Max tool calls per run.
35
35
  coordinate_mode (Optional[bool]): If True, The agent will be loaded as a Team. Default is False.
36
36
  pii_detection_enabled (Optional[bool]): If True, enables PII detection guardrail on agent input. Default is False.
@@ -50,7 +50,7 @@ class AgnoSettings(BaseModel):
50
50
  agentic_culture: Optional[bool] = False
51
51
 
52
52
  session_summaries: Optional[bool] = False
53
- num_history_runs: Optional[int] = 3
53
+ num_history_runs: Optional[int] = 10
54
54
  max_tool_calls_from_history: Optional[int] = 0
55
55
  tool_call_limit: Optional[int] = None
56
56
  coordinate_mode: Optional[bool] = False
@@ -219,6 +219,7 @@ async def build_agent_args(
219
219
 
220
220
  def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task: Optional[Task]) -> None:
221
221
  if args and agent and task and agent.deep_planning and task.deep_planning.enabled == True:
222
+ task.reload() # reload the task - get latest version
222
223
  # add instructions guidance
223
224
  if not "instructions" in args:
224
225
  args["instructions"] = ""
@@ -227,23 +228,49 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
227
228
  <important_planning_instructions>
228
229
  ## **Deep Planning Tools - Essential for Multi-Step Tasks**
229
230
 
231
+ **ABSOLUTE RULE - READ THIS FIRST**:
232
+
233
+ IF YOU ARE ABOUT TO WRITE A QUESTION TO THE USER, STOP AND CHECK:
234
+ - Did I call xpstart_execution_plan?
235
+ - YES → Use xpask_for_information tool (DO NOT write the question in your response)
236
+ - NO → You can ask directly
237
+
238
+ SIMPLE RULE:
239
+ - BEFORE calling xpstart_execution_plan: You CAN ask questions directly in your response
240
+ - AFTER calling xpstart_execution_plan: You are FORBIDDEN from writing questions - use xpask_for_information tool
241
+
242
+ Once execution has started, writing things like "Before I proceed, I need to know..." or "I need clarification on..."
243
+ or "Please choose one of the following..." in your response text is STRICTLY PROHIBITED and will cause execution failures.
244
+
245
+ MANDATORY CHECK BEFORE ASKING: Have I started the plan? YES = use tool | NO = can ask directly
246
+
230
247
  When handling complex tasks with multiple steps, use these planning tools to track progress systematically.
231
248
 
232
249
  ### **Core Workflow**
233
- 1. **CREATE** plan at the start (`xpcreate-agent-plan`)
234
- 2. **START** plan execution (`xpstart-execution-plan`) - MANDATORY to enable enforcement
235
- 3. **CHECK** plan before each action (`xpget-agent-plan`)
236
- 4. **COMPLETE** task immediately after finishing it (`xpcomplete-agent-plan-item`)
237
- 5. **ASK** user for info if needed (`xpask-for-information`)
238
- 6. Repeat steps 3-5 until all tasks are done
250
+ 1. **CREATE** plan at the start (`xpcreate_agent_plan`)
251
+ 2. **START** plan execution (`xpstart_execution_plan`) - MANDATORY to enable enforcement
252
+ 3. **CHECK** plan before each action (`xpget_agent_plan`)
253
+ 4. **DO THE WORK** for one task
254
+ 5. **COMPLETE** task IMMEDIATELY - call `xpcomplete_agent_plan_item` RIGHT AFTER finishing work (DO NOT DELAY!)
255
+ 6. **ASK** user for info if needed (`xpask_for_information`) - MANDATORY if you need input or want to pause
256
+ 7. Repeat steps 3-6 until all tasks are done
257
+
258
+ **CRITICAL RULES - ABSOLUTE REQUIREMENTS**:
259
+ - Mark each task complete THE MOMENT you finish it - not later, not at the end, RIGHT AWAY!
260
+ - **CHECK BEFORE ASKING**: Did you call xpstart_execution_plan?
261
+ - If YES: Use xpask_for_information tool ONLY (never write questions in response)
262
+ - If NO: Can ask directly
263
+ - **AFTER plan starts: Writing questions in your response is FORBIDDEN** - violates execution protocol
264
+ - If you called xpstart_execution_plan and then write "I need clarification" or "Before I proceed" or "Please choose", you are VIOLATING THE PROTOCOL
265
+ - AFTER xpstart_execution_plan: The ONLY way to ask users questions is through `xpask_for_information` tool - ZERO EXCEPTIONS!
239
266
 
240
267
  ---
241
268
 
242
269
  ### **Tool Reference**
243
270
 
244
- #### **1. xpcreate-agent-plan** - Create Initial Plan
271
+ #### **1. xpcreate_agent_plan** - Create Initial Plan
245
272
  **When to use**: At the very start of any multi-step task, ONLY if no plan exists yet
246
- **Note**: After creating a plan, you MUST call `xpstart-execution-plan` to begin enforcement
273
+ **Note**: After creating a plan, you MUST call `xpstart_execution_plan` to begin enforcement
247
274
 
248
275
  **How to use**:
249
276
  - Pass an array of task objects (NOT strings)
@@ -269,7 +296,7 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
269
296
 
270
297
  ---
271
298
 
272
- #### **2. xpget-agent-plan** - View Current Plan
299
+ #### **2. xpget_agent_plan** - View Current Plan
273
300
  **When to use**: Before deciding what to do next; to check progress
274
301
 
275
302
  **Returns**:
@@ -280,8 +307,8 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
280
307
 
281
308
  ---
282
309
 
283
- #### **3. xpcomplete-agent-plan-item** - Mark Task Complete
284
- **When to use**: **IMMEDIATELY** after finishing each task (NOT before!)
310
+ #### **3. xpcomplete_agent_plan_item** - Mark Task Complete
311
+ **When to use**: **IMMEDIATELY** after finishing each task (NOT before, NOT later, RIGHT NOW!)
285
312
 
286
313
  **How to use**:
287
314
  ```json
@@ -291,14 +318,19 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
291
318
  }
292
319
  }
293
320
  ```
294
- **CRITICAL**:
295
- - Only mark complete AFTER work is actually done
296
- - This is MANDATORY for progress tracking
297
- - Get the task ID from `xpget-agent-plan` results
321
+ **🚨 CRITICAL - NON-NEGOTIABLE RULES**:
322
+ - Call THIS TOOL the INSTANT you finish a task
323
+ - DO NOT wait to mark multiple tasks at once
324
+ - DO NOT postpone marking completion
325
+ - DO NOT be lazy - mark it complete RIGHT AFTER the work is done
326
+ - This is MANDATORY for progress tracking and continuation
327
+ - If you finish a task and don't mark it complete immediately, you are doing it WRONG
328
+
329
+ **Pattern**: Finish work → IMMEDIATELY call xpcomplete_agent_plan_item → Move to next task
298
330
 
299
331
  ---
300
332
 
301
- #### **4. xpadd-new-agent-plan-item** - Add Discovered Task
333
+ #### **4. xpadd_new_agent_plan_item** - Add Discovered Task
302
334
  **When to use**: When you discover additional work needed during execution
303
335
 
304
336
  **How to use**:
@@ -312,7 +344,7 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
312
344
  ```
313
345
  ---
314
346
 
315
- #### **5. xpupdate-agent-plan-item** - Modify Existing Task
347
+ #### **5. xpupdate_agent_plan_item** - Modify Existing Task
316
348
  **When to use**: When task details change or need clarification
317
349
 
318
350
  **How to use**:
@@ -329,7 +361,7 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
329
361
 
330
362
  ---
331
363
 
332
- #### **6. xpdelete-agent-plan-item** - Remove Task
364
+ #### **6. xpdelete_agent_plan_item** - Remove Task
333
365
  **When to use**: When a task becomes unnecessary or redundant
334
366
 
335
367
  **How to use**:
@@ -342,8 +374,8 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
342
374
  ```
343
375
  ---
344
376
 
345
- #### **7. xpstart-execution-plan** - Start Plan Execution
346
- **When to use**: Immediately after creating a plan with `xpcreate-agent-plan`
377
+ #### **7. xpstart_execution_plan** - Start Plan Execution
378
+ **When to use**: Immediately after creating a plan with `xpcreate_agent_plan`
347
379
  **CRITICAL**: Must be called to enable enforcement mode before executing tasks
348
380
 
349
381
  **How to use**:
@@ -361,9 +393,19 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
361
393
 
362
394
  ---
363
395
 
364
- #### **8. xpask-for-information** - Ask User a Question
365
- **When to use**: When you need information from the user during plan execution
396
+ #### **8. xpask_for_information** - Ask User a Question
397
+ **When to use**: **MANDATORY AFTER PLAN STARTS** when you need ANY of the following:
398
+ - Information from the user
399
+ - Clarification on requirements
400
+ - Approval before proceeding
401
+ - To pause execution for user input
402
+
366
403
  **PREREQUISITE**: Plan must be started (running) first
404
+
405
+ **CRITICAL RULE**: Once the plan has started, if you need user input or want to pause, you MUST use this tool.
406
+ DO NOT just respond with questions in your regular output after plan starts - that breaks execution flow!
407
+
408
+ **NOTE**: BEFORE starting the plan (before xpstart_execution_plan), you CAN ask questions directly if needed.
367
409
 
368
410
  **How to use**:
369
411
  ```json
@@ -375,10 +417,13 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
375
417
  ```
376
418
 
377
419
  **What it does**:
378
- - Sets `question_raised` flag to true
379
- - Prints the question for the user
380
- - Keeps enforcement active (does NOT pause execution)
381
- - Returns waiting status
420
+ - Properly pauses plan enforcement and sets `question_raised` flag
421
+ - Delivers question to the user through the correct channel
422
+ - Manages execution state for proper continuation
423
+ - Allows resuming execution after user responds
424
+
425
+ **Why this matters**: Using this tool ensures execution can be properly continued with full context.
426
+ Just responding with a question will NOT pause execution correctly!
382
427
 
383
428
  ---
384
429
 
@@ -386,19 +431,27 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
386
431
 
387
432
  ✅ **DO:**
388
433
  - Create comprehensive plans with ALL necessary steps
389
- - **START** the plan with `xpstart-execution-plan` after creating it
434
+ - **START** the plan with `xpstart_execution_plan` after creating it
390
435
  - Use descriptive, actionable task titles
391
436
  - Check plan before each action to stay oriented
392
- - Mark tasks complete immediately after finishing them
393
- - Ask for user information when needed with `xpask-for-information`
437
+ - **Mark tasks complete THE INSTANT you finish them - NO DELAYS, NO EXCEPTIONS**
438
+ - **ALWAYS use `xpask_for_information` when you need user input or want to pause**
394
439
  - Call plan tools **sequentially** (one at a time, never in parallel)
440
+ - Follow the pattern: DO WORK → MARK COMPLETE → NEXT TASK
395
441
 
396
- ❌ **DON'T:**
442
+ ❌ **DON'T - THESE ARE FORBIDDEN:**
397
443
  - Mark tasks complete before they're actually done
444
+ - **Be lazy and wait to mark tasks complete later** (FORBIDDEN!)
445
+ - **Batch mark multiple tasks at the end** (WRONG! Mark each immediately!)
446
+ - **AFTER plan starts: NEVER write questions in your response text** ("Before I proceed...", "I need clarification...", etc.)
447
+ - **AFTER plan starts: NEVER respond with questions - ONLY use xpask_for_information tool** (ABSOLUTE RULE!)
398
448
  - Pass plain string arrays - must be objects with `title` field
399
449
  - Call plan tools in parallel with each other
400
450
  - Skip checking the plan between major steps
401
- - Forget to mark completed tasks
451
+ - Postpone marking completion "until later" - there is no later, only NOW
452
+
453
+ **REMEMBER**: Once execution started, any text like "I need to know", "Before I proceed", "I need clarification" means you MUST call xpask_for_information instead!
454
+ **EXCEPTION**: Before starting the plan, you CAN ask questions directly if needed for planning.
402
455
 
403
456
  ---
404
457
 
@@ -407,7 +460,7 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
407
460
  ```
408
461
  1. User: "Build a REST API for user management"
409
462
 
410
- 2. Call: xpcreate-agent-plan
463
+ 2. Call: xpcreate_agent_plan
411
464
  tasks: [
412
465
  {"title": "Design user schema"},
413
466
  {"title": "Create database migration"},
@@ -416,27 +469,52 @@ def _configure_deep_planning_guidance(args: Dict[str, Any], agent: Agent, task:
416
469
  {"title": "Write integration tests"}
417
470
  ]
418
471
 
419
- 3. Call: xpstart-execution-plan
472
+ 3. Call: xpstart_execution_plan
420
473
  → Plan now started, enforcement enabled (if enforce=true)
421
474
 
422
- 4. Call: xpget-agent-plan
475
+ 4. Call: xpget_agent_plan
423
476
  → See: Task 1 (ID: abc-123) - Design user schema - Not complete
424
477
 
425
- 5. [Realize need user input] Call: xpask-for-information
478
+ 5. [Realize need user input] Call: xpask_for_information
426
479
  question: "Which database should we use - PostgreSQL or MySQL?"
427
480
  → question_raised=true, waiting for response
428
481
 
429
- 6. [After user responds, do the work: Design schema]
482
+ 6. [After user responds, DO THE WORK: Design schema]
430
483
 
431
- 7. Call: xpcomplete-agent-plan-item
484
+ 7. ⚠️ IMMEDIATELY Call: xpcomplete_agent_plan_item
432
485
  id: "abc-123"
486
+ → MARKED COMPLETE RIGHT AFTER FINISHING - NOT DELAYED!
487
+
488
+ 8. Call: xpget_agent_plan
489
+ → See: Task 1 ✓ complete, Task 2 (ID: def-456) - Create database migration - Not complete
490
+
491
+ 9. [DO THE WORK: Create migration file]
433
492
 
434
- 8. Call: xpget-agent-plan
435
- → See: Task 1 ✓ complete, Task 2 next...
493
+ 10. ⚠️ IMMEDIATELY Call: xpcomplete_agent_plan_item
494
+ id: "def-456"
495
+ → MARKED COMPLETE RIGHT AWAY!
436
496
 
437
- 9. [Continue through remaining tasks]
497
+ 11. [Continue this pattern: GET PLAN → DO WORK → MARK COMPLETE IMMEDIATELY → REPEAT]
498
+ ```
499
+
500
+ ### **WRONG WAY - ANTI-PATTERN (DO NOT DO THIS)**
501
+
502
+ ```
503
+ ❌ WRONG:
504
+ 1. Call: xpcreate_agent_plan
505
+ 2. Call: xpstart_execution_plan ← PLAN IS NOW STARTED!
506
+ 3. Respond: "Before I proceed, I need clarification on..." ← WRONG! FORBIDDEN!
507
+
508
+ ✅ CORRECT:
509
+ 1. Call: xpcreate_agent_plan
510
+ 2. Call: xpstart_execution_plan ← PLAN IS NOW STARTED!
511
+ 3. Call: xpask_for_information with question ← CORRECT! Use the tool!
438
512
  ```
439
- **Remember**: The plan is your roadmap. Check it often, update it as needed, and always mark tasks complete when done!
513
+
514
+ **KEY POINT**: Once you call `xpstart_execution_plan`, the execution mode changes.
515
+ You CANNOT write questions in your response anymore. You MUST use the tool.
516
+
517
+ **Golden Rule**: FINISH TASK → MARK COMPLETE INSTANTLY → MOVE TO NEXT TASK. No delays, no batching, no "I'll do it later"!
440
518
  </important_planning_instructions>
441
519
  """
442
520
 
@@ -358,12 +358,12 @@ class Events(ModuleBase):
358
358
  plan_following_status = await task.aget_plan_following_status()
359
359
  if not plan_following_status.can_finish:
360
360
  # Check if we've exceeded max retries
361
- if retry_count >= 2: # 0, 1, 2 = 3 total attempts
361
+ if retry_count >= 50: # 0, 1, 2 = 50 total attempts
362
362
  logger.warning(f"Failed to complete plan after {retry_count + 1} attempts. Remaining incomplete tasks.")
363
363
  return
364
364
 
365
365
  # Recursively call with incremented retry count
366
- logger.info(f"Plan not complete, retrying (attempt {retry_count + 2}/3)")
366
+ logger.info(f"Plan not complete, retrying (attempt {retry_count + 2})")
367
367
  await self.handle_task_execution_request(
368
368
  agent_worker,
369
369
  task,
@@ -43,7 +43,7 @@ from httpx import HTTPStatusError
43
43
  import httpx
44
44
  import json
45
45
  from httpx_sse import aconnect_sse
46
- from pydantic import Field, computed_field
46
+ from pydantic import Field
47
47
 
48
48
  from xpander_sdk.consts.api_routes import APIRoute
49
49
  from xpander_sdk.core.xpander_api_client import APIClient
@@ -337,10 +337,13 @@ class Task(XPanderSharedModel):
337
337
  """
338
338
  return run_sync(self.aset_status(status=status, result=result))
339
339
 
340
- async def asave(self):
340
+ async def asave(self, with_deep_plan_update: Optional[bool] = False):
341
341
  """
342
342
  Asynchronously saves the current task state to the backend.
343
343
 
344
+ Args:
345
+ with_deep_plan_update (Optional[bool]): should update deep plan as well? default false.
346
+
344
347
  Raises:
345
348
  ModuleException: Error related to HTTP requests or task saving.
346
349
 
@@ -349,10 +352,15 @@ class Task(XPanderSharedModel):
349
352
  """
350
353
  client = APIClient(configuration=self.configuration)
351
354
  try:
355
+ exclude = {"configuration"}
356
+
357
+ if not with_deep_plan_update:
358
+ exclude.add("deep_planning")
359
+
352
360
  response = await client.make_request(
353
361
  path=APIRoute.UpdateTask.format(task_id=self.id),
354
362
  method="PATCH",
355
- payload=self.model_dump_safe(exclude={"configuration","deep_planning"}),
363
+ payload=self.model_dump_safe(exclude=exclude),
356
364
  )
357
365
  updated_task = Task(**response, configuration=self.configuration)
358
366
  for field, value in updated_task.__dict__.items():
@@ -362,16 +370,19 @@ class Task(XPanderSharedModel):
362
370
  except Exception as e:
363
371
  raise ModuleException(500, f"Failed to save task: {str(e)}")
364
372
 
365
- def save(self):
373
+ def save(self, with_deep_plan_update: Optional[bool] = False):
366
374
  """
367
375
  Saves the current task state synchronously.
368
376
 
369
377
  This function wraps the asynchronous asave method.
378
+
379
+ Args:
380
+ with_deep_plan_update (Optional[bool]): should update deep plan as well? default false.
370
381
 
371
382
  Example:
372
383
  >>> task.save()
373
384
  """
374
- return run_sync(self.asave())
385
+ return run_sync(self.asave(with_deep_plan_update=with_deep_plan_update))
375
386
 
376
387
  async def astop(self):
377
388
  """
@@ -540,16 +551,20 @@ class Task(XPanderSharedModel):
540
551
  for f in readable_files:
541
552
  message += f"\n{json.dumps(f)}"
542
553
 
543
- if self.deep_planning and self.deep_planning.enabled == True:
554
+ if self.deep_planning and self.deep_planning.enabled == True and self.deep_planning.started:
544
555
  self.reload()
545
- uncompleted_tasks = [task for task in self.deep_planning.tasks if not task.completed]
546
- if len(uncompleted_tasks) != 0:
547
- message = "\n".join([
548
- "Task not finished, uncompleted tasks detected:",
549
- f"Uncompleted tasks: {[task.model_dump_json() for task in uncompleted_tasks]}",
550
- "You must complete tasks if fulfilled",
551
- f"User's original request: \"{message}\""
552
- ])
556
+ if not self.deep_planning.question_raised:
557
+ uncompleted_tasks = [task for task in self.deep_planning.tasks if not task.completed]
558
+ if len(uncompleted_tasks) != 0: # make a retry with compactization
559
+ from xpander_sdk.utils.agents.compactization_agent import run_task_compactization
560
+ compactization_result = run_task_compactization(message=message, task=self, uncompleted_tasks=uncompleted_tasks)
561
+ if isinstance(compactization_result, str):
562
+ message = compactization_result
563
+ else:
564
+ message = f"<user_input>{compactization_result.new_task_prompt}</user_input><task_context>{compactization_result.task_context}</task_context>"
565
+ else:
566
+ self.deep_planning.question_raised = False # reset question raised indicator
567
+ self.save(with_deep_plan_update=True)
553
568
 
554
569
  return message
555
570
 
@@ -785,9 +800,8 @@ class Task(XPanderSharedModel):
785
800
  ... print(f"Remaining tasks: {len(status.uncompleted_tasks)}")
786
801
  """
787
802
  try:
788
- return PlanFollowingStatus(can_finish=True) # TODO: complete
803
+ await self.areload()
789
804
  if self.deep_planning and self.deep_planning.enabled and self.deep_planning.started and self.deep_planning.enforce:
790
- await self.areload()
791
805
 
792
806
  # allow early exit to ask question
793
807
  if self.deep_planning.question_raised:
@@ -0,0 +1,189 @@
1
+ from typing import TYPE_CHECKING, List, Union
2
+ from agno.agent import Agent as AgnoAgent
3
+ from loguru import logger
4
+ import json
5
+ from xpander_sdk.models.compactization import TaskCompactizationOutput, TaskCompactizationInput
6
+ from xpander_sdk.models.deep_planning import DeepPlanningItem
7
+ from xpander_sdk.models.frameworks import Framework
8
+ from xpander_sdk.models.shared import Tokens
9
+ from xpander_sdk.modules.agents.agents_module import Agents
10
+ from xpander_sdk.modules.backend.backend_module import Backend
11
+
12
+ if TYPE_CHECKING:
13
+ from xpander_sdk.modules.tasks.sub_modules.task import Task
14
+
15
+ def run_task_compactization(message: str, task: "Task", uncompleted_tasks: List[DeepPlanningItem]) -> Union[str, TaskCompactizationOutput]:
16
+ try:
17
+ # get agent to identify framework
18
+ agent = Agents(configuration=task.configuration).get(agent_id=task.agent_id,version=task.agent_version)
19
+
20
+ # non agno, let the same agent handle it
21
+ if agent.framework != Framework.Agno:
22
+ return "\n".join([
23
+ "Task not finished, uncompleted tasks detected:",
24
+ f"Uncompleted tasks: {[task.model_dump_json() for task in uncompleted_tasks]}",
25
+ "You must complete tasks if fulfilled",
26
+ f"User's original request: \"{message}\""
27
+ ])
28
+
29
+ # load backend args for consistency of model provider and settings
30
+ agno_args = Backend(configuration=agent.configuration).get_args(agent_id=agent.id, agent_version=agent.version, task=task)
31
+
32
+ if agent.model_provider == "openai":
33
+ agno_args["model"].id = "gpt-5-mini"
34
+
35
+ # create compacitzation agent
36
+ compactization_agent = AgnoAgent(
37
+ output_schema=TaskCompactizationOutput,
38
+ name="Task Compactization Agent",
39
+ model=agno_args.get("model"),
40
+ description="""
41
+ You analyze a running agent execution that has uncompleted tasks and produce a seamless continuation package.
42
+
43
+ Your output enables the execution to resume exactly where it left off and complete ALL remaining tasks.
44
+
45
+ You produce:
46
+ 1. A continuation prompt that picks up mid-execution (NOT a new task start)
47
+ 2. Comprehensive context that preserves all critical state, decisions, and artifacts
48
+
49
+ CRITICAL: ALL uncompleted tasks provided to you MUST be addressed and marked as completed in your continuation plan.
50
+ """,
51
+ role="""
52
+ You are a **Task Compactization Agent** specialized in maintaining execution continuity.
53
+
54
+ Your mission: Convert a partially-executed agent run into a precise continuation package that allows the execution
55
+ to resume seamlessly and complete ALL uncompleted tasks without repetition or confusion.
56
+
57
+ You are NOT starting a new task - you are continuing a running process that was interrupted.
58
+ The next agent run will receive your continuation prompt as the next message in an ongoing conversation.
59
+ """,
60
+ instructions="""
61
+ ## Core Principles
62
+
63
+ * **This is a CONTINUATION, not a restart.** The next prompt continues an active execution mid-conversation.
64
+ * **ALL uncompleted tasks MUST be completed.** Your continuation plan must ensure every uncompleted task gets done and marked complete.
65
+ * **Stay factual.** Do not invent details. Use "Unknown" for missing information and list it under open questions.
66
+ * **Preserve exact state.** Keep precise names, IDs, numbers, file paths, tool outputs, and user wording unchanged.
67
+ * **Track completion accurately.** Never imply completion. Clearly distinguish what IS done from what REMAINS to be done.
68
+
69
+ ## What You Must Capture
70
+
71
+ * **Tool call history.** For each tool: name/id, purpose, inputs (high-level), outputs (high-level), errors. Include plan tools (xpcreate_agent_plan, xpcomplete_agent_plan_item, etc.).
72
+ * **Artifacts and state.** All created files, IDs, URLs, variables, decisions, and configurations.
73
+ * **What worked / what didn't.** Successes, failures, blockers, missing info, wrong assumptions.
74
+ * **Task completion status.** For each uncompleted task: exact ID, title, and specific reason it's incomplete.
75
+ * **PROTOCOL VIOLATIONS.** Check if agent asked questions in response text AFTER calling xpstart_execution_plan (violates protocol).
76
+
77
+ ## Detecting Protocol Violations
78
+
79
+ If the agent's last message contains questions to the user AFTER the plan was started (after xpstart_execution_plan was called):
80
+ - This is a PROTOCOL VIOLATION
81
+ - The agent should have used xpask_for_information tool instead
82
+
83
+ When violation is detected, you MUST make it SUPER CLEAR in BOTH output fields:
84
+
85
+ **In `new_task_prompt`:**
86
+ - START with: "CRITICAL PROTOCOL VIOLATION DETECTED: You asked questions directly after starting the plan."
87
+ - Explicitly state: "You MUST use xpask_for_information tool to ask questions once plan is running."
88
+ - Include: "NEVER write questions in your response text after calling xpstart_execution_plan."
89
+ - Then provide the continuation instructions
90
+
91
+ **In `task_context`:**
92
+ - Add a dedicated section at the TOP before section 1: "**PROTOCOL VIOLATION DETECTED**"
93
+ - State clearly: "Agent asked questions in response text after calling xpstart_execution_plan. This violates execution protocol."
94
+ - Remind: "Rule: After xpstart_execution_plan is called, questions MUST be asked using xpask_for_information tool, NOT written in response text."
95
+
96
+ Signs of protocol violation in messages:
97
+ - Phrases like "Before I proceed", "I need clarification", "Please choose", "Which option"
98
+ - Questions written in response text after xpstart_execution_plan was called
99
+
100
+ ## Continuation Prompt Requirements
101
+
102
+ Your `new_task_prompt` must:
103
+ 1. **IF protocol violation detected:** START with "CRITICAL PROTOCOL VIOLATION DETECTED" warning (see above)
104
+ 2. Resume where execution stopped ("Continuing from where we left off...")
105
+ 3. NOT repeat completed work
106
+ 4. List ALL uncompleted tasks by ID and title
107
+ 5. Provide step-by-step actions to complete each task
108
+ 6. Explicitly instruct to mark each task complete using xpcomplete_agent_plan_item after finishing it
109
+ 7. Sound like the next message in an ongoing conversation, not a new task
110
+ 8. **IF protocol violation:** Emphasize the requirement to use xpask_for_information tool for any questions
111
+
112
+ ## Task Context Requirements
113
+
114
+ Your `task_context` must:
115
+ 1. **IF protocol violation detected:** Add "PROTOCOL VIOLATION DETECTED" section at the TOP before section 1
116
+ 2. Follow the exact 9-heading structure specified in the output schema (or 10 if violation detected)
117
+ 3. Be deterministic and parseable by downstream systems
118
+ 4. Focus on actionable continuation steps in section 9 (NEXT ACTIONS)
119
+ 5. Include task IDs for all uncompleted tasks
120
+ 6. Emphasize that ALL tasks must be completed and marked complete
121
+
122
+ ## Critical Rules
123
+
124
+ ❌ **NEVER:**
125
+ - Suggest restarting or creating a new plan
126
+ - Mark tasks as complete that aren't actually done
127
+ - Invent details or speculate
128
+ - Write a "fresh start" prompt
129
+
130
+ ✅ **ALWAYS:**
131
+ - Write continuation prompts that resume mid-execution
132
+ - Include all uncompleted task IDs and titles
133
+ - Provide specific actions to complete each task
134
+ - Instruct to mark tasks complete using the plan tools
135
+ - Preserve exact state, IDs, names, and wording
136
+ - **Check for protocol violations** and correct them in your continuation prompt
137
+ - If agent asked questions in text after plan started, instruct to use xpask_for_information tool instead
138
+ """,
139
+ expected_output="""
140
+ Return a JSON object with exactly these two fields:
141
+
142
+ - new_task_prompt (string): A continuation message that resumes the running execution mid-conversation.
143
+ IF PROTOCOL VIOLATION DETECTED (agent asked questions after xpstart_execution_plan):
144
+ - START WITH: "CRITICAL PROTOCOL VIOLATION DETECTED: You asked questions directly after starting the plan. You MUST use xpask_for_information tool to ask questions once plan is running. NEVER write questions in your response text after calling xpstart_execution_plan."
145
+ Then: (1) list ALL uncompleted tasks with their IDs and titles, (2) give step-by-step actions to finish each,
146
+ (3) explicitly instruct to mark each task complete using xpcomplete_agent_plan_item after finishing it, and
147
+ (4) read like the next message in an ongoing conversation (NOT a fresh start).
148
+
149
+ - task_context (string): Comprehensive context for continuation.
150
+ IF PROTOCOL VIOLATION DETECTED:
151
+ - Add section at TOP: "**PROTOCOL VIOLATION DETECTED**\nAgent asked questions in response text after calling xpstart_execution_plan. This violates execution protocol. Rule: After xpstart_execution_plan is called, questions MUST be asked using xpask_for_information tool, NOT written in response text.\n\n"
152
+ Then follow the EXACT 9-section structure defined in TaskCompactizationOutput.task_context.
153
+ Must be deterministic, actionable, and focused on completing ALL remaining tasks and marking them as completed.
154
+
155
+ Important:
156
+ - Do NOT invent details; write 'Unknown' when information is missing.
157
+ - Preserve exact IDs, names, file paths, numbers, and user phrasing.
158
+ - Final actions must include marking each remaining task as completed with the plan tools.
159
+ - IF protocol violation: Make it SUPER CLEAR in both fields that tool must be used for questions.
160
+ """
161
+ )
162
+
163
+ session = agent.get_session(session_id=task.id)
164
+
165
+ # run compactization
166
+ run_result = compactization_agent.run(
167
+ input=TaskCompactizationInput(
168
+ user_input=task.input,
169
+ agent_instructions=agent.instructions,
170
+ task_context_and_messages=json.dumps({"messages": [message.model_dump() for message in session.get_messages() if message.role != "system"]}),
171
+ uncompleted_tasks=uncompleted_tasks
172
+ )
173
+ )
174
+
175
+ # reset old session
176
+ agent.delete_session(session_id=task.id)
177
+
178
+ # report LLM Metrics
179
+ task.tokens = Tokens(
180
+ completion_tokens=run_result.metrics.output_tokens,
181
+ prompt_tokens=run_result.metrics.input_tokens
182
+ )
183
+
184
+ task.report_metrics(configuration=task.configuration)
185
+
186
+ return run_result.content
187
+ except Exception as e:
188
+ logger.warning(f"Failed to run task compactization - {str(e)}")
189
+ return message
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xpander-sdk
3
- Version: 2.0.166
3
+ Version: 2.0.168
4
4
  Summary: xpander.ai Backend-as-a-service for AI Agents - SDK
5
5
  Home-page: https://www.xpander.ai
6
6
  Author: xpanderAI
@@ -18,6 +18,7 @@ src/xpander_sdk/exceptions/__init__.py
18
18
  src/xpander_sdk/exceptions/module_exception.py
19
19
  src/xpander_sdk/models/__init__.py
20
20
  src/xpander_sdk/models/activity.py
21
+ src/xpander_sdk/models/compactization.py
21
22
  src/xpander_sdk/models/configuration.py
22
23
  src/xpander_sdk/models/deep_planning.py
23
24
  src/xpander_sdk/models/events.py
@@ -88,6 +89,8 @@ src/xpander_sdk/utils/__init__.py
88
89
  src/xpander_sdk/utils/env.py
89
90
  src/xpander_sdk/utils/event_loop.py
90
91
  src/xpander_sdk/utils/tools.py
92
+ src/xpander_sdk/utils/agents/__init__.py
93
+ src/xpander_sdk/utils/agents/compactization_agent.py
91
94
  tests/test_agents_module.py
92
95
  tests/test_api_client.py
93
96
  tests/test_backend_module.py
File without changes
File without changes
File without changes