chore(core,langchain,openai): refresh stale OpenAI model references (#37487)

This commit is contained in:
Mason Daugherty
2026-05-17 23:06:42 -07:00
committed by GitHub
parent 73d4fd98c2
commit 6c091564ac
21 changed files with 73 additions and 97 deletions

View File

@@ -155,8 +155,6 @@ FALLBACK_MODELS_WITH_STRUCTURED_OUTPUT = [
"gpt-4.1",
"gpt-4o",
"gpt-oss",
"o3-pro",
"o3-mini",
]

View File

@@ -26,8 +26,10 @@ Can be either:
- A literal action string (`'error'` or `'continue'`)
- `'error'`: Re-raise the exception, stopping agent execution.
- `'continue'`: Inject a message with the error details, allowing the agent to continue.
For tool retries, a `ToolMessage` with the error details will be injected.
For model retries, an `AIMessage` with the error details will be returned.
For tool retries, a `ToolMessage` with the error details will be injected.
For model retries, an `AIMessage` with the error details will be returned.
- A callable that takes an exception and returns a string for error message content
"""

View File

@@ -114,7 +114,7 @@ class ModelCallLimitMiddleware(
# Create middleware with limits
call_tracker = ModelCallLimitMiddleware(thread_limit=10, run_limit=5, exit_behavior="end")
agent = create_agent("openai:gpt-4o", middleware=[call_tracker])
agent = create_agent("openai:gpt-5.5", middleware=[call_tracker])
# Agent will automatically jump to end when limits are exceeded
result = await agent.invoke({"messages": [HumanMessage("Help me with a task")]})

View File

@@ -33,16 +33,16 @@ class ModelFallbackMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT, R
from langchain.agents import create_agent
fallback = ModelFallbackMiddleware(
"openai:gpt-4o-mini", # Try first on error
"openai:gpt-5.5", # Try first on error
"anthropic:claude-sonnet-4-5-20250929", # Then this
)
agent = create_agent(
model="openai:gpt-4o", # Primary model
model="openai:gpt-5.5", # Primary model
middleware=[fallback],
)
# If primary fails: tries gpt-4o-mini, then claude-sonnet-4-5-20250929
# If primary fails: tries gpt-5.5, then claude-sonnet-4-5-20250929
result = await agent.invoke({"messages": [HumanMessage("Hello")]})
```
"""

View File

@@ -71,7 +71,7 @@ class PIIMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT, ResponseT])
# Redact all emails in user input
agent = create_agent(
"openai:gpt-5",
"openai:gpt-5.5",
middleware=[
PIIMiddleware("email", strategy="redact"),
],
@@ -79,7 +79,7 @@ class PIIMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT, ResponseT])
# Use different strategies for different PII types
agent = create_agent(
"openai:gpt-4o",
"openai:gpt-5.5",
middleware=[
PIIMiddleware("credit_card", strategy="mask"),
PIIMiddleware("url", strategy="redact"),
@@ -89,7 +89,7 @@ class PIIMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT, ResponseT])
# Custom PII type with regex
agent = create_agent(
"openai:gpt-5",
"openai:gpt-5.5",
middleware=[
PIIMiddleware("api_key", detector=r"sk-[a-zA-Z0-9]{32}", strategy="block"),
],

View File

@@ -50,15 +50,19 @@ You want to ensure that you don't repeat any actions you've already completed, s
You should structure your summary using the following sections. Each section acts as a checklist - you must populate it with relevant information or explicitly state "None" if there is nothing to report for that section:
## SESSION INTENT
What is the user's primary goal or request? What overall task are you trying to accomplish? This should be concise but complete enough to understand the purpose of the entire session.
## SUMMARY
Extract and record all of the most important context from the conversation history. Include important choices, conclusions, or strategies determined during this conversation. Include the reasoning behind key decisions. Document any rejected options and why they were not pursued.
## ARTIFACTS
What artifacts, files, or resources were created, modified, or accessed during this conversation? For file modifications, list specific file paths and briefly describe the changes made to each. This section prevents silent loss of artifact information.
## NEXT STEPS
What specific tasks remain to be completed to achieve the session intent? What should you do next?
</instructions>

View File

@@ -54,6 +54,7 @@ WRITE_TODOS_TOOL_DESCRIPTION = """Use this tool to create and manage a structure
Only use this tool if you think it will be helpful in staying organized. If the user's request is trivial and takes less than 3 steps, it is better to NOT use this tool and just do the task directly.
## When to Use This Tool
Use this tool in these scenarios:
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
@@ -63,12 +64,14 @@ Use this tool in these scenarios:
5. The plan may need future revisions or updates based on results from the first few steps
## How to Use This Tool
1. When you start working on a task - Mark it as in_progress BEFORE beginning work.
2. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation.
3. You can also update future tasks, such as deleting them if they are no longer necessary, or adding new tasks that are necessary. Don't change previously completed tasks.
4. You can make several updates to the todo list at once. For example, when you complete a task, you can mark the next task you need to start as in_progress.
## When NOT to Use This Tool
It is important to skip using this tool when:
1. There is only a single, straightforward task
2. The task is trivial and tracking it provides no benefit
@@ -78,33 +81,33 @@ It is important to skip using this tool when:
## Task States and Management
1. **Task States**: Use these states to track progress:
- pending: Task not yet started
- in_progress: Currently working on (you can have multiple tasks in_progress at a time if they are not related to each other and can be run in parallel)
- completed: Task finished successfully
- pending: Task not yet started
- in_progress: Currently working on (you can have multiple tasks in_progress at a time if they are not related to each other and can be run in parallel)
- completed: Task finished successfully
2. **Task Management**:
- Update task status in real-time as you work
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
- Complete current tasks before starting new ones
- Remove tasks that are no longer relevant from the list entirely
- IMPORTANT: When you write this todo list, you should mark your first task (or tasks) as in_progress immediately!.
- IMPORTANT: Unless all tasks are completed, you should always have at least one task in_progress to show the user that you are working on something.
- Update task status in real-time as you work
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
- Complete current tasks before starting new ones
- Remove tasks that are no longer relevant from the list entirely
- IMPORTANT: When you write this todo list, you should mark your first task (or tasks) as in_progress immediately!.
- IMPORTANT: Unless all tasks are completed, you should always have at least one task in_progress to show the user that you are working on something.
3. **Task Completion Requirements**:
- ONLY mark a task as completed when you have FULLY accomplished it
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
- When blocked, create a new task describing what needs to be resolved
- Never mark a task as completed if:
- There are unresolved issues or errors
- Work is partial or incomplete
- You encountered blockers that prevent completion
- You couldn't find necessary resources or dependencies
- Quality standards haven't been met
- ONLY mark a task as completed when you have FULLY accomplished it
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
- When blocked, create a new task describing what needs to be resolved
- Never mark a task as completed if:
- There are unresolved issues or errors
- Work is partial or incomplete
- You encountered blockers that prevent completion
- You couldn't find necessary resources or dependencies
- Quality standards haven't been met
4. **Task Breakdown**:
- Create specific, actionable items
- Break complex tasks into smaller, manageable steps
- Use clear, descriptive task names
- Create specific, actionable items
- Break complex tasks into smaller, manageable steps
- Use clear, descriptive task names
Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully
Remember: If you only need to make a few tool calls to complete a task, and it is clear what you need to do, it is better to just do the task directly and NOT call this tool at all.""" # noqa: E501
@@ -120,6 +123,7 @@ For simple objectives that only require a few steps, it is better to just comple
Writing todos takes time and tokens, use it when it is helpful for managing complex many-step problems! But not for simple few-step requests.
## Important To-Do List Usage Notes to Remember
- The `write_todos` tool should never be called multiple times in parallel.
- Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.""" # noqa: E501
@@ -177,7 +181,7 @@ class TodoListMiddleware(AgentMiddleware[PlanningState[ResponseT], ContextT, Res
from langchain.agents.middleware import TodoListMiddleware
from langchain.agents import create_agent
agent = create_agent("openai:gpt-4o", middleware=[TodoListMiddleware()])
agent = create_agent("openai:gpt-5.5", middleware=[TodoListMiddleware()])
# Agent now has access to write_todos tool and todo state tracking
result = await agent.invoke({"messages": [HumanMessage("Help me refactor my codebase")]})

View File

@@ -166,7 +166,7 @@ class ToolCallLimitMiddleware(AgentMiddleware[ToolCallLimitState[ResponseT], Con
exit_behavior="continue", # default
)
agent = create_agent("openai:gpt-4o", middleware=[limiter])
agent = create_agent("openai:gpt-5.5", middleware=[limiter])
```
!!! example "Stop immediately when limit exceeded"
@@ -175,7 +175,7 @@ class ToolCallLimitMiddleware(AgentMiddleware[ToolCallLimitState[ResponseT], Con
# End execution immediately with an AI message
limiter = ToolCallLimitMiddleware(run_limit=5, exit_behavior="end")
agent = create_agent("openai:gpt-4o", middleware=[limiter])
agent = create_agent("openai:gpt-5.5", middleware=[limiter])
```
!!! example "Raise exception on limit"
@@ -186,7 +186,7 @@ class ToolCallLimitMiddleware(AgentMiddleware[ToolCallLimitState[ResponseT], Con
tool_name="search", thread_limit=5, exit_behavior="error"
)
agent = create_agent("openai:gpt-4o", middleware=[limiter])
agent = create_agent("openai:gpt-5.5", middleware=[limiter])
try:
result = await agent.invoke({"messages": [HumanMessage("Task")]})
@@ -300,8 +300,7 @@ class ToolCallLimitMiddleware(AgentMiddleware[ToolCallLimitState[ResponseT], Con
run_count: Current run call count.
Returns:
Tuple of `(allowed_calls, blocked_calls, final_thread_count,
final_run_count)`.
Tuple of `(allowed_calls, blocked_calls, final_thread_count, final_run_count)`.
"""
allowed_calls: list[ToolCall] = []
blocked_calls: list[ToolCall] = []

View File

@@ -36,7 +36,7 @@ class LLMToolEmulator(AgentMiddleware[AgentState[Any], ContextT], Generic[Contex
middleware = LLMToolEmulator()
agent = create_agent(
model="openai:gpt-4o",
model="openai:gpt-5.5",
tools=[get_weather, get_user_location, calculator],
middleware=[middleware],
)

View File

@@ -352,8 +352,7 @@ class ToolRetryMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT, Respo
Args:
request: Tool call request with call `dict`, `BaseTool`, state, and runtime.
handler: Async callable to execute the tool and returns `ToolMessage` or
`Command`.
handler: Async callable to execute the tool and returns `ToolMessage` or `Command`.
Returns:
`ToolMessage` or `Command` (the final result).

View File

@@ -106,7 +106,7 @@ class LLMToolSelectorMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT,
middleware = LLMToolSelectorMiddleware(max_tools=3)
agent = create_agent(
model="openai:gpt-4o",
model="openai:gpt-5.5",
tools=[tool1, tool2, tool3, tool4, tool5],
middleware=[middleware],
)
@@ -115,7 +115,7 @@ class LLMToolSelectorMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT,
!!! example "Use a smaller model for selection"
```python
middleware = LLMToolSelectorMiddleware(model="openai:gpt-4o-mini", max_tools=2)
middleware = LLMToolSelectorMiddleware(model="openai:gpt-5.4-mini", max_tools=2)
```
"""
@@ -164,8 +164,7 @@ class LLMToolSelectorMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT,
request: the model request.
Returns:
`SelectionRequest` with prepared inputs, or `None` if no selection is
needed.
`SelectionRequest` with prepared inputs, or `None` if no selection is needed.
Raises:
ValueError: If tools in `always_include` are not found in the request.
@@ -280,8 +279,7 @@ class LLMToolSelectorMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT,
Args:
request: Model request to execute (includes state and runtime).
handler: Async callback that executes the model request and returns
`ModelResponse`.
handler: Async callback that executes the model request and returns `ModelResponse`.
Returns:
The model call result.
@@ -323,8 +321,7 @@ class LLMToolSelectorMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT,
Args:
request: Model request to execute (includes state and runtime).
handler: Async callback that executes the model request and returns
`ModelResponse`.
handler: Async callback that executes the model request and returns `ModelResponse`.
Returns:
The model call result.

View File

@@ -90,7 +90,9 @@ class ModelRequest(Generic[ContextT]):
"""Model request information for the agent.
Type Parameters:
ContextT: The type of the runtime context. Defaults to `None` if not specified.
ContextT: The type of the runtime context.
Defaults to `None` if not specified.
"""
model: BaseChatModel
@@ -117,7 +119,7 @@ class ModelRequest(Generic[ContextT]):
runtime: Runtime[ContextT] | None = None,
model_settings: dict[str, Any] | None = None,
) -> None:
"""Initialize ModelRequest with backward compatibility for system_prompt.
"""Initialize `ModelRequest` with backward compatibility for `system_prompt`.
Args:
model: The chat model to use.
@@ -129,7 +131,7 @@ class ModelRequest(Generic[ContextT]):
runtime: Runtime context.
model_settings: Additional model settings.
system_message: System message instance (preferred).
system_prompt: System prompt string (deprecated, converted to SystemMessage).
system_prompt: System prompt string (deprecated, converted to `SystemMessage`).
Raises:
ValueError: If both `system_prompt` and `system_message` are provided.
@@ -245,7 +247,7 @@ class ModelRequest(Generic[ContextT]):
```python
new_request = request.override(
model=ChatOpenAI(model="gpt-4o"),
model=ChatOpenAI(model="gpt-5.5"),
system_message=SystemMessage(content="New instructions"),
)
```

View File

@@ -474,7 +474,7 @@ def init_chat_model(
""" # noqa: E501
if model is not None and not isinstance(model, str):
msg = ( # type: ignore[unreachable]
f"`model` must be a string (e.g., 'openai:gpt-4o'), got "
f"`model` must be a string (e.g., 'openai:gpt-5.5'), got "
f"{type(model).__name__}. If you've already constructed a chat model "
f"object, use it directly instead of passing it to init_chat_model()."
)