[BUG] Agent.copy() shares the LLM's additional_params and token usage
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu bằng cách tìm Agent.copy() và logic sao chép LLM được mô tả trong issue, sau đó đọc các bài kiểm thử hiện có về sao chép agent. Thêm một bài kiểm thử hồi quy sao chép một agent, thay đổi additional_params và _token_usage của bản sao, rồi kiểm tra rằng các giá trị ban đầu không đổi trong khi HTTP client vẫn được dùng chung. Hoàn thành khi bài kiểm thử hồi quy chạy thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Agent.copy() documents itself as a deep copy, but it copies the LLM with copy.copy. The two agents get different LLM objects that still share additional_params and _token_usage. Mutating either dict on the copy changes the original agent.
Steps to Reproduce
- Build an Agent with an LLM instance.
- Set llm.additional_params["bucket"] to an empty list.
- Call agent.copy().
- Append 1 to the copy's additional_params["bucket"] and add 5 to the copy's _token_usage["total_tokens"].
- Read those two values on the original agent.
Expected behavior
The original agent's bucket stays [] and its total_tokens stays 0. The copy has its own additional_params and _token_usage dicts.
Screenshots/Code snippets
from crewai import Agent, LLM
llm = LLM(model="gpt-4o-mini")
llm.additional_params["bucket"] = []
original = Agent(
role="test role",
goal="test goal",
backstory="test backstory",
llm=llm,
)
copied = original.copy()
copied.llm.additional_params["bucket"].append(1)
copied.llm._token_usage["total_tokens"] += 5
assert copied.llm is not original.llm
assert original.llm.additional_params["bucket"] == []
assert original.llm._token_usage["total_tokens"] == 0
Operating System
Windows 11
Python Version
3.12
crewAI Version
1.15.44
crewAI Tools Version
N/A
Virtual Environment
Venv
Evidence
On current main the script fails after printing:
llm identical False
params identical True
usage identical True
original bucket [1]
original tokens 5
copy.copy creates a new LLM object but does not copy its mutable dicts. additional_params and _token_usage stay shared with the original. The HTTP client is intentionally left shared, because it holds a connection pool and locks that deepcopy cannot clone after the first request.
Possible Solution
After the shallow copy, deepcopy additional_params and _token_usage onto the copied LLM. Leave the client in place.
Additional context
A regression test is test_agent_copy_isolates_llm_mutable_state.
- Ngôn ngữ chính
- Python
- Star
- 60.9k
- Fork
- 9.2k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 226
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của crewAIInc/crewAI
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 89/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] CrewJSONEncoder saves enums as "Status.DONE" instead of their valueCó thể đã có người làm @nurlanmnn đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[FEATURE] Document a single-agent workflow with skillsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Feature request: GoldenDirectiveTool (harmonic relationship score, full vs cropped reporting)Đang mởfeature-request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
crewAIInc/crewAI#9200 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của crewAIInc/crewAI
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
DoRA magnitude vectors are not loaded by Transformers load_adapter / from_pretrained(adapter_dir)Đang mởpost-v1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
huggingface/peft#4208 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
approved correction metadata
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 76/100
acl-org/acl-anthology#10996 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
gke-labs/kube-agents#6620 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ashhart/TensorFold#4150 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày