The agent driving ctx, for code that only runs because one is.
An LLM flow, an agent transfer, a tool call: each is reached from inside an
agent's own execution, so InvocationContext.agent is set by
construction. Going through here says that out loud, and turns a violated
assumption into a named error rather than a property access on undefined
several frames away.
A free function rather than an accessor on the class, because a good deal of
code (and most tests) passes a duck-typed context object; a getter would be
simply absent on those, which fails less clearly than not having the agent.
The agent driving
ctx, for code that only runs because one is.An LLM flow, an agent transfer, a tool call: each is reached from inside an agent's own execution, so InvocationContext.agent is set by construction. Going through here says that out loud, and turns a violated assumption into a named error rather than a property access on
undefinedseveral frames away.A free function rather than an accessor on the class, because a good deal of code (and most tests) passes a duck-typed context object; a getter would be simply absent on those, which fails less clearly than not having the agent.