xgae 0.1.20__tar.gz → 0.4.1__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.
- {xgae-0.1.20 → xgae-0.4.1}/.env +2 -1
- xgae-0.4.1/CHANGELOG.md +140 -0
- xgae-0.4.1/PKG-INFO +50 -0
- xgae-0.4.1/README.md +34 -0
- xgae-0.4.1/examples/agent/are/README.md +56 -0
- xgae-0.4.1/examples/agent/are/are/simulation/agents/xga/are_agent.py +307 -0
- xgae-0.4.1/examples/agent/are/are/simulation/agents/xga/are_agent_factory.py +42 -0
- xgae-0.4.1/examples/agent/are/are/simulation/agents/xga/are_prompt_builder.py +27 -0
- xgae-0.4.1/examples/agent/are/are/simulation/agents/xga/are_tool_box.py +87 -0
- xgae-0.4.1/examples/agent/are/are/simulation/agents/xga/mcp_tool_executor.py +134 -0
- xgae-0.4.1/examples/agent/are/are/simulation/scenarios/scenario_bomc_fault/scenario.py +184 -0
- xgae-0.4.1/examples/agent/are/are_modify_ref.zip +0 -0
- xgae-0.4.1/examples/agent/are/env.example +43 -0
- xgae-0.4.1/examples/agent/are/mcpservers/example_mcp_apps.json +11 -0
- xgae-0.4.1/examples/agent/are/templates/are_prompt_template.md +57 -0
- xgae-0.4.1/examples/agent/are/templates/system_prompt_template.md +282 -0
- {xgae-0.1.20/src/examples/agent/langgraph/react → xgae-0.4.1/examples/agent/langgraph/reflection}/agent_base.py +4 -2
- xgae-0.4.1/examples/agent/langgraph/reflection/custom_prompt_rag.py +108 -0
- xgae-0.1.20/src/examples/agent/langgraph/react/react_agent.py → xgae-0.4.1/examples/agent/langgraph/reflection/reflection_agent.py +123 -42
- xgae-0.1.20/src/examples/agent/langgraph/react/final_result_agent.py → xgae-0.4.1/examples/agent/langgraph/reflection/result_eval_agent.py +16 -9
- xgae-0.1.20/src/examples/agent/langgraph/react/run_react_agent.py → xgae-0.4.1/examples/agent/langgraph/reflection/run_agent_app.py +4 -4
- xgae-0.4.1/examples/engine/run_custom_and_agent_tools.py +60 -0
- xgae-0.4.1/examples/engine/run_general_tools.py +42 -0
- {xgae-0.1.20/src → xgae-0.4.1}/examples/engine/run_human_in_loop.py +2 -2
- {xgae-0.1.20/src → xgae-0.4.1}/examples/tools/custom_fault_tools_app.py +4 -2
- {xgae-0.1.20/src → xgae-0.4.1}/examples/tools/simu_a2a_tools_app.py +6 -0
- {xgae-0.1.20 → xgae-0.4.1}/pyproject.toml +17 -9
- xgae-0.1.20/templates/example/fault_user_prompt.txt → xgae-0.4.1/templates/example/fault_user_prompt.md +6 -5
- xgae-0.1.20/templates/example/final_result_template.txt → xgae-0.4.1/templates/example/result_eval_template.txt +10 -5
- xgae-0.1.20/templates/system_prompt_template.txt → xgae-0.4.1/templates/general_prompt_template.md +98 -14
- xgae-0.4.1/templates/system_prompt_template.md +282 -0
- xgae-0.4.1/test/test_chroma.py +31 -0
- xgae-0.4.1/tool.md +64 -0
- xgae-0.4.1/uv.lock +3250 -0
- xgae-0.1.20/mcpservers/custom_servers.json → xgae-0.4.1/xga_mcp_servers.json +7 -3
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/engine/engine_base.py +7 -2
- xgae-0.4.1/xgae/engine/mcp_tool_box.py +313 -0
- xgae-0.4.1/xgae/engine/prompt_builder.py +166 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/engine/responser/non_stream_responser.py +2 -1
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/engine/responser/stream_responser.py +3 -2
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/engine/task_engine.py +59 -20
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/engine_cli_app.py +3 -4
- xgae-0.4.1/xgae/gaia2/are_engine.py +126 -0
- xgae-0.4.1/xgae/tools/system_tools.py +116 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/utils/llm_client.py +90 -30
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/utils/xml_tool_parser.py +14 -3
- xgae-0.1.20/CHANGELOG.md +0 -50
- xgae-0.1.20/PKG-INFO +0 -12
- xgae-0.1.20/README.md +0 -0
- xgae-0.1.20/mcpservers/xga_server.json +0 -11
- xgae-0.1.20/mcpservers/xga_server_sse.json +0 -8
- xgae-0.1.20/src/examples/engine/run_custom_and_agent_tools.py +0 -45
- xgae-0.1.20/src/examples/engine/run_general_tools.py +0 -16
- xgae-0.1.20/src/xgae/engine/mcp_tool_box.py +0 -241
- xgae-0.1.20/src/xgae/engine/prompt_builder.py +0 -113
- xgae-0.1.20/src/xgae/tools/without_general_tools_app.py +0 -50
- xgae-0.1.20/templates/agent_tool_prompt_template.txt +0 -29
- xgae-0.1.20/templates/custom_tool_prompt_template.txt +0 -25
- xgae-0.1.20/templates/gemini_system_prompt_template.txt +0 -1742
- xgae-0.1.20/templates/general_tool_prompt_template.txt +0 -25
- xgae-0.1.20/templates/system_prompt_response_sample.txt +0 -1252
- xgae-0.1.20/uv.lock +0 -1463
- {xgae-0.1.20 → xgae-0.4.1}/.python-version +0 -0
- {xgae-0.1.20/src → xgae-0.4.1}/examples/engine/run_simple.py +0 -0
- {xgae-0.1.20 → xgae-0.4.1}/test/test_langfuse.py +0 -0
- {xgae-0.1.20 → xgae-0.4.1}/test/test_litellm_langfuse.py +0 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/__init__.py +0 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/engine/responser/responser_base.py +0 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/engine/task_langfuse.py +0 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/utils/__init__.py +0 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/utils/json_helpers.py +0 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/utils/misc.py +0 -0
- {xgae-0.1.20/src → xgae-0.4.1}/xgae/utils/setup_env.py +0 -0
{xgae-0.1.20 → xgae-0.4.1}/.env
RENAMED
|
@@ -12,6 +12,7 @@ LANGFUSE_HOST=https://cloud.langfuse.com
|
|
|
12
12
|
|
|
13
13
|
# LLM
|
|
14
14
|
LLM_MODEL=openai/qwen3-235b-a22b
|
|
15
|
+
#LLM_MODEL=openai/qwen3-4b
|
|
15
16
|
LLM_API_BASE=https://dashscope.aliyuncs.com/compatible-mode/v1
|
|
16
17
|
LLM_API_KEY=
|
|
17
18
|
LLM_MAX_TOKENS=16384
|
|
@@ -20,7 +21,7 @@ LLM_MAX_RETRIES=1
|
|
|
20
21
|
LLM_STREAM=True
|
|
21
22
|
LLM_ENABLE_THINKING=False
|
|
22
23
|
|
|
23
|
-
LLM_LANGFUSE_ENABLE=
|
|
24
|
+
LLM_LANGFUSE_ENABLE=True
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
# TASK_ENGINE
|
xgae-0.4.1/CHANGELOG.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
## [0.4.1] - 2025-11-15
|
|
2
|
+
### Modified
|
|
3
|
+
- XGATaskEngine : Fix Bug, allow 'no tool call' occur, after LLM summary, will call 'complete'
|
|
4
|
+
- general_prompt_template: Optimize prompt template
|
|
5
|
+
- engine examples update with more clear example, show how to use General Agent and Custom Agent on different scenario
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## [0.4.0] - 2025-11-11
|
|
9
|
+
- ✅ Overall Refact
|
|
10
|
+
### Added
|
|
11
|
+
- LLMClient : Add 'completion' sync LLM call function
|
|
12
|
+
- XGASystemTools: Use local system tools, abandoned 'stdio' mode MCP system tool
|
|
13
|
+
### Modified
|
|
14
|
+
- XGAMcpToolBox: Separate 'system_tool' from ’general_tool'
|
|
15
|
+
- XGAPromptBuilder: Support two model system_prompt, distinguish between 'system' and 'general' mode
|
|
16
|
+
- templates: Merge tool prompt template with system prompt template, Remove unclear template
|
|
17
|
+
- XGA MCP Server Config: all merge to xga_mcp_servers.json
|
|
18
|
+
- GAIA2 ARE Example: Refact with xgae engine new version
|
|
19
|
+
- All Examples modified by xgae engine new version
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [0.3.10] - 2025-11-6
|
|
23
|
+
### Modified
|
|
24
|
+
- XMLToolParser : Fix Bug, when string like '+2478' will convert to int
|
|
25
|
+
- GAIA2 ARE Example XGAAreToolBox: Fix Bug, ARE tool use full tool name
|
|
26
|
+
- GAIA2 ARE Example XGAAreAgent: Fix Bug, add ObservationLog log
|
|
27
|
+
- GAIA2 ARE Example are_agent_factory : Fix Bug, add xga_termination_step, avoid exit on calling wait_for_notification tool
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [0.3.9] - 2025-11-4
|
|
31
|
+
### Added
|
|
32
|
+
- ✅ GAIA2 ARE Example: Add new prompt template, Leading over ARE 'default agent'
|
|
33
|
+
### Modified
|
|
34
|
+
- GAIA2 ARE Example: Refact prompt templates, use MD format
|
|
35
|
+
- GAIA2 ARE Example: XGAArePromptBuilder add 'prior' template mode
|
|
36
|
+
- ARE Engine: remove useless 'system_prompt' init parameter
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## [0.3.5] - 2025-11-1
|
|
40
|
+
### Added
|
|
41
|
+
- GAIA2 ARE Example: XGAArePromptBuilder, Use MCP tool format general tool construct prompt
|
|
42
|
+
### Modified
|
|
43
|
+
- GAIA2 ARE Example: Refact code struct and class name
|
|
44
|
+
- GAIA2 ARE Example: Optimize prompt template
|
|
45
|
+
- ARETaskEngine: add prompt_builder init parameter
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## [0.3.3] - 2025-10-30
|
|
49
|
+
### Added
|
|
50
|
+
- GAIA2 ARE Scenario: scenario_bomc_fault
|
|
51
|
+
- GAIA2 ARE MCP: Support Custom MCP Apps, example_mcp_apps.json
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## [0.3.2] - 2025-10-24
|
|
55
|
+
### Added
|
|
56
|
+
- GAIA2 ARE Example: XGAAreAgent, XGAAreToolBox
|
|
57
|
+
### Modified
|
|
58
|
+
- ARETaskEngine
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## [0.3.0] - 2025-10-22
|
|
62
|
+
### Added
|
|
63
|
+
- Support GAIA2 ARE: ARETaskEngine
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## [0.2.4] - 2025-9-23
|
|
67
|
+
### Modified
|
|
68
|
+
- Refact project structure
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## [0.2.3] - 2025-9-19
|
|
72
|
+
### Modified
|
|
73
|
+
- CustomPromptRag: remove FastEmbedEmbeddings, use 'text-embedding-v3' model for chinese, avoid download 'bge-small-zh-v1.5'
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## [0.2.1] - 2025-9-17
|
|
77
|
+
### Added
|
|
78
|
+
- Example ReflectionAgent: add CustomPromptRag, use FastEmbedEmbeddings and 'BAAI/bge-small-zh-v1.5' model
|
|
79
|
+
### Modified
|
|
80
|
+
- pyproject.toml: add [project.optional-dependencies] 'examples'
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## [0.2.0] - 2025-9-10
|
|
84
|
+
### Added
|
|
85
|
+
- Agent Engine release 0.2
|
|
86
|
+
- Example: Langgraph ReflectionAgent release 0.2
|
|
87
|
+
### Fixed
|
|
88
|
+
- Agent Engine: call mcp tool fail, call 'ask' tool again and again
|
|
89
|
+
- Example Langgraph ReflectionAgent: retry on 'ask', user_input is ask answer
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
## [0.1.20] - 2025-9-9
|
|
93
|
+
### Added
|
|
94
|
+
- Example: Langgraph ReflectionAgent add final_result_agent
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## [0.1.19] - 2025-9-8
|
|
98
|
+
### Added
|
|
99
|
+
- Example: Langgraph ReflectionAgent release V1, full logic but no final result agent and tool select agent
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# Release Changelog
|
|
103
|
+
## [0.1.18] - 2025-9-3
|
|
104
|
+
### Added
|
|
105
|
+
- Support Agent tools
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## [0.1.17] - 2025-9-1
|
|
109
|
+
### Target
|
|
110
|
+
- Saved for XGATaskEngine base version
|
|
111
|
+
### Changed
|
|
112
|
+
- Delete StreamTaskResponser tool_exec_on_stream model code
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
## [0.1.15] - 2025-9-1
|
|
116
|
+
### Target
|
|
117
|
+
- Saved for StreamResponser tool_exec_on_stream mode, next release will be abolished
|
|
118
|
+
### Changed
|
|
119
|
+
- Refact TaskResponseProcessor, XGATaskEngine
|
|
120
|
+
### Fixed
|
|
121
|
+
- Fix finish_reason judge logic
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
## [0.1.14] - 2025-8-31
|
|
125
|
+
### Target
|
|
126
|
+
- First complete version is merged
|
|
127
|
+
### Changed
|
|
128
|
+
- StreamTaskResponser first version
|
|
129
|
+
|
|
130
|
+
## [0.1.10] - 2025-8-28
|
|
131
|
+
### Target
|
|
132
|
+
- NonStream mode release is completed
|
|
133
|
+
### Changed
|
|
134
|
+
- StreamTaskResponser is original
|
|
135
|
+
- NonStreamTaskResponser first version is completed
|
|
136
|
+
- Langfuse use 2.x, match for LiteLLM package
|
|
137
|
+
|
|
138
|
+
## [0.1.7] - 2025-8-25
|
|
139
|
+
### Target
|
|
140
|
+
- Langfuse use 3.x package
|
xgae-0.4.1/PKG-INFO
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xgae
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Extreme General Agent Engine
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: colorlog>=6.9.0
|
|
7
|
+
Requires-Dist: langchain-mcp-adapters>=0.1.9
|
|
8
|
+
Requires-Dist: langfuse==2.60.9
|
|
9
|
+
Requires-Dist: litellm>=1.71.1
|
|
10
|
+
Requires-Dist: mcp>=1.11.0
|
|
11
|
+
Provides-Extra: examples
|
|
12
|
+
Requires-Dist: chromadb==1.1.0; extra == 'examples'
|
|
13
|
+
Requires-Dist: langchain-community==0.3.29; extra == 'examples'
|
|
14
|
+
Requires-Dist: langgraph==0.6.5; extra == 'examples'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# XGAE: Extreme General Agent Engine
|
|
18
|
+
## XGAE Features
|
|
19
|
+
### Functional Features
|
|
20
|
+
- Support Custom prompt and external MCP Tools
|
|
21
|
+
- Support Langfuse
|
|
22
|
+
- Support Langgraph
|
|
23
|
+
- Support GAIA2 ARE agent and Custom MCP Apps, Leading over ARE 'default agent'
|
|
24
|
+
- Support Human-in-Loop in agent
|
|
25
|
+
- Can Use A2A protocol call A2A Agent as tool by 'xgaproxy' project
|
|
26
|
+
- Can Use E2B or Daytona Sandbox of 'xgatools' project
|
|
27
|
+
|
|
28
|
+
### Non-Functional Features
|
|
29
|
+
- Faster than SUNA Engine's speed
|
|
30
|
+
- Architecture is lighter than SUNA Engine
|
|
31
|
+
- Separate tools from Agent Engine
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## XGAE Run Mode
|
|
35
|
+
### General Agent
|
|
36
|
+
- Use General Agent Prompt
|
|
37
|
+
- Use general tools mainly
|
|
38
|
+
- In addition to using general tools, custom tools can also be used
|
|
39
|
+
|
|
40
|
+
### Custom Agent
|
|
41
|
+
- Use User Custom Prompt
|
|
42
|
+
- Use custom tools mainly
|
|
43
|
+
- Some general tools can also be used, like 'web_search'
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
- engine: Use XGA Engine in various scenarios, you can find out how to use General or Custom Agent
|
|
48
|
+
- langgraph: Build React mode Langgraph Agent by XGA Engine
|
|
49
|
+
- are: Build GAIA2 ARE Agent by XGA Engine
|
|
50
|
+
- tools: Simulation tools for example and test
|
xgae-0.4.1/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# XGAE: Extreme General Agent Engine
|
|
2
|
+
## XGAE Features
|
|
3
|
+
### Functional Features
|
|
4
|
+
- Support Custom prompt and external MCP Tools
|
|
5
|
+
- Support Langfuse
|
|
6
|
+
- Support Langgraph
|
|
7
|
+
- Support GAIA2 ARE agent and Custom MCP Apps, Leading over ARE 'default agent'
|
|
8
|
+
- Support Human-in-Loop in agent
|
|
9
|
+
- Can Use A2A protocol call A2A Agent as tool by 'xgaproxy' project
|
|
10
|
+
- Can Use E2B or Daytona Sandbox of 'xgatools' project
|
|
11
|
+
|
|
12
|
+
### Non-Functional Features
|
|
13
|
+
- Faster than SUNA Engine's speed
|
|
14
|
+
- Architecture is lighter than SUNA Engine
|
|
15
|
+
- Separate tools from Agent Engine
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## XGAE Run Mode
|
|
19
|
+
### General Agent
|
|
20
|
+
- Use General Agent Prompt
|
|
21
|
+
- Use general tools mainly
|
|
22
|
+
- In addition to using general tools, custom tools can also be used
|
|
23
|
+
|
|
24
|
+
### Custom Agent
|
|
25
|
+
- Use User Custom Prompt
|
|
26
|
+
- Use custom tools mainly
|
|
27
|
+
- Some general tools can also be used, like 'web_search'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Examples
|
|
31
|
+
- engine: Use XGA Engine in various scenarios, you can find out how to use General or Custom Agent
|
|
32
|
+
- langgraph: Build React mode Langgraph Agent by XGA Engine
|
|
33
|
+
- are: Build GAIA2 ARE Agent by XGA Engine
|
|
34
|
+
- tools: Simulation tools for example and test
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
## GAIA2 ARE Support
|
|
2
|
+
### How to add XGAE to ARE Project
|
|
3
|
+
- add xgae==0.3.x to ARE requirements.txt
|
|
4
|
+
- uv pip install -r requirements.txt
|
|
5
|
+
- Modify ARE 'AgentBuilder' and 'AgentConfigBuilder' class, add "xga" type agent :
|
|
6
|
+
```
|
|
7
|
+
File: agent_builder.py
|
|
8
|
+
class AgentBuilder:
|
|
9
|
+
def list_agents(self) -> list[str]:
|
|
10
|
+
return ["default", "xga"]
|
|
11
|
+
|
|
12
|
+
def build():
|
|
13
|
+
...
|
|
14
|
+
agent_name = agent_config.get_agent_name()
|
|
15
|
+
if agent_name in ["default", "xga"]:
|
|
16
|
+
# add xga agent code
|
|
17
|
+
|
|
18
|
+
File: agent_config_builder.py
|
|
19
|
+
class AgentConfigBuilder:
|
|
20
|
+
def build():
|
|
21
|
+
if agent_name in["default", "xga"]:
|
|
22
|
+
```
|
|
23
|
+
- Modify ARE 'MCPApp' :
|
|
24
|
+
```
|
|
25
|
+
File: mcp_app.py
|
|
26
|
+
class MCPApp:
|
|
27
|
+
def _call_tool(self, tool_name: str, **kwargs) -> str:
|
|
28
|
+
try:
|
|
29
|
+
...
|
|
30
|
+
# original code don't support async engine loop
|
|
31
|
+
from are.simulation.agents.xga.mcp_tool_executor import call_mcp_tool
|
|
32
|
+
result = call_mcp_tool(self.server_url, tool_name, kwargs, 10)
|
|
33
|
+
return str(result)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
- Modify ARE .env, add XGAE .env config, refer to env.example
|
|
38
|
+
- Copy XGAE package 'templates' directory to ARE project root
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Run XGA Agent in ARE
|
|
42
|
+
```
|
|
43
|
+
# Run ARE Code Scenario
|
|
44
|
+
uv run are-run -e -s scenario_apps_tutorial -a xga --model openai/qwen3-235b-a22b --provider llama-api --output_dir ./output --log-level INFO
|
|
45
|
+
|
|
46
|
+
# Run Custom Scenario
|
|
47
|
+
uv run example-fault-tools
|
|
48
|
+
uv run are-run -e -s scenario_bomc_fault -a xga --model openai/qwen3-235b-a22b --provider llama-api --output_dir ./output --log-level INFO
|
|
49
|
+
|
|
50
|
+
# Run HF Scenario Benchmark
|
|
51
|
+
uv run are-benchmark run -a xga --dataset ./scenarios --config mini --model openai/deepseek-v3.1 --provider llama-api --output_dir ./output --limit 1 --num_runs 1 --max_concurrent_scenarios 1 --log-level INFO
|
|
52
|
+
|
|
53
|
+
# Run GUI
|
|
54
|
+
uv run are-gui -a xga -s scenario_find_image_file --model openai/qwen3-235b-a22b --provider llama-api --log-level INFO
|
|
55
|
+
|
|
56
|
+
```
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import asyncio
|
|
3
|
+
from typing import List, Dict, Any
|
|
4
|
+
|
|
5
|
+
from mammoth.results import success
|
|
6
|
+
from typing_extensions import override
|
|
7
|
+
|
|
8
|
+
from are.simulation.agents.are_simulation_agent import AgentStoppedException
|
|
9
|
+
from are.simulation.agents.llm.types import MMObservation
|
|
10
|
+
from are.simulation.agents.multimodal import Attachment, attachments_to_pil
|
|
11
|
+
from are.simulation.agents.agent_log import (
|
|
12
|
+
LLMInputLog,
|
|
13
|
+
LLMOutputThoughtActionLog,
|
|
14
|
+
StepLog,
|
|
15
|
+
StopLog,
|
|
16
|
+
SystemPromptLog,
|
|
17
|
+
ThoughtLog,
|
|
18
|
+
ToolCallLog,
|
|
19
|
+
FinalAnswerLog,
|
|
20
|
+
ObservationLog,
|
|
21
|
+
ErrorLog
|
|
22
|
+
)
|
|
23
|
+
from are.simulation.agents.default_agent.base_agent import (
|
|
24
|
+
BaseAgent,
|
|
25
|
+
RunningState,
|
|
26
|
+
get_offset_from_time_config_mode
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from xgae.utils.llm_client import LLMConfig
|
|
30
|
+
from xgae.gaia2.are_engine import ARETaskEngine
|
|
31
|
+
from are.simulation.agents.xga.are_tool_box import XGAAreToolBox
|
|
32
|
+
from are.simulation.agents.xga.are_prompt_builder import XGAArePromptBuilder
|
|
33
|
+
|
|
34
|
+
def pre_run_task_check(agent, iterations: int, llm_messages: List[Dict[str, Any]]):
|
|
35
|
+
try:
|
|
36
|
+
agent.logger.info(f"\n\n------ Starting Run Task Iteration {iterations}... ------")
|
|
37
|
+
|
|
38
|
+
if iterations == 0:
|
|
39
|
+
agent.system_prompt = agent.task_engine.task_prompt
|
|
40
|
+
agent.logger.info(f"------ SYSTEM_PROMPT ------ \n{agent.system_prompt}\n")
|
|
41
|
+
agent.append_agent_log(
|
|
42
|
+
SystemPromptLog(
|
|
43
|
+
content = agent.system_prompt,
|
|
44
|
+
timestamp = agent.make_timestamp(),
|
|
45
|
+
agent_id = agent.agent_id,
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
agent.append_agent_log(
|
|
50
|
+
StepLog(
|
|
51
|
+
iteration = agent.iterations,
|
|
52
|
+
timestamp = agent.make_timestamp(),
|
|
53
|
+
agent_id = agent.agent_id,
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
if agent.stop_event.is_set():
|
|
58
|
+
agent.logger.info(f"pre_run_task_check[{iterations}]: Recv Stop Event before condition, raise AgentStoppedException")
|
|
59
|
+
raise AgentStoppedException("Agent stopped.")
|
|
60
|
+
|
|
61
|
+
# Execute a pre_step() function if it exists
|
|
62
|
+
for conditional_step in agent.conditional_pre_steps:
|
|
63
|
+
if conditional_step.condition is None or conditional_step.condition(agent):
|
|
64
|
+
conditional_step.function(agent)
|
|
65
|
+
|
|
66
|
+
if agent.stop_event.is_set():
|
|
67
|
+
agent.logger.info(f"pre_run_task_check[{iterations}]: Recv Stop Event after condition, raise AgentStoppedException")
|
|
68
|
+
raise AgentStoppedException("Agent stopped.")
|
|
69
|
+
|
|
70
|
+
# Begin step()
|
|
71
|
+
agent.build_history_from_logs(
|
|
72
|
+
exclude_log_types=["tool_call", "rationale", "action"]
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
agent.append_agent_log(
|
|
76
|
+
LLMInputLog(
|
|
77
|
+
content = llm_messages,
|
|
78
|
+
timestamp = agent.make_timestamp(),
|
|
79
|
+
agent_id = agent.agent_id
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
if agent.simulated_generation_time_config is not None:
|
|
84
|
+
if agent.pause_env is None:
|
|
85
|
+
raise ValueError("pause_env is not set")
|
|
86
|
+
agent.pause_env()
|
|
87
|
+
except Exception as e:
|
|
88
|
+
agent.log_error(e)
|
|
89
|
+
agent.logger.info(f"pre_run_task_check[{iterations}]: Exception Occur, Stop task")
|
|
90
|
+
agent.task_engine.stop_task()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def post_run_task_check(agent, iterations: int, llm_response: Dict[str, Any]):
|
|
94
|
+
try:
|
|
95
|
+
agent.logger.info(f"------ LLM Response Iteration [{iterations}] ------ \n{llm_response}\n")
|
|
96
|
+
|
|
97
|
+
llm_output = str(llm_response)
|
|
98
|
+
|
|
99
|
+
# Resume the environment after the generation of a thought/action if needed
|
|
100
|
+
if agent.simulated_generation_time_config is not None:
|
|
101
|
+
if agent.resume_env is None:
|
|
102
|
+
raise ValueError("resume_env is not set")
|
|
103
|
+
|
|
104
|
+
offset = get_offset_from_time_config_mode(
|
|
105
|
+
time_config = agent.simulated_generation_time_config,
|
|
106
|
+
completion_duration = 0,
|
|
107
|
+
)
|
|
108
|
+
agent.logger.info(f"post_run_task_check[{iterations}]: Resuming environment with {offset} offset")
|
|
109
|
+
agent.resume_env(offset)
|
|
110
|
+
|
|
111
|
+
metadata = {}
|
|
112
|
+
agent.append_agent_log(
|
|
113
|
+
LLMOutputThoughtActionLog(
|
|
114
|
+
content = llm_output,
|
|
115
|
+
timestamp = agent.make_timestamp(),
|
|
116
|
+
agent_id = agent.agent_id,
|
|
117
|
+
prompt_tokens = metadata.get("prompt_tokens", 0),
|
|
118
|
+
completion_tokens = metadata.get("completion_tokens", 0),
|
|
119
|
+
total_tokens = metadata.get("total_tokens", 0),
|
|
120
|
+
reasoning_tokens = metadata.get("reasoning_tokens", 0),
|
|
121
|
+
completion_duration = metadata.get("completion_duration", 0),
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
# end step()
|
|
125
|
+
|
|
126
|
+
if agent.stop_event.is_set():
|
|
127
|
+
agent.logger.info(f"post_run_task_check[{iterations}]: Recv Stop Event, raise AgentStoppedException")
|
|
128
|
+
raise AgentStoppedException("Agent stopped.")
|
|
129
|
+
|
|
130
|
+
# Execute a post_step() function if it exists (polling the Meta Agents Research Environments notifications for example)
|
|
131
|
+
for conditional_step in agent.conditional_post_steps:
|
|
132
|
+
if conditional_step.condition is None or conditional_step.condition(agent):
|
|
133
|
+
conditional_step.function(agent)
|
|
134
|
+
except Exception as e:
|
|
135
|
+
agent.log_error(e)
|
|
136
|
+
agent.logger.info(f"post_run_task_check[{iterations}]: Exception Occur, Stop task")
|
|
137
|
+
agent.task_engine.stop_task()
|
|
138
|
+
finally:
|
|
139
|
+
if agent.simulated_generation_time_config and agent.resume_env:
|
|
140
|
+
agent.resume_env(0.0) # Resume without advancing time
|
|
141
|
+
|
|
142
|
+
agent.iterations += 1
|
|
143
|
+
agent.planning_counter += 1
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def terminate_task_check(agent, iterations: int) -> bool:
|
|
147
|
+
is_terminate_task = False
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
if agent.termination_step and agent.termination_step.condition:
|
|
151
|
+
is_terminate_task = agent.termination_step.condition(agent)
|
|
152
|
+
if is_terminate_task:
|
|
153
|
+
agent.logger.info(f"terminate_task_check[{iterations}]: termination_step.condition is True")
|
|
154
|
+
except Exception as e:
|
|
155
|
+
agent.log_error(e)
|
|
156
|
+
|
|
157
|
+
return is_terminate_task
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class XGAAreAgent(BaseAgent):
|
|
161
|
+
def __init__(self, **kwargs):
|
|
162
|
+
super().__init__(**kwargs)
|
|
163
|
+
self.task_engine: ARETaskEngine = None
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@override
|
|
167
|
+
def initialize(self, attachments: list[Attachment] | None = None, **kwargs) -> None:
|
|
168
|
+
self.logs = []
|
|
169
|
+
self.iterations = 0
|
|
170
|
+
self.planning_counter = 0
|
|
171
|
+
|
|
172
|
+
tool_box = XGAAreToolBox(self.tools)
|
|
173
|
+
|
|
174
|
+
general_system_prompt = "\n\n".join(prompt for prompt in self.init_system_prompts.values())
|
|
175
|
+
prompt_builder = XGAArePromptBuilder(general_system_prompt)
|
|
176
|
+
|
|
177
|
+
model_config = self.llm_engine.model_config
|
|
178
|
+
llm_config = LLMConfig(
|
|
179
|
+
model = model_config.model_name,
|
|
180
|
+
api_key = model_config.api_key,
|
|
181
|
+
api_base = model_config.endpoint
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
self.task_engine = ARETaskEngine(
|
|
185
|
+
agent = self,
|
|
186
|
+
agent_id = self.agent_id,
|
|
187
|
+
max_auto_run = self.max_iterations,
|
|
188
|
+
llm_config = llm_config,
|
|
189
|
+
tool_box = tool_box,
|
|
190
|
+
prompt_builder = prompt_builder,
|
|
191
|
+
pre_run_task_fn = pre_run_task_check,
|
|
192
|
+
post_run_task_fn = post_run_task_check,
|
|
193
|
+
terminate_task_fn = terminate_task_check,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
# Reload the agent state if logs are provided
|
|
197
|
+
start_logs = kwargs.pop("start_logs", [])
|
|
198
|
+
if start_logs:
|
|
199
|
+
self.replay(start_logs)
|
|
200
|
+
|
|
201
|
+
# Include additional image PILs directly into state stack.
|
|
202
|
+
if attachments:
|
|
203
|
+
images = attachments_to_pil(attachments)
|
|
204
|
+
self.action_executor.inject_state({f"image_{i}": image for i, image in enumerate(images)})
|
|
205
|
+
self.logger.debug(f"XGAAreAgent initialize: Injecting images into states for {len(images)} images")
|
|
206
|
+
self.logger.debug(f"XGAAreAgent initialize: New Keys {','.join(self.action_executor.state.keys())}")
|
|
207
|
+
|
|
208
|
+
self.initialized = True
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@override
|
|
212
|
+
def execute_agent_loop(self) -> str | None | MMObservation:
|
|
213
|
+
with asyncio.Runner() as runner:
|
|
214
|
+
runner.run(self.async_execute_agent_loop())
|
|
215
|
+
|
|
216
|
+
# We have reached a termination condition, execute the termination method
|
|
217
|
+
if self.termination_step.function is not None and not self.stop_event.is_set():
|
|
218
|
+
return self.termination_step.function(self)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
async def async_execute_agent_loop(self) -> str | None | MMObservation:
|
|
222
|
+
chunks = []
|
|
223
|
+
async for chunk in self.task_engine.run_task(task_input={"role": "user", "content": self.task}):
|
|
224
|
+
chunks.append(chunk)
|
|
225
|
+
chunk_type = chunk['type']
|
|
226
|
+
if chunk_type== "status":
|
|
227
|
+
status_content = chunk['content']
|
|
228
|
+
status_type = status_content['status_type']
|
|
229
|
+
if status_type == "error":
|
|
230
|
+
error_msg = chunk.get('message')
|
|
231
|
+
self.logger.warning(f"XGAAreAgent execute_agent_loop: Fatal error - {error_msg}")
|
|
232
|
+
self.log_error(error_msg)
|
|
233
|
+
elif status_type == "stop":
|
|
234
|
+
error_msg = chunk.get('message')
|
|
235
|
+
self.logger.warning("XGAAreAgent execute_agent_loop: Agent stopped.")
|
|
236
|
+
self.append_agent_log(
|
|
237
|
+
StopLog(
|
|
238
|
+
content = f"Agent stopped - {error_msg}",
|
|
239
|
+
timestamp = self.make_timestamp(),
|
|
240
|
+
agent_id = self.agent_id,
|
|
241
|
+
)
|
|
242
|
+
)
|
|
243
|
+
elif chunk_type == "assistant":
|
|
244
|
+
llm_content = chunk['content']['content']
|
|
245
|
+
if "<thought>" in llm_content:
|
|
246
|
+
thought_content = re.search(r'<thought>(.*?)</thought>', llm_content, re.DOTALL).group(1).strip()
|
|
247
|
+
if thought_content:
|
|
248
|
+
self.append_agent_log(
|
|
249
|
+
ThoughtLog(
|
|
250
|
+
content = thought_content,
|
|
251
|
+
timestamp = self.make_timestamp(),
|
|
252
|
+
agent_id = self.agent_id,
|
|
253
|
+
)
|
|
254
|
+
)
|
|
255
|
+
elif chunk_type == "tool":
|
|
256
|
+
tool_content = chunk['content']
|
|
257
|
+
tool_execution = tool_content.get('tool_execution')
|
|
258
|
+
tool_result = tool_execution.get('result')
|
|
259
|
+
self.append_agent_log(
|
|
260
|
+
ObservationLog(
|
|
261
|
+
content = str(tool_result),
|
|
262
|
+
attachments = [],
|
|
263
|
+
timestamp = self.make_timestamp(),
|
|
264
|
+
agent_id = self.agent_id,
|
|
265
|
+
)
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
self.append_agent_log(
|
|
269
|
+
ToolCallLog(
|
|
270
|
+
tool_name = tool_execution.get('function_name'),
|
|
271
|
+
tool_arguments = tool_execution.get('arguments'),
|
|
272
|
+
timestamp = self.make_timestamp(),
|
|
273
|
+
agent_id = self.agent_id,
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
#print(chunk)
|
|
277
|
+
|
|
278
|
+
final_result = self.task_engine.parse_final_result(chunks)
|
|
279
|
+
print(f"\n\nFINAL_RESULT: {final_result}")
|
|
280
|
+
|
|
281
|
+
# Send Final Result to user
|
|
282
|
+
args = {
|
|
283
|
+
'content': final_result['content']
|
|
284
|
+
}
|
|
285
|
+
self.tools['AgentUserInterface__send_message_to_user'](**args)
|
|
286
|
+
self.append_agent_log(
|
|
287
|
+
ToolCallLog(
|
|
288
|
+
tool_name = 'AgentUserInterface__send_message_to_user',
|
|
289
|
+
tool_arguments = args,
|
|
290
|
+
timestamp = self.make_timestamp(),
|
|
291
|
+
agent_id = self.agent_id,
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
# Return Final Result
|
|
296
|
+
if final_result['type'] == "error":
|
|
297
|
+
self.custom_state["running_state"] = RunningState.FAILED
|
|
298
|
+
else:
|
|
299
|
+
self.custom_state["running_state"] = RunningState.TERMINATED
|
|
300
|
+
|
|
301
|
+
self.append_agent_log(
|
|
302
|
+
FinalAnswerLog(
|
|
303
|
+
content = final_result['content'],
|
|
304
|
+
timestamp = self.make_timestamp(),
|
|
305
|
+
agent_id = self.agent_id
|
|
306
|
+
)
|
|
307
|
+
)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from functools import partial
|
|
2
|
+
|
|
3
|
+
from are.simulation.agents.llm.llm_engine import LLMEngine
|
|
4
|
+
from are.simulation.agents.are_simulation_agent_config import ARESimulationReactBaseAgentConfig
|
|
5
|
+
from are.simulation.agents.default_agent.steps.are_simulation import get_are_simulation_update_pre_step
|
|
6
|
+
from are.simulation.agents.default_agent.termination_methods.are_simulation import get_gaia2_termination_step
|
|
7
|
+
from are.simulation.agents.default_agent.tools.json_action_executor import JsonActionExecutor
|
|
8
|
+
from are.simulation.agents.default_agent.base_agent import TerminationStep
|
|
9
|
+
from are.simulation.agents.default_agent.termination_methods.are_simulation import termination_condition_are_simulation
|
|
10
|
+
|
|
11
|
+
from are.simulation.agents.xga.are_agent import XGAAreAgent
|
|
12
|
+
|
|
13
|
+
termination_condition_are_simulation_send_message_to_user = partial(
|
|
14
|
+
termination_condition_are_simulation,
|
|
15
|
+
termination_tool_names=[
|
|
16
|
+
"AgentUserInterface__send_message_to_user"
|
|
17
|
+
],
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
def get_xga_termination_step() -> TerminationStep:
|
|
21
|
+
return TerminationStep(
|
|
22
|
+
name="end_scenario",
|
|
23
|
+
condition=termination_condition_are_simulation_send_message_to_user,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def xga_simulation_react_xml_agent(
|
|
27
|
+
llm_engine: LLMEngine, base_agent_config: ARESimulationReactBaseAgentConfig
|
|
28
|
+
):
|
|
29
|
+
return XGAAreAgent(
|
|
30
|
+
llm_engine=llm_engine,
|
|
31
|
+
tools={},
|
|
32
|
+
system_prompts={
|
|
33
|
+
"system_prompt": str(base_agent_config.system_prompt),
|
|
34
|
+
},
|
|
35
|
+
termination_step=get_xga_termination_step(),
|
|
36
|
+
max_iterations=base_agent_config.max_iterations,
|
|
37
|
+
action_executor=JsonActionExecutor( # Just for compatible BaseAgent, useless
|
|
38
|
+
use_custom_logger=base_agent_config.use_custom_logger
|
|
39
|
+
),
|
|
40
|
+
conditional_pre_steps=[get_are_simulation_update_pre_step()],
|
|
41
|
+
use_custom_logger=base_agent_config.use_custom_logger,
|
|
42
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Optional, List, Literal
|
|
3
|
+
|
|
4
|
+
from xgae.engine.prompt_builder import XGAPromptBuilder
|
|
5
|
+
from xgae.utils.misc import read_file
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class XGAArePromptBuilder(XGAPromptBuilder):
|
|
9
|
+
def __init__(self, general_system_prompt: Optional[str]):
|
|
10
|
+
are_system_prompt = self.build_are_system_prompt(general_system_prompt)
|
|
11
|
+
super().__init__(are_system_prompt)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_are_system_prompt(self, _system_prompt: str)-> str:
|
|
15
|
+
pattern = r'<general_instructions>(.*?)</general_instructions>'
|
|
16
|
+
prompt_are_general = re.search(pattern, _system_prompt, re.DOTALL)
|
|
17
|
+
prompt_header = "# CORE IDENTITY\n"
|
|
18
|
+
if prompt_are_general:
|
|
19
|
+
prompt_are_general = prompt_header + prompt_are_general.group(1).strip() + "\n\n"
|
|
20
|
+
else:
|
|
21
|
+
prompt_are_general = prompt_header + _system_prompt + "\n\n"
|
|
22
|
+
|
|
23
|
+
are_tool_prompt = read_file("templates/are_prompt_template.md")
|
|
24
|
+
are_system_prompt = prompt_are_general + are_tool_prompt
|
|
25
|
+
|
|
26
|
+
return are_system_prompt
|
|
27
|
+
|