xgae 0.1.5__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.
- {xgae-0.1.5 → xgae-0.1.6}/.idea/misc.xml +1 -1
- {xgae-0.1.5 → xgae-0.1.6}/.idea/workspace.xml +59 -50
- {xgae-0.1.5 → xgae-0.1.6}/.idea/xgae.iml +1 -1
- {xgae-0.1.5 → xgae-0.1.6}/PKG-INFO +1 -1
- {xgae-0.1.5 → xgae-0.1.6}/pyproject.toml +1 -1
- xgae-0.1.5/src/xgae/engine/xga_base.py → xgae-0.1.6/src/xgae/engine/engine_base.py +6 -9
- xgae-0.1.5/src/xgae/engine/xga_mcp_tool_box.py → xgae-0.1.6/src/xgae/engine/mcp_tool_box.py +5 -5
- xgae-0.1.5/src/xgae/engine/xga_prompt_builder.py → xgae-0.1.6/src/xgae/engine/prompt_builder.py +3 -2
- xgae-0.1.6/src/xgae/engine/responser/non_stream_responser.py +110 -0
- xgae-0.1.5/src/xgae/engine/responser/xga_responser_base.py → xgae-0.1.6/src/xgae/engine/responser/responser_base.py +102 -186
- xgae-0.1.5/src/xgae/engine/responser/xga_stream_responser.py → xgae-0.1.6/src/xgae/engine/responser/stream_responser.py +51 -55
- xgae-0.1.5/src/xgae/engine/xga_engine.py → xgae-0.1.6/src/xgae/engine/task_engine.py +86 -73
- xgae-0.1.6/src/xgae/utils/__init__.py +13 -0
- xgae-0.1.5/src/xgae/utils/utils.py → xgae-0.1.6/src/xgae/utils/misc.py +0 -8
- xgae-0.1.6/src/xgae/utils/setup_env.py +78 -0
- {xgae-0.1.5 → xgae-0.1.6}/src/xgae/utils/xml_tool_parser.py +4 -7
- xgae-0.1.5/src/xgae/engine/responser/xga_non_stream_responser.py +0 -216
- xgae-0.1.5/src/xgae/utils/setup_env.py +0 -93
- {xgae-0.1.5 → xgae-0.1.6}/.env +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/.idea/.gitignore +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/.idea/inspectionProfiles/Project_Default.xml +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/.idea/modules.xml +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/.idea/vcs.xml +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/.python-version +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/README.md +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/mcpservers/custom_servers.json +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/mcpservers/xga_server.json +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/src/xgae/__init__.py +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/src/xgae/utils/json_helpers.py +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/src/xgae/utils/llm_client.py +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/templates/custom_tool_prompt_template.txt +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/templates/gemini_system_prompt_template.txt +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/templates/general_tool_prompt_template.txt +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/templates/scp_test_prompt.txt +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/templates/system_prompt_response_sample.txt +0 -0
- {xgae-0.1.5 → xgae-0.1.6}/templates/system_prompt_template.txt +0 -0
- {xgae-0.1.5 → 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 ~/
|
|
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"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"vue.rearranger.settings.migration": "true"
|
|
28
|
+
<component name="PropertiesComponent">{
|
|
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": "Run",
|
|
37
|
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
38
|
+
"last_opened_file_path": "/Users/goosezzy/DevelopSpace/xgae",
|
|
39
|
+
"node.js.detected.package.eslint": "true",
|
|
40
|
+
"node.js.detected.package.tslint": "true",
|
|
41
|
+
"node.js.selected.package.eslint": "(autodetect)",
|
|
42
|
+
"node.js.selected.package.tslint": "(autodetect)",
|
|
43
|
+
"nodejs_package_manager_path": "npm",
|
|
44
|
+
"settings.editor.selected.configurable": "preferences.pluginManager",
|
|
45
|
+
"vue.rearranger.settings.migration": "true"
|
|
47
46
|
}
|
|
48
|
-
}
|
|
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/
|
|
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="
|
|
146
|
-
<workItem from="
|
|
147
|
-
<workItem from="
|
|
148
|
-
<workItem from="
|
|
149
|
-
<workItem from="
|
|
150
|
-
<workItem from="
|
|
151
|
-
<workItem from="
|
|
152
|
-
<workItem from="
|
|
153
|
-
<workItem from="
|
|
154
|
-
<workItem from="
|
|
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$
|
|
174
|
-
<SUITE FILE_PATH="coverage/xgae$
|
|
175
|
-
<SUITE FILE_PATH="coverage/xgae$
|
|
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 ~/
|
|
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>
|
|
@@ -6,18 +6,15 @@ 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
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
class XGAResponseMessage(TypedDict, total=False):
|
|
13
|
+
message_id: str
|
|
14
|
+
type: XGAResponseMsgType
|
|
13
15
|
is_llm_message: bool
|
|
16
|
+
content: Union[Dict[str, Any], List[Any], str]
|
|
14
17
|
metadata: Dict[str, Any]
|
|
15
|
-
message_id: str
|
|
16
|
-
task_id: str
|
|
17
|
-
task_run_id: str
|
|
18
|
-
trace_id: str
|
|
19
|
-
session_id: Optional[str]
|
|
20
|
-
agent_id: Optional[str]
|
|
21
18
|
|
|
22
19
|
class XGATaskResult(TypedDict, total=False):
|
|
23
20
|
type: Literal["ask", "answer", "error"]
|
|
@@ -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.
|
|
11
|
-
from xgae.utils
|
|
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
|
|
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
|
-
|
|
62
|
-
task_tool_schemas.update(
|
|
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:
|
xgae-0.1.5/src/xgae/engine/xga_prompt_builder.py → xgae-0.1.6/src/xgae/engine/prompt_builder.py
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import datetime
|
|
3
|
+
|
|
3
4
|
from typing import Optional, List
|
|
4
5
|
|
|
5
|
-
from
|
|
6
|
-
from xgae.utils.
|
|
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
|
+
|