Skip to content

Commit f806e35

Browse files
fengju0213claude
andcommitted
fix: remove phantom public attribute, unused var, add deprecation comments
- Remove `worker_agent.execution_context` assignment (attribute doesn't exist on ChatAgent, only `_execution_context` does) - Remove unused `total_tokens` local variable - Add backward-compat comments for duplicate fields - Fix line-length lint errors Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 8d49619 commit f806e35

2 files changed

Lines changed: 31 additions & 26 deletions

File tree

camel/societies/workforce/single_agent_worker.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def _build_execution_context(
430430
"borrowed_agent_id": getattr(
431431
worker_agent, "agent_id", worker_agent.role_name
432432
),
433+
# Alias kept for backward compatibility with eigent consumers.
433434
"agent_id": getattr(
434435
worker_agent, "agent_id", worker_agent.role_name
435436
),
@@ -441,7 +442,6 @@ def _attach_execution_context(
441442
) -> Dict[str, Any]:
442443
execution_context = self._build_execution_context(task, worker_agent)
443444
worker_agent._execution_context = execution_context.copy()
444-
worker_agent.execution_context = execution_context.copy()
445445

446446
if task.additional_info is None:
447447
task.additional_info = {}
@@ -484,9 +484,12 @@ def _record_worker_attempt(
484484
"execution_context": execution_context.copy(),
485485
"response_content_summary": response_content[:200],
486486
"tool_calls_summary": tool_calls_summary,
487-
"tool_call_count": len(tool_calls) if isinstance(tool_calls, list) else 0,
487+
"tool_call_count": (
488+
len(tool_calls) if isinstance(tool_calls, list) else 0
489+
),
488490
"token_usage": token_usage.copy(),
489-
# Backward-compatible fields.
491+
# Backward-compatible fields — used by eigent task detail UI.
492+
# TODO: migrate eigent to *_summary keys, then remove these.
490493
"response_content": response_content[:50],
491494
"tool_calls": tool_calls_summary[:50],
492495
"total_tokens": token_usage.get("total_tokens", 0),
@@ -564,10 +567,12 @@ async def _process_task(
564567

565568
# Normalize streamed vs non-streamed content for logging and
566569
# structured parsing.
567-
final_response, response_content, _ = (
568-
await self._consume_worker_response(
569-
response, stream_callback
570-
)
570+
(
571+
final_response,
572+
response_content,
573+
_,
574+
) = await self._consume_worker_response(
575+
response, stream_callback
571576
)
572577
response = final_response
573578
task_result = (
@@ -585,10 +590,12 @@ async def _process_task(
585590
response = await worker_agent.astep(
586591
prompt, response_format=TaskResult
587592
)
588-
final_response, response_content, parsed_result = (
589-
await self._consume_worker_response(
590-
response, stream_callback
591-
)
593+
(
594+
final_response,
595+
response_content,
596+
parsed_result,
597+
) = await self._consume_worker_response(
598+
response, stream_callback
592599
)
593600
response = final_response
594601

@@ -604,7 +611,6 @@ async def _process_task(
604611
"token_usage"
605612
)
606613
token_usage = usage_info or {"total_tokens": 0}
607-
total_tokens = token_usage.get("total_tokens", 0)
608614

609615
# collect conversation from working agent to
610616
# accumulator for workflow memory

test/workforce/test_workforce_single_agent.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def __init__(self, response, agent_id: str = "worker-clone-1"):
124124
self.role_name = "Fake Worker Agent"
125125
self.agent_id = agent_id
126126
self._execution_context = {"stale": "value"}
127-
self.execution_context = {"stale": "value"}
128127
self.astep = AsyncMock(return_value=response)
129128

130129

@@ -299,7 +298,7 @@ def on_stream(worker_id: str, task_id: str, text: str, mode: str):
299298

300299

301300
@pytest.mark.asyncio
302-
async def test_single_agent_worker_normalizes_delta_stream_and_records_context():
301+
async def test_single_agent_worker_normalizes_delta_stream_and_ctx():
303302
sys_msg = BaseMessage.make_assistant_message(
304303
role_name="programmer",
305304
content="You are a python programmer.",
@@ -354,19 +353,18 @@ async def test_single_agent_worker_normalizes_delta_stream_and_records_context()
354353
"agent_id": "worker-clone-1",
355354
"attempt": 1,
356355
}
357-
assert fake_agent._execution_context == task.additional_info[
358-
"execution_context"
359-
]
360-
assert fake_agent.execution_context == task.additional_info[
361-
"execution_context"
362-
]
356+
assert (
357+
fake_agent._execution_context
358+
== task.additional_info["execution_context"]
359+
)
363360
assert "stale" not in fake_agent._execution_context
364361

365362
worker_attempt = task.additional_info["worker_attempts"][0]
366363
assert worker_attempt["attempt"] == 1
367-
assert worker_attempt["execution_context"] == task.additional_info[
368-
"execution_context"
369-
]
364+
assert (
365+
worker_attempt["execution_context"]
366+
== task.additional_info["execution_context"]
367+
)
370368
assert worker_attempt["response_content_summary"] == "Hello"
371369
assert worker_attempt["tool_call_count"] == 1
372370
assert worker_attempt["token_usage"] == {
@@ -422,6 +420,7 @@ async def test_single_agent_worker_attempt_counter_uses_existing_attempts():
422420
"worker-clone-2"
423421
)
424422
assert task.additional_info["worker_attempts"][-1]["attempt"] == 2
425-
assert task.additional_info["worker_attempts"][-1][
426-
"response_content_summary"
427-
] == "Completed"
423+
assert (
424+
task.additional_info["worker_attempts"][-1]["response_content_summary"]
425+
== "Completed"
426+
)

0 commit comments

Comments
 (0)