xgae 0.1.4__tar.gz → 0.1.6__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.

Potentially problematic release.


This version of xgae might be problematic. Click here for more details.

Files changed (39) hide show
  1. {xgae-0.1.4 → xgae-0.1.6}/.idea/misc.xml +1 -1
  2. {xgae-0.1.4 → xgae-0.1.6}/.idea/workspace.xml +59 -50
  3. {xgae-0.1.4 → xgae-0.1.6}/.idea/xgae.iml +1 -1
  4. {xgae-0.1.4 → xgae-0.1.6}/PKG-INFO +1 -1
  5. {xgae-0.1.4 → xgae-0.1.6}/pyproject.toml +1 -1
  6. xgae-0.1.4/src/xgae/engine/xga_base.py → xgae-0.1.6/src/xgae/engine/engine_base.py +12 -15
  7. xgae-0.1.4/src/xgae/engine/xga_mcp_tool_box.py → xgae-0.1.6/src/xgae/engine/mcp_tool_box.py +6 -9
  8. xgae-0.1.4/src/xgae/engine/xga_prompt_builder.py → xgae-0.1.6/src/xgae/engine/prompt_builder.py +3 -2
  9. xgae-0.1.6/src/xgae/engine/responser/non_stream_responser.py +110 -0
  10. xgae-0.1.4/src/xgae/engine/responser/xga_responser_base.py → xgae-0.1.6/src/xgae/engine/responser/responser_base.py +103 -228
  11. xgae-0.1.4/src/xgae/engine/responser/xga_stream_responser.py → xgae-0.1.6/src/xgae/engine/responser/stream_responser.py +94 -55
  12. xgae-0.1.6/src/xgae/engine/task_engine.py +360 -0
  13. xgae-0.1.6/src/xgae/utils/__init__.py +13 -0
  14. xgae-0.1.4/src/xgae/utils/utils.py → xgae-0.1.6/src/xgae/utils/misc.py +0 -8
  15. xgae-0.1.6/src/xgae/utils/setup_env.py +78 -0
  16. {xgae-0.1.4 → xgae-0.1.6}/src/xgae/utils/xml_tool_parser.py +4 -7
  17. xgae-0.1.4/src/xgae/engine/responser/xga_non_stream_responser.py +0 -213
  18. xgae-0.1.4/src/xgae/engine/xga_engine.py +0 -278
  19. xgae-0.1.4/src/xgae/utils/setup_env.py +0 -93
  20. {xgae-0.1.4 → xgae-0.1.6}/.env +0 -0
  21. {xgae-0.1.4 → xgae-0.1.6}/.idea/.gitignore +0 -0
  22. {xgae-0.1.4 → xgae-0.1.6}/.idea/inspectionProfiles/Project_Default.xml +0 -0
  23. {xgae-0.1.4 → xgae-0.1.6}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
  24. {xgae-0.1.4 → xgae-0.1.6}/.idea/modules.xml +0 -0
  25. {xgae-0.1.4 → xgae-0.1.6}/.idea/vcs.xml +0 -0
  26. {xgae-0.1.4 → xgae-0.1.6}/.python-version +0 -0
  27. {xgae-0.1.4 → xgae-0.1.6}/README.md +0 -0
  28. {xgae-0.1.4 → xgae-0.1.6}/mcpservers/custom_servers.json +0 -0
  29. {xgae-0.1.4 → xgae-0.1.6}/mcpservers/xga_server.json +0 -0
  30. {xgae-0.1.4 → xgae-0.1.6}/src/xgae/__init__.py +0 -0
  31. {xgae-0.1.4 → xgae-0.1.6}/src/xgae/utils/json_helpers.py +0 -0
  32. {xgae-0.1.4 → xgae-0.1.6}/src/xgae/utils/llm_client.py +0 -0
  33. {xgae-0.1.4 → xgae-0.1.6}/templates/custom_tool_prompt_template.txt +0 -0
  34. {xgae-0.1.4 → xgae-0.1.6}/templates/gemini_system_prompt_template.txt +0 -0
  35. {xgae-0.1.4 → xgae-0.1.6}/templates/general_tool_prompt_template.txt +0 -0
  36. {xgae-0.1.4 → xgae-0.1.6}/templates/scp_test_prompt.txt +0 -0
  37. {xgae-0.1.4 → xgae-0.1.6}/templates/system_prompt_response_sample.txt +0 -0
  38. {xgae-0.1.4 → xgae-0.1.6}/templates/system_prompt_template.txt +0 -0
  39. {xgae-0.1.4 → xgae-0.1.6}/uv.lock +0 -0
@@ -3,5 +3,5 @@
3
3
  <component name="Black">
4
4
  <option name="sdkName" value="Python 3.13 (xgae)" />
5
5
  </component>
6
- <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 virtualenv at ~/DevProjects/xga/xgae/.venv" project-jdk-type="Python SDK" />
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 virtualenv at ~/DevelopSpace/xgae/.venv" project-jdk-type="Python SDK" />
7
7
  </project>
@@ -25,27 +25,26 @@
25
25
  <option name="hideEmptyMiddlePackages" value="true" />
26
26
  <option name="showLibraryContents" value="true" />
27
27
  </component>
28
- <component name="PropertiesComponent"><![CDATA[{
29
- "keyToString": {
30
- "ModuleVcsDetector.initialDetectionPerformed": "true",
31
- "Python.llm_client.executor": "Run",
32
- "Python.run_xga_engine.executor": "Run",
33
- "Python.setup_env.executor": "Run",
34
- "Python.utils.executor": "Run",
35
- "Python.xga_engine.executor": "Run",
36
- "Python.xga_mcp_tool_box.executor": "Debug",
37
- "Python.xga_prompt_builder.executor": "Debug",
38
- "RunOnceActivity.ShowReadmeOnStart": "true",
39
- "last_opened_file_path": "/Users/sharkystar/DevProjects/xga/xgae",
40
- "node.js.detected.package.eslint": "true",
41
- "node.js.detected.package.tslint": "true",
42
- "node.js.selected.package.eslint": "(autodetect)",
43
- "node.js.selected.package.tslint": "(autodetect)",
44
- "nodejs_package_manager_path": "npm",
45
- "settings.editor.selected.configurable": "com.intellij.pycharm.community.ide.impl.configuration.PythonContentEntriesConfigurable",
46
- "vue.rearranger.settings.migration": "true"
28
+ <component name="PropertiesComponent">{
29
+ &quot;keyToString&quot;: {
30
+ &quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
31
+ &quot;Python.llm_client.executor&quot;: &quot;Run&quot;,
32
+ &quot;Python.run_xga_engine.executor&quot;: &quot;Run&quot;,
33
+ &quot;Python.setup_env.executor&quot;: &quot;Run&quot;,
34
+ &quot;Python.utils.executor&quot;: &quot;Run&quot;,
35
+ &quot;Python.xga_engine.executor&quot;: &quot;Run&quot;,
36
+ &quot;Python.xga_mcp_tool_box.executor&quot;: &quot;Run&quot;,
37
+ &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
38
+ &quot;last_opened_file_path&quot;: &quot;/Users/goosezzy/DevelopSpace/xgae&quot;,
39
+ &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
40
+ &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
41
+ &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
42
+ &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
43
+ &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
44
+ &quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
45
+ &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
47
46
  }
48
- }]]></component>
47
+ }</component>
49
48
  <component name="RecentsManager">
50
49
  <key name="MoveFile.RECENT_KEYS">
51
50
  <recent name="$PROJECT_DIR$/src/xgae/engine/responser" />
@@ -61,7 +60,6 @@
61
60
  <env name="PYTHONUNBUFFERED" value="1" />
62
61
  </envs>
63
62
  <option name="SDK_HOME" value="" />
64
- <option name="SDK_NAME" value="Python 3.13 virtualenv at ~/DevProjects/xga/xgae/.venv" />
65
63
  <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
66
64
  <option name="IS_MODULE_SDK" value="false" />
67
65
  <option name="ADD_CONTENT_ROOTS" value="true" />
@@ -86,7 +84,7 @@
86
84
  <option name="INPUT_FILE" value="" />
87
85
  <method v="2" />
88
86
  </configuration>
89
- <configuration name="run_xga_engine" type="PythonConfigurationType" factoryName="Python">
87
+ <configuration name="run_xga_engine" type="PythonConfigurationType" factoryName="Python" temporary="true">
90
88
  <module name="xgae" />
91
89
  <option name="ENV_FILES" value="" />
92
90
  <option name="INTERPRETER_OPTIONS" value="" />
@@ -110,7 +108,7 @@
110
108
  <ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
111
109
  </ENTRIES>
112
110
  </EXTENSION>
113
- <option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/xgae/engine/xga_engine.py" />
111
+ <option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/xgae/engine/task_engine.py" />
114
112
  <option name="PARAMETERS" value="" />
115
113
  <option name="SHOW_COMMAND_LINE" value="false" />
116
114
  <option name="EMULATE_TERMINAL" value="false" />
@@ -119,6 +117,11 @@
119
117
  <option name="INPUT_FILE" value="" />
120
118
  <method v="2" />
121
119
  </configuration>
120
+ <recent_temporary>
121
+ <list>
122
+ <item itemvalue="Python.run_xga_engine" />
123
+ </list>
124
+ </recent_temporary>
122
125
  </component>
123
126
  <component name="SharedIndexes">
124
127
  <attachedChunks>
@@ -142,40 +145,46 @@
142
145
  <workItem from="1755270285722" duration="12068000" />
143
146
  <workItem from="1755283728206" duration="1511000" />
144
147
  <workItem from="1755286552901" duration="3130000" />
145
- <workItem from="1755409529770" duration="670000" />
146
- <workItem from="1755478595168" duration="20000" />
147
- <workItem from="1755479257156" duration="16895000" />
148
- <workItem from="1755525531052" duration="13030000" />
149
- <workItem from="1755585869510" duration="5796000" />
150
- <workItem from="1755593112104" duration="786000" />
151
- <workItem from="1755611972189" duration="13340000" />
152
- <workItem from="1755668525673" duration="14877000" />
153
- <workItem from="1755700523844" duration="24000" />
154
- <workItem from="1755737435202" duration="24716000" />
148
+ <workItem from="1755307767865" duration="337000" />
149
+ <workItem from="1755308113420" duration="2825000" />
150
+ <workItem from="1755321931380" duration="8531000" />
151
+ <workItem from="1755330830188" duration="229000" />
152
+ <workItem from="1755396985976" duration="6435000" />
153
+ <workItem from="1755415614018" duration="461000" />
154
+ <workItem from="1755416476555" duration="256000" />
155
+ <workItem from="1755419142521" duration="150000" />
156
+ <workItem from="1755429851003" duration="290000" />
157
+ <workItem from="1755430331676" duration="21000" />
158
+ <workItem from="1755529583730" duration="1643000" />
159
+ <workItem from="1755609955702" duration="37000" />
160
+ <workItem from="1755612319869" duration="621000" />
161
+ <workItem from="1755690345086" duration="6847000" />
162
+ <workItem from="1755781193226" duration="485000" />
163
+ <workItem from="1755781685826" duration="38000" />
164
+ <workItem from="1755781735460" duration="170000" />
165
+ <workItem from="1755817545372" duration="285000" />
166
+ <workItem from="1755862006389" duration="1051000" />
167
+ <workItem from="1755863094184" duration="553000" />
168
+ <workItem from="1755863979826" duration="4236000" />
169
+ <workItem from="1755875255916" duration="2308000" />
170
+ <workItem from="1755877576514" duration="2000" />
171
+ <workItem from="1755878805800" duration="3590000" />
172
+ <workItem from="1755904284653" duration="7803000" />
173
+ <workItem from="1755912586948" duration="1553000" />
174
+ <workItem from="1755915353109" duration="5872000" />
175
+ <workItem from="1755997335603" duration="7550000" />
155
176
  </task>
156
177
  <servers />
157
178
  </component>
158
179
  <component name="TypeScriptGeneratedFilesManager">
159
180
  <option name="version" value="3" />
160
181
  </component>
161
- <component name="XDebuggerManager">
162
- <breakpoint-manager>
163
- <default-breakpoints>
164
- <breakpoint type="python-exception">
165
- <properties notifyOnTerminate="true" exception="BaseException">
166
- <option name="notifyOnTerminate" value="true" />
167
- </properties>
168
- </breakpoint>
169
- </default-breakpoints>
170
- </breakpoint-manager>
171
- </component>
172
182
  <component name="com.intellij.coverage.CoverageDataManagerImpl">
173
- <SUITE FILE_PATH="coverage/xgae$xga_engine.coverage" NAME="xga_engine Coverage Results" MODIFIED="1755580277172" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
174
- <SUITE FILE_PATH="coverage/xgae$xga_prompt_builder.coverage" NAME="xga_prompt_builder Coverage Results" MODIFIED="1755587456555" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
175
- <SUITE FILE_PATH="coverage/xgae$run_xga_engine.coverage" NAME="run_xga_engine Coverage Results" MODIFIED="1755768463510" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
183
+ <SUITE FILE_PATH="coverage/xgae$xga_mcp_tool_box.coverage" NAME="xga_mcp_tool_box Coverage Results" MODIFIED="1755864064753" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
184
+ <SUITE FILE_PATH="coverage/xgae$llm_client.coverage" NAME="llm_client Coverage Results" MODIFIED="1755247632274" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
185
+ <SUITE FILE_PATH="coverage/xgae$setup_env.coverage" NAME="setup_env Coverage Results" MODIFIED="1755876041210" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
186
+ <SUITE FILE_PATH="coverage/xgae$run_xga_engine.coverage" NAME="run_xga_engine Coverage Results" MODIFIED="1756003050644" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
187
+ <SUITE FILE_PATH="coverage/xgae$xga_engine.coverage" NAME="xga_engine Coverage Results" MODIFIED="1755876180376" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
176
188
  <SUITE FILE_PATH="coverage/xgae$utils.coverage" NAME="utils Coverage Results" MODIFIED="1755226923439" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
177
- <SUITE FILE_PATH="coverage/xgae$setup_env.coverage" NAME="setup_env Coverage Results" MODIFIED="1755657717310" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
178
- <SUITE FILE_PATH="coverage/xgae$xga_mcp_tool_box.coverage" NAME="xga_mcp_tool_box Coverage Results" MODIFIED="1755583099719" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
179
- <SUITE FILE_PATH="coverage/xgae$llm_client.coverage" NAME="llm_client Coverage Results" MODIFIED="1755565705235" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
180
189
  </component>
181
190
  </project>
@@ -5,7 +5,7 @@
5
5
  <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
6
6
  <excludeFolder url="file://$MODULE_DIR$/.venv" />
7
7
  </content>
8
- <orderEntry type="jdk" jdkName="Python 3.13 virtualenv at ~/DevProjects/xga/xgae/.venv" jdkType="Python SDK" />
8
+ <orderEntry type="jdk" jdkName="Python 3.13 virtualenv at ~/DevelopSpace/xgae/.venv" jdkType="Python SDK" />
9
9
  <orderEntry type="sourceFolder" forTests="false" />
10
10
  </component>
11
11
  </module>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xgae
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Extreme General Agent Engine
5
5
  Requires-Python: >=3.13
6
6
  Requires-Dist: colorlog>=6.9.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xgae"
3
- version = "0.1.4"
3
+ version = "0.1.6"
4
4
  description = "Extreme General Agent Engine"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -6,24 +6,20 @@ class XGAError(Exception):
6
6
  """Custom exception for errors in the XGA system."""
7
7
  pass
8
8
 
9
+ XGAMsgStatusType = Literal["error", "finish", "tool_error", "tool_started", "tool_completed", "tool_failed", "thread_run_start", "thread_run_end", "assistant_response_start", "assistant_response_end"]
10
+ XGAResponseMsgType = Literal["user", "status", "tool", "assistant"]
9
11
 
10
- class XGAContextMsg(TypedDict, total=False):
11
- type: Literal["user", "status", "tool", "assistant", "assistant_response_end"]
12
- content: Union[Dict[str, Any], List[Any], str]
13
- is_llm_message: bool
14
- metadata: Dict[str, Any]
12
+ class XGAResponseMessage(TypedDict, total=False):
15
13
  message_id: str
16
- session_id: str
17
- agent_id: str
18
- task_id: str
19
- task_run_id: str
20
- trace_id: str
21
-
22
- class XGAResponseMsg(TypedDict, total=False):
23
- type: Literal["content", "status"]
14
+ type: XGAResponseMsgType
15
+ is_llm_message: bool
24
16
  content: Union[Dict[str, Any], List[Any], str]
25
- status: Literal["error", "status"]
26
- message: str
17
+ metadata: Dict[str, Any]
18
+
19
+ class XGATaskResult(TypedDict, total=False):
20
+ type: Literal["ask", "answer", "error"]
21
+ content: str
22
+ attachments: Optional[List[str]]
27
23
 
28
24
  @dataclass
29
25
  class XGAToolSchema:
@@ -39,6 +35,7 @@ class XGAToolResult:
39
35
  success: bool
40
36
  output: str
41
37
 
38
+
42
39
  class XGAToolBox(ABC):
43
40
  @abstractmethod
44
41
  async def creat_task_tool_box(self, task_id: str, general_tools: List[str], custom_tools: List[str]):
@@ -7,8 +7,8 @@ from typing import List, Any, Dict, Optional, Literal, override
7
7
  from langchain_mcp_adapters.client import MultiServerMCPClient
8
8
  from langchain_mcp_adapters.tools import load_mcp_tools
9
9
 
10
- from xgae.engine.xga_base import XGAError, XGAToolSchema, XGAToolBox, XGAToolResult
11
- from xgae.utils.setup_env import langfuse
10
+ from xgae.engine.engine_base import XGAError, XGAToolSchema, XGAToolBox, XGAToolResult
11
+ from xgae.utils import langfuse
12
12
 
13
13
  class XGAMcpToolBox(XGAToolBox):
14
14
  GENERAL_MCP_SERVER_NAME = "xga_general"
@@ -38,7 +38,7 @@ class XGAMcpToolBox(XGAToolBox):
38
38
  async def creat_task_tool_box(self, task_id: str, general_tools: List[str], custom_tools: List[str]):
39
39
  task_tool_schemas = {}
40
40
  general_tool_schemas = self.mcp_tool_schemas.get(XGAMcpToolBox.GENERAL_MCP_SERVER_NAME, {})
41
- if len(general_tools) > 0 and general_tools[0] == "*":
41
+ if "*" in general_tools:
42
42
  task_tool_schemas = {tool_schema.tool_name: tool_schema for tool_schema in general_tool_schemas}
43
43
  else:
44
44
  for tool_schema in general_tool_schemas:
@@ -58,8 +58,8 @@ class XGAMcpToolBox(XGAToolBox):
58
58
  if custom_tool_schemas is None:
59
59
  continue
60
60
  if custom_tool_name == "*":
61
- custom_tool_schema_d = {tool_schema.tool_name: tool_schema for tool_schema in custom_tool_schemas}
62
- task_tool_schemas.update(custom_tool_schema_d)
61
+ custom_tool_schema_dict = {tool_schema.tool_name: tool_schema for tool_schema in custom_tool_schemas}
62
+ task_tool_schemas.update(custom_tool_schema_dict)
63
63
  else:
64
64
  for tool_schema in custom_tool_schemas:
65
65
  if custom_tool_name == tool_schema.tool_name:
@@ -112,10 +112,7 @@ class XGAMcpToolBox(XGAToolBox):
112
112
  if mcp_tool:
113
113
  tool_args = args or {}
114
114
  if server_name == self.GENERAL_MCP_SERVER_NAME:
115
- pass
116
- #tool_args["task_id"] = task_id #xga general tool, first param must be task_id
117
- else:
118
- tool_args = args
115
+ tool_args = dict({"task_id": task_id}, **tool_args)
119
116
 
120
117
  try:
121
118
  tool_result = await mcp_tool.arun(tool_args)
@@ -1,9 +1,10 @@
1
1
  import json
2
2
  import datetime
3
+
3
4
  from typing import Optional, List
4
5
 
5
- from xga_base import XGAToolSchema, XGAError
6
- from xgae.utils.utils import read_file, format_file_with_args
6
+ from engine_base import XGAToolSchema, XGAError
7
+ from xgae.utils.misc import read_file, format_file_with_args
7
8
 
8
9
 
9
10
  class XGAPromptBuilder():
@@ -0,0 +1,110 @@
1
+ import logging
2
+
3
+ from typing import List, Dict, Any, AsyncGenerator, override,Optional
4
+
5
+ from xgae.engine.responser.responser_base import TaskResponseProcessor, TaskResponserContext, TaskRunContinuousState
6
+ from xgae.utils import langfuse
7
+ from xgae.utils.json_helpers import format_for_yield
8
+
9
+ class NonStreamTaskResponser(TaskResponseProcessor):
10
+ def __init__(self, response_context: TaskResponserContext):
11
+ super().__init__(response_context)
12
+
13
+ @override
14
+ async def process_response(self,llm_response: Any,prompt_messages: List[Dict[str, Any]],
15
+ continuous_state: Optional[TaskRunContinuousState] = None) -> AsyncGenerator[Dict[str, Any], None]:
16
+ llm_content = ""
17
+ parsed_xml_data = []
18
+ finish_reason = None
19
+
20
+ try:
21
+ # Extract finish_reason, content, tool calls
22
+ if hasattr(llm_response, 'choices') and llm_response.choices:
23
+ if hasattr(llm_response.choices[0], 'finish_reason'):
24
+ finish_reason = llm_response.choices[0].finish_reason
25
+ logging.info(f"NonStreamTask:LLM response finish_reason={finish_reason}")
26
+
27
+ langfuse.create_event(trace_context=self.trace_context, name="non_streaming_finish_reason", level="DEFAULT",
28
+ status_message=(f"Non-streaming finish_reason: {finish_reason}"))
29
+
30
+ response_message = llm_response.choices[0].message if hasattr(llm_response.choices[0], 'message') else None
31
+ if response_message:
32
+ if hasattr(response_message, 'content') and response_message.content:
33
+ llm_content = response_message.content
34
+
35
+ parsed_xml_data = self._parse_xml_tool_calls(llm_content)
36
+ if self.max_xml_tool_calls > 0 and len(parsed_xml_data) > self.max_xml_tool_calls:
37
+ logging.warning(f"NonStreamTask:Truncate content, parsed_xml_data length {len(parsed_xml_data)} limit over max_xml_tool_calls={self.max_xml_tool_calls}")
38
+ xml_chunks = self._extract_xml_chunks(llm_content)[:self.max_xml_tool_calls]
39
+ if xml_chunks:
40
+ last_chunk = xml_chunks[-1]
41
+ last_chunk_pos = llm_content.find(last_chunk)
42
+ if last_chunk_pos >= 0:
43
+ llm_content = llm_content[:last_chunk_pos + len(last_chunk)]
44
+ parsed_xml_data = parsed_xml_data[:self.max_xml_tool_calls]
45
+ finish_reason = "xml_tool_limit_reached"
46
+ logging.info(f"NonStreamTask:LLM response finish_reason={finish_reason}")
47
+ else:
48
+ logging.warning(f"NonStreamTask:LLM response_message is empty")
49
+
50
+ message_data = {"role": "assistant", "content": llm_content, "index": -1} # index=-1, full llm_content
51
+ assistant_msg = self.add_response_message(type="assistant", content=message_data, is_llm_message=True)
52
+ yield assistant_msg
53
+
54
+ tool_calls_to_execute = [item['tool_call'] for item in parsed_xml_data]
55
+ if len(tool_calls_to_execute) > 0:
56
+ logging.info(f"NonStreamTask:Executing {len(tool_calls_to_execute)} tools with strategy: {self.tool_execution_strategy}")
57
+ langfuse.create_event(trace_context=self.trace_context, name="executing_tools_with_strategy", level="DEFAULT", status_message=(
58
+ f"NonStreamTask Executing {len(tool_calls_to_execute)} tools with strategy: {self.tool_execution_strategy}"))
59
+
60
+ tool_results = await self._execute_tools(tool_calls_to_execute, self.tool_execution_strategy)
61
+
62
+ tool_index = 0
63
+ for i, (returned_tool_call, tool_result) in enumerate(tool_results):
64
+ parsed_xml_item = parsed_xml_data[i]
65
+ tool_call = parsed_xml_item['tool_call']
66
+ parsing_details = parsed_xml_item['parsing_details']
67
+ assistant_msg_id = assistant_msg['message_id'] if assistant_msg else None
68
+
69
+ tool_context = self._create_tool_context(tool_call, tool_index, assistant_msg_id, parsing_details)
70
+ tool_context.result = tool_result
71
+
72
+ tool_start_msg = self._add_tool_start_message(tool_context)
73
+ yield format_for_yield(tool_start_msg)
74
+
75
+ tool_message = self._add_tool_messsage(tool_call, tool_result, self.xml_adding_strategy, assistant_msg_id, parsing_details)
76
+
77
+ tool_completed_msg = self._add_tool_completed_message(tool_context, tool_message['message_id'])
78
+ yield format_for_yield(tool_completed_msg)
79
+
80
+ yield format_for_yield(tool_message)
81
+
82
+ if tool_completed_msg["metadata"].get("agent_should_terminate") == "true":
83
+ finish_reason = "completed"
84
+ break
85
+ tool_index += 1
86
+
87
+ if finish_reason:
88
+ finish_content = {"status_type": "finish", "finish_reason": finish_reason}
89
+ finish_msg_obj = self.add_response_message(type="status", content=finish_content, is_llm_message=False)
90
+ if finish_msg_obj:
91
+ yield format_for_yield(finish_msg_obj)
92
+
93
+ except Exception as e:
94
+ logging.error(f"NonStreamTask: Error processing non-streaming response: {llm_content}")
95
+ langfuse.create_event(trace_context=self.trace_context, name="error_processing_non_streaming_response", level="ERROR",
96
+ status_message=(f"Error processing non-streaming response: {str(e)}"))
97
+
98
+ content = {"role": "system", "status_type": "error", "message": str(e)}
99
+ err_msg = self.add_response_message(ype="status", content=content,is_llm_message=False)
100
+ if err_msg:
101
+ yield format_for_yield(err_msg)
102
+
103
+ # Re-raise the same exception (not a new one) to ensure proper error propagation
104
+ logging.critical(f"NonStreamTask: Re-raising error to stop further processing: {str(e)}")
105
+ langfuse.create_event(trace_context=self.trace_context, name="re_raising_error_to_stop_further_processing", level="CRITICAL",
106
+ status_message=(f"Re-raising error to stop further processing: {str(e)}"))
107
+ raise # Use bare 'raise' to preserve the original exception with its traceback
108
+
109
+
110
+