-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Record instructions on the agent run span even when they are dynamic #3131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Record instructions on the agent run span even when they are dynamic #3131
Conversation
Docs Preview
|
def _run_span_end_attributes( | ||
self, state: _agent_graph.GraphAgentState, usage: _usage.RunUsage, settings: InstrumentationSettings | ||
self, | ||
state: _agent_graph.GraphAgentState, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we only use state.message_history
, lets send in just that, so that the compatibility between that list and new_message_index
are clear.
|
||
# Store an attribute that indicates that the instructions from this agent run were not always the same | ||
# This can signal to an observability UI that different steps in the agent run had different instructions | ||
# Note: We purposely only look at "new" messages because they are the only ones produced by this agent run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also store the new_message_index
so that the UI can show which messages are from older agent runs? Similar to how I think we should show the ModelResponse.model_name
if it's not the same between different messages
for m in state.message_history[new_message_index:]: | ||
if ( | ||
isinstance(m, _messages.ModelRequest) | ||
and m.instructions is not None | ||
and m.instructions != last_instructions | ||
): | ||
attrs['pydantic_ai.variable_instructions'] = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we simplify this into an any()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmontagu attrs['pydantic_ai.variable_instructions'] = any(isinstance(m, _messages.ModelRequest) and m.instructions is not None and m.instructions != last_instructions for m in state.message_history[new_message_index:])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, sure
bbd4409
to
84361ab
Compare
This does the following:
pydantic_ai.variable_instructions
toTrue
as a way to have a signal in a UI like Logfire that the agent run made use of different instructions in different steps.Closes #2884