DEV Community

Monika Sadlok
Monika Sadlok Subscriber

Posted on

Python 3.15 for AI agent builders: 5 changes worth knowing

Before you start: LangGraph doesn't install on Python 3.15 yet. One of its dependencies (ormsgpack) has no build for 3.15. Keep production agents on 3.13 or 3.14 for now.

Python 3.15 won't make your agent faster. An agent spends most of its time waiting for the model, and a faster Python doesn't change that.
Five changes do make building agents easier, though: faster startup, faster answers, easier debugging, safer state and simpler code. Each one comes with a short example.

1. Faster startup: lazy import

Importing LangGraph alone takes about 0.7 s. Add a model SDK, a vector database client and a document parser, and a cold start in the cloud grows to several seconds.
In 3.15 a module can load only when it's actually needed:

Python.315

When it helps: agents on serverless (Cloud Run, Lambda) and CLI tools.

  1. Faster answers: TaskGroup.cancel()

Agents often query several sources at once. When the first one answers, you can stop the rest with a single call:

Python.315

In test the answer arrived after 0.8 s instead of 2 s, because the agent didn't wait for the slowest source.

3. Easier debugging: the Tachyon profiler
Your agent “hangs” in production and you don't know where. In 3.15 one command shows what every task is doing, without restarting the process:

Python.315

Python.315

Tip: give your tasks names (create_task(..., name="planner")). Then the output shows the graph node, not Task-17.

4. Safer state: TypedDict(closed=True)
Agent state in LangGraph is usually a TypedDict. The closed=True option says: “there are no fields other than these”.

Python.315

Now mypy or pyright reports an error when a dict with extra fields reaches the state, for example a tool result with a debug_trace field. Otherwise that field would end up in checkpoints and logs.
Note: this works only in the type checker, not at runtime.

5. Simpler code: sentinel and frozendict

sentinel tells “no value given” apart from None. Unlike the old object() trick, it survives saving and loading a checkpoint:
KEEP = sentinel("KEEP")

Python.315

Python 3.15

What not to expect

The new JIT compiler and Python without the GIL (free-threading) sound promising, but they won't do much for an agent. They help only nodes that do heavy local computation, such as parsing documents. Model calls will take just as long.

Top comments (0)