Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
226 commits
Select commit Hold shift + click to select a range
617693f
supported aworld with areal train
rainsonGain Sep 26, 2025
fdbf598
Merge remote-tracking branch 'origin/main' into feature/train_with_areal
rainsonGain Sep 26, 2025
53418c3
rename examples parallel_task
rainsonGain Sep 26, 2025
7b1fdf3
Merge remote-tracking branch 'origin/main' into feature/train_with_areal
rainsonGain Sep 28, 2025
2a00df7
AWorld with AReaL training refine
rainsonGain Sep 28, 2025
1fe36d3
all use async in LLM provider
rainsonGain Oct 9, 2025
4f87d81
Merge remote-tracking branch 'origin/main' into feature/train_with_areal
rainsonGain Oct 9, 2025
c671fb6
add loop in new thread;
rainsonGain Oct 9, 2025
65d458f
improve event runner;
rainsonGain Oct 10, 2025
53534bc
copy inference response
rainsonGain Oct 11, 2025
641ef2e
for robust on run
rainsonGain Oct 11, 2025
944667c
use new loop supported;
rainsonGain Oct 11, 2025
078e211
Non-essential log info change from warning to debug level
rainsonGain Oct 11, 2025
1d993ca
file format
rainsonGain Oct 11, 2025
aea7fea
improve robust on run
rainsonGain Oct 13, 2025
a5a7f3b
add thread pool of create and close;
rainsonGain Oct 13, 2025
a440e76
example update
rainsonGain Oct 13, 2025
98cb5ab
fix run.sh and param
rainsonGain Oct 13, 2025
7566b29
train with areal add README.md;
rainsonGain Oct 13, 2025
fd73294
Merge remote-tracking branch 'origin/main' into feature/train_with_areal
rainsonGain Oct 13, 2025
cdf22e6
remove unused code
rainsonGain Oct 13, 2025
fa82b15
keep log
rainsonGain Oct 13, 2025
fb9342f
remove prompt
rainsonGain Oct 13, 2025
08f7f4d
[GroupHandler] apply group message when call agent as tool
SiqiHouCk Oct 14, 2025
fb45a27
Merge branch 'main' into feature/train_areal_multi_turn
wangchunf Oct 15, 2025
9e06131
Merge branch 'main' of github.com:inclusionAI/AWorld into feat/group_…
SiqiHouCk Oct 20, 2025
faa248f
Merge branch 'main' into feature/train_areal_multi_turn
wangchunf Oct 21, 2025
a43d4e2
Merge branch 'main' of github.com:inclusionAI/AWorld into feat/group_…
SiqiHouCk Oct 21, 2025
cbc19ca
[train] sigle step train
wangchunf Oct 21, 2025
6002118
use memory handler to add agent memory
SiqiHouCk Oct 22, 2025
73c7eec
[train] token id trajectory
wangchunf Oct 22, 2025
610340a
Merge branch 'main' into feature/train_areal_multi_turn
wangchunf Oct 22, 2025
c6b1c53
Merge branch 'main' of github.com:inclusionAI/AWorld into feat/group_…
SiqiHouCk Oct 23, 2025
ce0f390
[train] single step train
wangchunf Oct 23, 2025
7af9fdc
Merge branch 'feat/group_message_for_agent_as_tool' into feature/trai…
wangchunf Oct 23, 2025
fcd9f81
remove duplicate code
rainsonGain Oct 23, 2025
612c134
[train] multi turn train
wangchunf Oct 23, 2025
7ecd859
micro refactor write memory function
rainsonGain Oct 23, 2025
5b6ba24
Merge branch 'main' of github.com:inclusionAI/AWorld into feat/group_…
SiqiHouCk Oct 23, 2025
27db467
[train] single step test
wangchunf Oct 23, 2025
a796ea6
fix wait timeout in MessageFuture
SiqiHouCk Oct 24, 2025
af74b91
do not try to add tool result to memory if receive_agent is null
SiqiHouCk Oct 24, 2025
c77bab6
[train] single step test
wangchunf Oct 24, 2025
a8ecbff
[train] single step test
wangchunf Oct 24, 2025
d494208
Merge branch 'feat/group_message_for_agent_as_tool' into feature/trai…
wangchunf Oct 24, 2025
08eefbe
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/gro…
ahgpt Oct 27, 2025
e99d595
[train] token_id trajectory
wangchunf Oct 27, 2025
917d86d
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/gro…
ahgpt Oct 27, 2025
0f6fca6
quick start gaia
tallate Oct 27, 2025
fc3754f
[train] token_ids trajectory test
wangchunf Oct 27, 2025
f02b6d4
quick start gaia (single_context_agent_demo)
tallate Oct 27, 2025
4e6109c
quick start gaia (single_context_agent_demo)
tallate Oct 27, 2025
550da9e
amnicontext
tallate Oct 27, 2025
abc0573
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Oct 28, 2025
bcccf22
[Context] refactor call tool with context
ahgpt Oct 28, 2025
be07835
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Oct 28, 2025
2b1f782
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Oct 28, 2025
9be7957
test query 10
tallate Oct 28, 2025
ea77050
[Context] Add Agent Skill Support
ahgpt Oct 28, 2025
77fa383
Merge remote-tracking branch 'origin/main' into feat/group_message_fo…
ahgpt Oct 28, 2025
933bc6c
[Context] Add Agent Skill Support
ahgpt Oct 28, 2025
6d010f5
[Context] Add Agent Skill Support
ahgpt Oct 28, 2025
53711f1
[train] context token_id copy
wangchunf Oct 28, 2025
6554075
support mcp_config context_config
tallate Oct 28, 2025
760340e
support mcp_config context_config
tallate Oct 28, 2025
99668eb
Merge branch 'feat/group_message_for_agent_as_tool' into feature/trai…
wangchunf Oct 28, 2025
2ed2ba7
support mcp_config context_config
tallate Oct 28, 2025
fdc9dc1
support mcp_config context_config
tallate Oct 28, 2025
73142b0
[train] multi turn train
wangchunf Oct 28, 2025
8a09776
default to summary
tallate Oct 28, 2025
56d4e7e
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Oct 28, 2025
9d4a860
fix init middleware
tallate Oct 28, 2025
fce656d
[train] event bus clear task data
wangchunf Oct 28, 2025
0c50daf
3 summary prompt
tallate Oct 29, 2025
9e8a6f1
fix
tallate Oct 29, 2025
94bddc2
default to local
tallate Oct 29, 2025
dc7fc6c
[train] mas train token ids trajectory
wangchunf Oct 29, 2025
ae07d7b
qwen deepresearch tools
tallate Oct 30, 2025
cc4bcd1
[train] mas token ids trajectory
wangchunf Oct 30, 2025
ca77acd
[train] mas train token ids trajectory
wangchunf Oct 30, 2025
4ced193
[train] mas train token ids trajectory
wangchunf Oct 30, 2025
28c0eda
[train] mas token ids trajectory
wangchunf Oct 30, 2025
0a8c383
qwen idp doc parser tools
tallate Oct 30, 2025
fd1842a
qwen idp doc parser tools
tallate Oct 30, 2025
35900cd
file_parser
tallate Oct 30, 2025
a8afaef
qwen idp doc parser tools
tallate Oct 30, 2025
b89d74a
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Oct 30, 2025
101528e
[train] mas rl token ids trajectory
wangchunf Oct 30, 2025
c4de808
[train] token ids trajectory log json
wangchunf Oct 30, 2025
3935045
[train] token ids trajectory log json
wangchunf Oct 30, 2025
44e2bf2
[train] areal multi turn workflow
wangchunf Oct 30, 2025
d69a148
qwen file parser
tallate Oct 30, 2025
4b60b3c
fix path
tallate Oct 30, 2025
0932559
gaia
tallate Oct 30, 2025
790cbfe
gaia trajectory
tallate Oct 31, 2025
81fb1db
gaia trajectory
tallate Oct 31, 2025
781251e
gaia trajectory
tallate Oct 31, 2025
e090b79
remove session_id
kevinfeng030 Oct 31, 2025
0254afb
[train] add prompt template tool from AgentFly
wangchunf Oct 31, 2025
957f445
Merge branch 'main' into feature/train_areal_multi_turn_1
wangchunf Oct 31, 2025
39fd8a5
Merge branch 'main' into feature/train_areal_multi_turn_1
wangchunf Oct 31, 2025
feb545b
Merge branch 'main' into feature/train_areal_multi_turn_1
wangchunf Oct 31, 2025
a72a9b0
Merge branch 'main' into feature/train_areal_multi_turn_1
wangchunf Oct 31, 2025
f24412d
Merge branch 'main' into feature/train_areal_multi_turn_1
wangchunf Oct 31, 2025
de2da1e
gaia trajectory
tallate Oct 31, 2025
a67e2bb
merge
tallate Oct 31, 2025
c04d392
test local
tallate Oct 31, 2025
7632ccf
rollback test code
tallate Nov 3, 2025
5eda89c
Merge branch 'feature/train_areal_multi_turn_1' into aworld_gaia
tallate Nov 3, 2025
970779c
test local gaia agent
tallate Nov 3, 2025
50d63bb
trajectory from memory
tallate Nov 4, 2025
e4d2b45
update usage
tallate Nov 4, 2025
438c4a4
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Nov 4, 2025
d58cf86
update usage
tallate Nov 4, 2025
9e2d724
merge
tallate Nov 4, 2025
2c42fd5
merge
tallate Nov 4, 2025
651805d
save traj
tallate Nov 4, 2025
18223dd
env
tallate Nov 4, 2025
d321c22
env
tallate Nov 4, 2025
34b5c68
trajectory usage
tallate Nov 4, 2025
055198d
tool_name
tallate Nov 4, 2025
df72a08
init_middlewares
tallate Nov 4, 2025
fcbe4c9
assistant
tallate Nov 4, 2025
ab595ee
fix outputs
tallate Nov 4, 2025
f1b8d84
no vectory
tallate Nov 5, 2025
848c453
code path
tallate Nov 5, 2025
e73408f
verl
tallate Nov 5, 2025
69c66a3
fix
tallate Nov 5, 2025
5337cdb
default to not summary
tallate Nov 5, 2025
e985b96
mcp version
tallate Nov 5, 2025
ec69019
time metrics
tallate Nov 6, 2025
fb8dfc6
time metrics
tallate Nov 6, 2025
e76dc40
time metrics
tallate Nov 6, 2025
92aba34
time metrics
tallate Nov 6, 2025
a9ce484
skip last round summary
tallate Nov 6, 2025
13c62a9
screen_shot features
tallate Nov 7, 2025
53a778e
screenshot_hook
tallate Nov 7, 2025
cb6a380
path
tallate Nov 7, 2025
5382939
path
tallate Nov 7, 2025
8019790
path
tallate Nov 7, 2025
ee4cb69
summary default config
tallate Nov 7, 2025
92bdfe7
已总结的也加入待总结列表
tallate Nov 10, 2025
0ef43b9
已总结的也加入待总结列表
tallate Nov 10, 2025
91a8eb4
add flight_judge reward
yaoyueduzhen Nov 10, 2025
aa707d9
ip pool
tallate Nov 11, 2025
284acf8
Merge branch 'aworld_gaia' of https://github.com/inclusionAI/AWorld i…
tallate Nov 11, 2025
727442b
support ip pool
tallate Nov 11, 2025
240d1ae
flight judge
tallate Nov 11, 2025
8ed7fcd
fire
tallate Nov 11, 2025
76d7c78
fire
tallate Nov 11, 2025
743bf37
current path .env
tallate Nov 11, 2025
e999401
current path .env
tallate Nov 11, 2025
4722e9d
fix score error
tallate Nov 11, 2025
9ec2e72
fix score error
tallate Nov 11, 2025
b533dcc
utils
tallate Nov 11, 2025
071c8d8
memory_type
tallate Nov 11, 2025
d838d37
debug
tallate Nov 11, 2025
f978e6e
not use test ip pool
tallate Nov 11, 2025
5fd513f
session_id, task_id
tallate Nov 11, 2025
accaa94
modify flight_judge
yaoyueduzhen Nov 12, 2025
a7ff148
fix memory direct
tallate Nov 12, 2025
480371e
Merge branch 'aworld_gaia' of https://github.com/inclusionAI/AWorld i…
tallate Nov 12, 2025
6786221
taskInput
tallate Nov 12, 2025
f0d9024
taskInput
tallate Nov 12, 2025
c692281
fix image content
tallate Nov 12, 2025
d84151e
modify flight_judge
yaoyueduzhen Nov 12, 2025
610302a
ip pool retry
tallate Nov 13, 2025
c3ac440
Merge branch 'aworld_gaia' of https://github.com/inclusionAI/AWorld i…
tallate Nov 13, 2025
aa137d1
modify flight_judge
yaoyueduzhen Nov 13, 2025
fa21538
Merge remote-tracking branch 'origin/aworld_gaia' into aworld_gaia
yaoyueduzhen Nov 13, 2025
1f6b967
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Nov 13, 2025
f7b9cda
trajectory_strategy
tallate Nov 13, 2025
6c1540c
Merge branch 'aworld_gaia' of https://github.com/inclusionAI/AWorld i…
tallate Nov 13, 2025
493af7b
try catch toolcallback
tallate Nov 14, 2025
acac900
ip pool
tallate Nov 17, 2025
4456e69
modify flight_judge
yaoyueduzhen Nov 17, 2025
e1411ce
ip pool test
tallate Nov 18, 2025
c5cdaf0
Merge branch 'aworld_gaia' of https://github.com/inclusionAI/AWorld i…
tallate Nov 18, 2025
abc36ed
fix flight_judge
yaoyueduzhen Nov 18, 2025
58281b0
retry screenshot
tallate Nov 18, 2025
c8d4344
Merge branch 'aworld_gaia' of https://github.com/inclusionAI/AWorld i…
tallate Nov 18, 2025
829fbbb
specify role
tallate Nov 19, 2025
8ba58bd
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Nov 19, 2025
9ef615f
clean code
tallate Nov 19, 2025
c9813a9
clean duplicate code
tallate Nov 19, 2025
d4d7ea7
clean duplicate code
tallate Nov 19, 2025
2c725d4
debug_mode default to False
tallate Nov 19, 2025
f8b32cc
delete duplicate nodes
tallate Nov 19, 2025
8f47b95
delete duplicate code
tallate Nov 19, 2025
00bea53
delete duplicate code
tallate Nov 19, 2025
edbd9e6
delete duplicate code
tallate Nov 19, 2025
c9644f3
Merge branch 'main' of https://github.com/inclusionAI/AWorld into awo…
tallate Nov 19, 2025
1f0bc42
delete duplicate code
tallate Nov 19, 2025
f376143
xiecheng hook
tallate Nov 19, 2025
d9e85e7
xiecheng hook
tallate Nov 19, 2025
3f72ed0
xiecheng hook
tallate Nov 20, 2025
4ad6fe9
debug_mode
tallate Nov 20, 2025
4feba8c
context train
tallate Nov 21, 2025
e0acc9a
log agent config
tallate Nov 21, 2025
fe8857d
agent loop
tallate Nov 21, 2025
2d155e9
agent loop
tallate Nov 21, 2025
29d5902
agent loop
tallate Nov 21, 2025
4e3115e
Merge branch 'main' of https://github.com/inclusionAI/AWorld into gai…
tallate Nov 21, 2025
8aab21f
task input
tallate Nov 21, 2025
f55ac74
download artifact content
tallate Nov 25, 2025
0b39117
Merge branch 'main' of https://github.com/inclusionAI/AWorld into gai…
tallate Nov 25, 2025
30ed3f7
memory aworld agent loop
tallate Nov 26, 2025
d7dd661
encode usage
tallate Nov 26, 2025
d55e793
revert
tallate Nov 26, 2025
ee06556
agent_loop path
tallate Nov 26, 2025
5ccda51
await fix
tallate Nov 26, 2025
0042229
await fix
tallate Nov 26, 2025
7675ad4
LLM_API_KEY
tallate Nov 27, 2025
fb2eb38
provider
tallate Nov 27, 2025
3682ca6
provider
tallate Nov 27, 2025
6ce75b9
dataset
tallate Nov 27, 2025
80b9ae0
qwen_file_parser
tallate Nov 27, 2025
c6ec6be
task_input
tallate Nov 27, 2025
11874d5
task_input
tallate Nov 27, 2025
9ab8d5e
context train
tallate Nov 27, 2025
0e03f1f
context train
tallate Nov 27, 2025
b33ad22
import fix
tallate Nov 27, 2025
e5ca111
import param
tallate Nov 28, 2025
cc0c5aa
env fix
tallate Nov 28, 2025
bf3edbf
encode_run
tallate Nov 28, 2025
2238f59
history_scope
tallate Dec 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 51 additions & 27 deletions aworld/agents/llm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,45 @@ def messages_transform(self,
return sync_exec(self.async_messages_transform, image_urls=image_urls, observation=observation,
message=message, **kwargs)

def _is_amni_context(self, context: Context):
from aworld.core.context.amni import AmniContext
return isinstance(context, AmniContext)

def _build_memory_filters(self, context: Context, additional_filters: Dict[str, Any] = None) -> Dict[str, Any]:
filters = {
"agent_id": self.id()
}

# Decide which filter to add based on history_scope
agent_memory_config = self.memory_config
if self._is_amni_context(context):
agent_context_config = context.get_config().get_agent_context_config(self.id())
agent_memory_config = agent_context_config.to_memory_config()

query_scope = agent_memory_config.history_scope if agent_memory_config and agent_memory_config.history_scope else "task"
task = context.get_task()

if query_scope == "user":
# Pass user_id when query_scope is user
if hasattr(context, 'user_id') and context.user_id:
filters["user_id"] = context.user_id
elif hasattr(task, 'user_id') and task.user_id:
filters["user_id"] = task.user_id
elif query_scope == "session":
# Pass session_id when query_scope is session
if task and task.session_id:
filters["session_id"] = task.session_id
else: # query_scope == "task" or default
# Pass task_id when query_scope is task
if task and task.id:
filters["task_id"] = task.id

# Add additional filter conditions
if additional_filters:
filters.update(additional_filters)

return filters

def _clean_redundant_tool_call_messages(self, histories: List[MemoryItem]) -> None:
try:
for i in range(len(histories) - 1, -1, -1):
Expand All @@ -269,14 +308,8 @@ def postprocess_terminate_loop(self, message: Message):
logger.info(f"Agent {self.id()} postprocess_terminate_loop: {self.loop_step}")
super().postprocess_terminate_loop(message)
try:
session_id = message.context.get_task().session_id
task_id = message.context.get_task().id
histories = self.memory.get_all(filters={
"agent_id": self.id(),
"session_id": session_id,
"task_id": task_id,
"memory_type": "message"
})
filters = self._build_memory_filters(message.context, additional_filters={"memory_type": "message"})
histories = self.memory.get_all(filters=filters)
self._clean_redundant_tool_call_messages(histories)
except Exception:
logger.error(f"Agent {self.id()} postprocess_terminate_loop error: {traceback.format_exc()}")
Expand Down Expand Up @@ -304,14 +337,8 @@ async def async_messages_transform(self,
if self.system_prompt:
await self._add_message_to_memory(context=message.context, payload=content, message_type=MemoryType.SYSTEM)

session_id = message.context.get_task().session_id
task_id = message.context.get_task().id
histories = self.memory.get_all(filters={
"agent_id": self.id(),
"session_id": session_id,
"task_id": task_id,
"memory_type": "message"
})
filters = self._build_memory_filters(message.context, additional_filters={"memory_type": "message"})
histories = self.memory.get_all(filters=filters)

# append observation to memory
tool_result_added = False
Expand All @@ -333,11 +360,12 @@ async def async_messages_transform(self,
context=message.context)

# from memory get last n messages
histories = self.memory.get_last_n(self.memory_config.history_rounds, filters={
"agent_id": self.id(),
"session_id": session_id,
"task_id": task_id
}, agent_memory_config=self.memory_config)
filters = self._build_memory_filters(message.context)
agent_memory_config = self.memory_config
if self._is_amni_context(message.context):
agent_context_config = message.context.get_config().get_agent_context_config(self.id())
agent_memory_config = agent_context_config.to_memory_config()
histories = self.memory.get_last_n(agent_memory_config.history_rounds, filters=filters, agent_memory_config=agent_memory_config)
if histories:
tool_calls_map = {}
last_tool_calls = []
Expand Down Expand Up @@ -841,12 +869,8 @@ async def _add_tool_result_token_ids_to_context(self, context: Context):
"""Add tool result token ids to context"""
if context.get_task().conf.get("run_mode") != TaskRunMode.INTERACTIVE:
return
histories = self.memory.get_all(filters={
"agent_id": self.id(),
"session_id": context.get_task().session_id,
"task_id": context.get_task().id,
"memory_type": "message"
})
filters = self._build_memory_filters(context, additional_filters={"memory_type": "message"})
histories = self.memory.get_all(filters=filters)
tool_openai_messages_after_last_assistant = []
found_assistant = False
tool_call_ids = []
Expand Down
3 changes: 2 additions & 1 deletion aworld/config/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ class AgentMemoryConfig(BaseConfig):
description="rounds of message msg; when the number of messages is greater than the history_rounds, the memory will be trimmed")
history_write_strategy: HistoryWriteStrategy = Field(default=HistoryWriteStrategy.EVENT_DRIVEN,
description="History write strategy: event_driven (through message system) or direct (direct call to handler)")

history_scope: Optional[str] = Field(default="task", description="History initialization scope: user, session, or task")

enable_summary: bool = Field(default=False,
description="enable_summary use llm to create summary short-term memory")
summary_model: Optional[str] = Field(default=None, description="short-term summary model")
Expand Down
2 changes: 2 additions & 0 deletions aworld/core/context/amni/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class AgentContextConfig(BaseConfig):
description="rounds of message msg; when the number of messages is greater than the history_rounds, the memory will be trimmed")
history_write_strategy: HistoryWriteStrategy = Field(default=HistoryWriteStrategy.EVENT_DRIVEN,
description="History write strategy: event_driven (through message system) or direct (direct call to handler)")
history_scope: Optional[str] = Field(default="task", description="History initialization scope: user, session, or task")

# Context Reduce - Compress
enable_summary: bool = Field(default=False,
Expand Down Expand Up @@ -118,6 +119,7 @@ def to_memory_config(self) -> AgentMemoryConfig:
return AgentMemoryConfig(
history_rounds=self.history_rounds,
history_write_strategy=self.history_write_strategy,
history_scope=self.history_scope,
enable_summary=self.enable_summary,
summary_rounds=self.summary_rounds,
summary_context_length=self.summary_context_length,
Expand Down
9 changes: 9 additions & 0 deletions aworld/core/tool/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ async def post_step(self,
headers={"context": context})
return result

# tool hooks
try:
events = []
async for event in run_hooks(context=message.context, hook_point=HookPoint.POST_TOOL_CALL, hook_from=result.caller, payload=step_res):
events.append(event)
except Exception:
logger.debug(traceback.format_exc())
return result

async def _exec_tool_callback(self, step_res: Tuple[Observation, float, bool, bool, Dict[str, Any]],
action: List[ActionModel],
message: Message,
Expand Down
6 changes: 3 additions & 3 deletions aworld/dataset/trajectory_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,18 @@ async def generate_trajectory_for_memory(self, swarm: Swarm, context: Context):
}, agent_memory_config=swarm.cur_agent[0].memory_config)

# Convert memory items to OpenAI message format
result = {}
result = []
for i, item in enumerate(memory_items):
# Check if item has to_openai_message method
if hasattr(item, 'to_openai_message'):
message = item.to_openai_message()
# Add usage to the message if it exists in metadata
if hasattr(item, 'metadata') and item.metadata and 'usage' in item.metadata:
message['usage'] = item.metadata['usage']
result[i] = message
result.append(message)
else:
# If item doesn't have to_openai_message, return the item as is
result[i] = item
result.append(item)

return result

Expand Down
8 changes: 5 additions & 3 deletions aworld/evaluations/scorers/llm_as_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def build_judge_prompt(self, index: int, input: EvalDataCase[EvalCaseDataType],
raise NotImplementedError("build_judge_prompt must be implemented in subclasses")

@abc.abstractmethod
def build_judge_data(self, index: int, input: EvalDataCase[EvalCaseDataType], output: dict) -> str:
def build_judge_data(self, index: int, input: EvalDataCase[EvalCaseDataType], output: dict) -> [str, dict]:
"""Builds the input for the judge agent task.

Args:
Expand All @@ -72,7 +72,7 @@ def build_judge_data(self, index: int, input: EvalDataCase[EvalCaseDataType], ou
str: The input string for the judge agent task.

Example:
[Question]: {input.case_data.get('question', '')}
[疑问]: {input.case_data.get('question', '')}
[Correct_Answer]: {input.case_data.get('answer', '')}
[Response]: {output.get('answer', '')}
"""
Expand Down Expand Up @@ -106,6 +106,8 @@ async def score(self, index: int, input: EvalDataCase[EvalCaseDataType], output:
agent_prompt=self.build_judge_prompt(index=index, input=input, output=output))

task_input = self.build_judge_data(index=index, input=input, output=output)
if not task_input:
return ScorerResult(scorer_name=self.name, metric_results={})
response = await exec_agent(task_input, agent=score_agent, context=Context())
metric_results = self.convert_judge_response_to_score(response.answer)
if metric_results:
Expand All @@ -130,4 +132,4 @@ def _build_judge_system_prompt(self) -> str:
"""
return '''
You are a judge model that evaluates the quality of the response.
'''
'''
3 changes: 2 additions & 1 deletion aworld/evaluations/scorers/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class MetricNames:
LABEL_DISTRIBUTION = 'label_distribution'
SUMMARIZE_QUALITY = 'summarize_quality'
ANSWER_ACCURACY = 'answer_accuracy'
PREDICT_TIME_COST_MS = 'predict_time_cost_ms'
PREDICT_TIME_COST_MS = 'predict_time_cost_ms'
FLIGHT_JUDGE = 'flight_judge'
17 changes: 17 additions & 0 deletions aworld/output/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,23 @@ def save(self) -> None:
self.repository.save_index(workspace_data)
self._rebuild_artifact_id_index()

def get_raw_file_content_by_artifact_id(self, artifact_id: str) -> str:
"""
Get concatenated content of all artifacts with the same filename.

Args:
artifact_id: artifact_id

Returns:
Raw unescaped concatenated content of all matching artifacts
"""
filename = artifact_id
artifact_data = self.repository.retrieve_latest_artifact(artifact_id)
if not artifact_data:
return ""
artifact = Artifact.from_dict(artifact_data)
return artifact.content

def get_file_content_by_artifact_id(self, artifact_id: str) -> str:
"""
Get concatenated content of all artifacts with the same filename.
Expand Down
29 changes: 14 additions & 15 deletions aworld/runners/handler/memory.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# aworld/runners/handler/output.py
import copy
import json
import time
import traceback
from datetime import datetime
from typing import AsyncGenerator, Any
from typing import Any

from aworld.agents.llm_agent import Agent
from aworld.config import ConfigDict
from aworld.core.common import ActionResult
from aworld.core.context.base import Context
from aworld.core.event.base import Message, Constants, MemoryEventMessage, MemoryEventType
from aworld.logs.util import logger
from aworld.memory.main import MemoryFactory
from aworld.memory.models import MemoryToolMessage, MessageMetadata, MemoryHumanMessage, MemorySystemMessage, \
MemoryAIMessage
from aworld.runners import HandlerFactory
from aworld.runners.handler.base import DefaultHandler
from aworld.core.common import TaskItem, ActionResult
from aworld.core.event.base import Message, Constants, TopicType, MemoryEventMessage, MemoryEventType
from aworld.logs.util import logger
from aworld.runners.hook.hook_factory import HookFactory


Expand Down Expand Up @@ -182,7 +181,7 @@ async def _add_llm_response_to_memory(self, agent: Agent, llm_response, context:
"""Add LLM response to memory"""
# Get start time from context (if exists)
start_time = context.context_info.get("llm_call_start_time")

ai_message = MemoryAIMessage(
content=llm_response.content,
tool_calls=llm_response.tool_calls,
Expand All @@ -197,13 +196,13 @@ async def _add_llm_response_to_memory(self, agent: Agent, llm_response, context:
}
)
)

# If start time exists in context, update it
if start_time:
ai_message.start_time = start_time
# Record message end time
ai_message.end_time = None

agent_memory_config = agent.memory_config
if self._is_amni_context(context):
agent_memory_config = context.get_config().get_agent_memory_config(agent.id())
Expand Down Expand Up @@ -283,10 +282,10 @@ async def _do_add_tool_result_to_memory(self, agent: 'Agent', tool_call_id: str,
tool_use_summary = None
if isinstance(tool_result, ActionResult):
tool_use_summary = tool_result.metadata.get("tool_use_summary")

# Get start time from context (if exists)
start_time = context.context_info.get(f"tool_call_start_time_{tool_call_id}")

tool_message = MemoryToolMessage(
content=tool_result.content if hasattr(tool_result, 'content') else tool_result,
tool_call_id=tool_call_id,
Expand All @@ -301,14 +300,14 @@ async def _do_add_tool_result_to_memory(self, agent: 'Agent', tool_call_id: str,
ext_info={"tool_name": tool_result.tool_name, "action_name": tool_result.action_name}
)
)

# If start time exists in context, update it
if start_time:
tool_message.start_time = start_time

# Record message end time
tool_message.end_time = None

await memory.add(tool_message, agent_memory_config=agent.memory_config)

def _is_amni_context(self, context: Context):
Expand All @@ -318,7 +317,7 @@ def _is_amni_context(self, context: Context):
@staticmethod
async def handle_memory_message_directly(memory_msg: MemoryEventMessage, context: Context):
"""Handle memory message directly without going through message system

Args:
memory_msg: Memory event message
context: Context object
Expand All @@ -329,7 +328,7 @@ class SimpleRunner:
def __init__(self, task):
self.task = task
self.start_time = 0

task = context.get_task()
simple_runner = SimpleRunner(task)
handler = DefaultMemoryHandler(simple_runner)
Expand Down
1 change: 1 addition & 0 deletions aworld/runners/hook/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class HookPoint:
ERROR = "error"
PRE_LLM_CALL = "pre_llm_call"
POST_LLM_CALL = "post_llm_call"
POST_TOOL_CALL = "post_tool_call"
OUTPUT_PROCESS = "output_process"
PRE_TOOL_CALL = "pre_tool_call"
POST_TOOL_CALL = "post_tool_call"
Expand Down
Loading