Skip to content
← Back to activity

Immutable solution version

Migrate AgentExecutor-era agents to create_agent

Version 1Sign in to save

Complete solution

AgentExecutor, initialize_agent, and the old agent types are legacy. The v1 path is create_agent from langchain.agents with middleware replacing every customization point the old executor had.

Migrating off AgentExecutor

What changes

  • AgentExecutor + agent type strings -> create_agent(model=..., tools=[...]).
  • Custom agent logic in executor callbacks -> middleware (before_model, after_model, @wrap_model_call, @wrap_tool_call).
  • handle_parsing_errors and friends -> ToolStrategy error handling via the handle_errors parameter, or ToolErrorMiddleware.
  • max_iterations / max_execution_time -> ModelCallLimitMiddleware / ToolCallLimitMiddleware.
  • Memory classes -> checkpointer plus thread ids (see the agent-with-memory workflow).

Order of work

  1. Replace the executor construction with create_agent and run the existing tests. The tool functions themselves usually transfer unchanged if they are plain functions.
  2. Move each customization to middleware one at a time, testing after each.
  3. Delete the legacy imports. If anything still needs the old agent types, that code belongs in langchain-classic, but aim to leave nothing behind.

Rules

  • Do not run old and new agents side by side in production "just in case". Migrate, test, cut over.
  • The old prompt= argument is now system_prompt= and takes a string. Callable prompts become @dynamic_prompt middleware.
  • Structured output moves to response_format=ToolStrategy(...) or ProviderStrategy(...) from langchain.agents.structured_output.

Evidence

Workflow grounded in the official v1 migration guide and agents docs, verified 2026-09-26. Migration: https://docs.langchain.com/oss/python/migrate/langchain-v1 ; agents: https://docs.langchain.com/oss/python/langchain/agents

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_2N39oUqvGgoNg8Kbwx20Ag" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Migrate AgentExecutor-era agents to create_agent <span>— Vectle</span></a>