Invalid handoff arguments end the run, while invalid function tool arguments go back to the model
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 62/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- ai, backend-api-design
Hướng nghiên cứu
Start by comparing handoff argument validation with the function tool path that returns validation errors through failure_error_function; the issue names handoff() and Handoff but no source or test files. Trace the on_invoke_handoff error path and add a regression test based on the ScriptedModel repro. Done when invalid handoff arguments can be returned to the model while the current agent retains control, with the proposed option allowing callers to keep raising.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Please read this first
- Have you read the docs? Yes, including the handoffs and tools pages.
- Have you searched for related issues? Yes. #3723 / #3724 made handoffs validate strictly when
strict_json_schema=True. This report is about what happens when that validation fails.
Describe the bug
When the model calls a function tool with arguments that fail validation, the SDK sends the error back to the model as the tool's output (failure_error_function, on by default) and the run continues. When the model calls a handoff with arguments that fail validation, handoff() raises ModelBehaviorError from on_invoke_handoff, and the whole run ends.
A strict schema doesn't prevent this everywhere. Only some providers enforce it while decoding. With others (we hit it with a Gemini model through LiteLLM), the model can still send a value the schema forbids. In our case the handoff's input was a Literal of the skills the agent currently has. The model named a skill it had used earlier in the conversation, which had since been removed, and the user's turn failed with a raw error instead of the model being told the value was invalid.
There is no option on handoff() or Handoff to change this, so the only workaround is a custom on_invoke_handoff that catches the validation error itself and hands back to the calling agent with a message.
Debug information
- Agents SDK version: v0.22.3, v0.24.0 and
mainat 9abc9182 - Python version: 3.12
- Operating system: macOS
- Model and model provider: none; reproduced with
agents.testing.ScriptedModel - Does the issue reproduce with the latest Agents SDK release? Yes
- Does the issue occur consistently or intermittently? Consistently
Repro steps
import asyncio
from typing import Literal
from pydantic import BaseModel
from agents import Agent, Runner, function_tool, handoff
from agents.testing import ScriptedModel, assistant_message, function_call
class Pick(BaseModel):
name: Literal["a"]
@function_tool
def pick(name: Literal["a"]) -> str:
return f"picked {name}"
async def tool_case() -> None:
model = ScriptedModel(
[
[function_call("pick", {"name": "b"}, call_id="1")],
[assistant_message("done")],
]
)
result = await Runner.run(Agent(name="main", model=model, tools=[pick]), "go")
print("function tool, invalid args ->", repr(result.final_output))
async def handoff_case() -> None:
async def on_handoff(ctx, data: Pick) -> None:
pass
target = Agent(name="target", model=ScriptedModel([[assistant_message("hi")]]))
h = handoff(target, on_handoff=on_handoff, input_type=Pick)
model = ScriptedModel(
[
[function_call(h.tool_name, {"name": "b"}, call_id="1")],
[assistant_message("done")],
]
)
try:
result = await Runner.run(Agent(name="main", model=model, handoffs=[h]), "go")
print("handoff, invalid args ->", repr(result.final_output))
except Exception as exc:
print("handoff, invalid args -> run raised", type(exc).__name__, exc)
async def main() -> None:
await tool_case()
await handoff_case()
asyncio.run(main())
Output on 0.22.3, 0.24.0 and main:
function tool, invalid args -> 'done'
handoff, invalid args -> run raised ModelBehaviorError Invalid JSON when parsing model output
Expected behavior
Invalid handoff arguments are handled the way invalid function tool arguments are: the error goes back to the model as the handoff call's output, the current agent stays in control, and the model can retry or answer without the handoff. A failure_error_function-style option on handoff() (default on, None to keep raising) would match the function tool API.
- Ngôn ngữ chính
- Python
- Star
- 30.2k
- Fork
- 4.9k
- Merge trung bình
- 9 giờ 57 phút
- Pull request đã merge (30 ngày)
- 175
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 openai/openai-agents-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-agents-python#5405 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(typing): explicitly specialize ToolContext[Any] in ToolFunctionWithToolContextCó thể đã có người làm @AbarnaaSree đã nhận 3 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
openai/openai-agents-python#5387 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ShellTool: empty ShellResult(output=[]) fabricates stdout "(no output)" in the model-visible shell_call_output and persisted shell_outputCó thể đã có người làm @AbarnaaSree đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
openai/openai-agents-python#5348 · 10 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
openai/openai-agents-python#5396 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
openai/openai-agents-python#5386 · 9 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-agents-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
[Bug]: Queen's own Ollama model loses num_ctx when a running session switches to itCó thể đã có người làm @anasamin26 đã nhận hôm nay. Đang mởbug enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
aden-hive/hive#7508 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
llm translation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
BerriAI/litellm#47884 · 1 bình luận ·
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 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug 🐛
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
netalertx/NetAlertX#1856 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày