Skip to content

Commit 360af4c

Browse files
committed
update
1 parent d9eea89 commit 360af4c

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

eval_protocol/mcp/execution/manager.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async def _execute_with_semaphore(idx):
171171
if trajectory.terminated:
172172
if trajectory.termination_reason == TerminationReason.ERROR:
173173
evaluation_rows[idx].rollout_status.status = "error"
174-
evaluation_rows[idx].rollout_status.reason= trajectory.control_plane_summary.get(
174+
evaluation_rows[idx].rollout_status.reason = trajectory.control_plane_summary.get(
175175
"error_message", None
176176
)
177177
else:
@@ -362,6 +362,12 @@ async def _execute_rollout(
362362
if recording_mode:
363363
policy.log_conversation_state_for_playback(rollout_idx, step - 1, conversation_history)
364364

365+
if env_end:
366+
# if the env marks the end of the rollout, break the tool call loop
367+
# but set the termination reason later after the final policy call
368+
trajectory.terminated = True
369+
break
370+
365371
if step >= steps:
366372
trajectory.terminated = True
367373
trajectory.termination_reason = TerminationReason.MAX_STEPS
@@ -395,9 +401,16 @@ async def _execute_rollout(
395401
if recording_mode:
396402
policy.log_conversation_state_for_playback(rollout_idx, step - 1, conversation_history)
397403

398-
# update control plane summary if the env marks end
404+
# if the env marks end, update control plane summary and do one last policy call, then break the agent loop
405+
# this is to ensure each turn ends with an assistant message, which will align with the actual agentic llm behavior
399406
if env_end:
400-
# Add final control plane summary
407+
_, usage_stats, finish_reason = await policy(tool_schema, rollout_idx, conversation_history)
408+
if usage_stats:
409+
trajectory.usage["prompt_tokens"] += usage_stats.prompt_tokens
410+
trajectory.usage["completion_tokens"] += usage_stats.completion_tokens
411+
trajectory.usage["total_tokens"] += usage_stats.total_tokens
412+
trajectory.terminated = True
413+
trajectory.termination_reason = TerminationReason.from_str(finish_reason)
401414
trajectory.control_plane_summary.update(
402415
{
403416
"total_reward": trajectory.total_reward,

eval_protocol/types/types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from contextlib import AsyncExitStack
12
from dataclasses import dataclass, field
23
from enum import Enum
34
from typing import Any, Dict, List, Optional
5+
46
from mcp.client.session import ClientSession
5-
from contextlib import AsyncExitStack
67

78

89
class TerminationReason(str, Enum):
@@ -14,6 +15,7 @@ class TerminationReason(str, Enum):
1415
ERROR: Trajectory ends because of an error
1516
STOP: Trajectory ends by the policy (mapped to llm response stop reason "stop")
1617
LENGTH: Trajectory ends by the policy (mapped to llm response stop reason "length")
18+
TOOL_CALLS: Trajectory ends by the policy with a hanging tool call response (mapped to llm response stop reason "tool_calls")
1719
"""
1820

1921
MAX_STEPS = "max_steps"
@@ -22,6 +24,7 @@ class TerminationReason(str, Enum):
2224
ERROR = "error"
2325
STOP = "stop"
2426
LENGTH = "length"
27+
TOOL_CALLS = "tool_calls"
2528

2629
@classmethod
2730
def from_str(cls, value: str) -> "TerminationReason":
@@ -37,6 +40,8 @@ def from_str(cls, value: str) -> "TerminationReason":
3740
return cls.USER_STOP
3841
elif value == "error":
3942
return cls.ERROR
43+
elif value == "tool_calls":
44+
return cls.TOOL_CALLS
4045
else:
4146
raise ValueError(f"Invalid termination reason: {value}")
4247

0 commit comments

Comments
 (0)