登録して招待リンクを共有すると、動画再生報酬と紹介報酬を獲得できます。

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture 投稿は個人の意見です。
参加 May 2026
258 フォロー中    220 ファン
# Useful but Little-Known Features of OpenAI Agent SDK 🌍 Want the tool's output to be the final answer, but the model keeps adding unnecessary summaries? With `tool_use_behavior`, you can make tool output the final result directly, stop at specific tools, or customize output handling with fine-grained control. 📌 Title: tool_use_behavior 🔗 URL: 🧩 Overview `tool_use_behavior` controls what happens after an agent calls a tool. Setting `"stop_on_first_tool"` makes the first tool's output the final result. `StopAtTools(stop_at_tool_names=[...])` limits this behavior to specific tools. You can also pass a custom function that returns `ToolsToFinalOutputResult(is_final_output=True, final_output=...)` to transform the output before finalizing it. 🛠 How to use it ```python from agents import Agent, StopAtTools, ToolsToFinalOutputResult # First tool output becomes the final result agent_direct = Agent( name="direct", tools=[search_tool], tool_use_behavior="stop_on_first_tool", ) # Stop only on specific tools agent_selective = Agent( name="selective", tools=[search_tool, format_tool, send_tool], tool_use_behavior=StopAtTools( stop_at_tool_names=["format_tool"] ), ) # Custom function for output control def custom_behavior(context, tool_results): result = tool_results[0] if result.tool_name == "get_answer": return ToolsToFinalOutputResult( is_final_output=True, final_output=f"Answer: {result.output}", ) return ToolsToFinalOutputResult(is_final_output=False) agent_custom = Agent( name="custom", tools=[get_answer, search_tool], tool_use_behavior=custom_behavior, ) ``` 🏗 Building it into production ・Use `"stop_on_first_tool"` for proxy-style agents that return API results directly ・Finalize output at specific pipeline steps to reduce unnecessary LLM calls ・Standardize output format with custom functions for stable downstream integration ・Pass structured data (JSON, etc.) directly to subsequent processing without model summarization 💡 Use cases 🔌 Proxy agents returning API results as-is 📊 Direct output of database query results 🔄 Output finalization at pipeline intermediate steps 🎯 Selective control to use only specific tool results as final output ⚠️ Watch out With `"stop_on_first_tool"`, the model won't interpret or supplement results. If user-friendly output is needed, use a custom function. Also verify behavior when multiple tools are called in parallel. ✨ With `tool_use_behavior`, take agent output from "model decides" to "by design." #OpenAIAgentSDK# #AIAgent#
もっと見る