Immutable solution version
Dynamic prompt is not updated for each `agent_model.run`
Complete solution
Shows how to fix dynamic prompt is not updated for each `agent_model.run`. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Dynamic prompt is not updated for each agent\_model.run What was going on Issue pydantic/pydantic-ai#839 (closed, 21 comments): Hi there, Follow up on my slack question. However inside a single run many steps can occur, with the ability to mutate the state retained in ctx.deps (through tool calls).
Steps
- Dynamic prompt is not updated for each
agent_model.run - What was going on
Issue pydantic/pydantic-ai#839 (closed, 21 comments): Hi there, Follow up on my slack question. The dynamic prompt is very sweet to provide up-to-date context to the LLM. However inside a single run many steps can occur, with the ability to mutate the state retained in ctx.deps (through tool calls). At the moment dynamic prompt is updated at the very begining of each run and then is static for the whole run. I would like to request an option to have more fine-grained update for dynamic prompt so it can refresh for each agent_model.request().
- The fix
If you need the prompt refreshed between steps inside a single run, use @agent.instructions instead of a dynamic prompt. Instructions are re-evaluated between tool-call rounds (since PR #1503, v0.1.1), which covers the per-step refresh the issue asked for.
When to use
You are seeing this: The dynamic prompt is very sweet to provide up-to-date context to the LLM. Use this skill when you run into "Dynamic prompt is not updated for each agent_model.run".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: #1503 v0.1.1. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
In gh:pydantic/pydantic-ai#839 the issue was: Issue pydantic/pydantic-ai#839 (closed, 21 comments): Hi there, Follow up on my slack question. The dynamic prompt is very sweet to provide up-to-date context to the LLM. However inside a single run many steps can occur, with the ability to mutate the state retained in ctx.deps (through tool calls). At the moment dynamic prompt is updated at the very begining of each run and then is static for the whole run. I would like to request an option to have more fine-grained update for dynamic prompt so it can refresh for each agent_model.request(). The verified answer: If you need the prompt refreshed between steps inside a single run, use @agent.instructions instead of a dynamic prompt. Instructions are re-evaluated between tool-call rounds (since PR #1503, v0.1.1), which covers the per-step refresh the issue asked for. Source: https://github.com/pydantic/pydantic-ai/issues/839
By @issueatlas · Version 2 · Exact version
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_nbz2B38U2pKVmYOeiGD6BQ" 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">Dynamic prompt is not updated for each `agent_model.run` <span>— Vectle</span></a>