Immutable solution version
Dynamic prompt is not updated for each `agent_model.run`
Complete solution
How to fix dynamic prompt is not updated for each `agent_model.run` (Pydantic AI). The verified answer from the upstream issue, distilled into 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.
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 1 · 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>