-
Notifications
You must be signed in to change notification settings - Fork 603
Fix Pydantic AI docs in integration class docstring (Fixes #5293) #5729
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
Changes from 2 commits
bd0b816
85279b5
bcce29d
556b6d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,43 +154,6 @@ def _transform_langchain_message_content(content: "Any") -> "Any": | |
|
|
||
|
|
||
| # Contextvar to track agent names in a stack for re-entrant agent support | ||
| _agent_stack: "contextvars.ContextVar[Optional[List[Optional[str]]]]" = ( | ||
| contextvars.ContextVar("langchain_agent_stack", default=None) | ||
| ) | ||
|
|
||
|
|
||
| def _push_agent(agent_name: "Optional[str]") -> None: | ||
| """Push an agent name onto the stack.""" | ||
| stack = _agent_stack.get() | ||
| if stack is None: | ||
| stack = [] | ||
| else: | ||
| # Copy the list to maintain contextvar isolation across async contexts | ||
| stack = stack.copy() | ||
| stack.append(agent_name) | ||
| _agent_stack.set(stack) | ||
|
|
||
|
|
||
| def _pop_agent() -> "Optional[str]": | ||
| """Pop an agent name from the stack and return it.""" | ||
| stack = _agent_stack.get() | ||
| if stack: | ||
| # Copy the list to maintain contextvar isolation across async contexts | ||
| stack = stack.copy() | ||
| agent_name = stack.pop() | ||
| _agent_stack.set(stack) | ||
| return agent_name | ||
| return None | ||
|
|
||
|
|
||
| def _get_current_agent() -> "Optional[str]": | ||
| """Get the current agent name (top of stack) without removing it.""" | ||
| stack = _agent_stack.get() | ||
| if stack: | ||
| return stack[-1] | ||
| return None | ||
|
|
||
|
|
||
| def _get_system_instructions(messages: "List[List[BaseMessage]]") -> "List[str]": | ||
| system_instructions = [] | ||
|
|
||
|
|
@@ -455,10 +418,6 @@ def on_chat_model_start( | |
| elif "openai" in ai_type: | ||
| span.set_data(SPANDATA.GEN_AI_SYSTEM, "openai") | ||
|
|
||
| agent_name = _get_current_agent() | ||
| if agent_name: | ||
| span.set_data(SPANDATA.GEN_AI_AGENT_NAME, agent_name) | ||
|
|
||
| for key, attribute in DATA_FIELDS.items(): | ||
| if key in all_params and all_params[key] is not None: | ||
| set_data_normalized(span, attribute, all_params[key], unpack=False) | ||
|
|
@@ -655,10 +614,6 @@ def on_tool_start( | |
| if tool_description is not None: | ||
| span.set_data(SPANDATA.GEN_AI_TOOL_DESCRIPTION, tool_description) | ||
|
|
||
| agent_name = _get_current_agent() | ||
| if agent_name: | ||
| span.set_data(SPANDATA.GEN_AI_AGENT_NAME, agent_name) | ||
|
|
||
| if should_send_default_pii() and self.include_prompts: | ||
| set_data_normalized( | ||
| span, | ||
|
|
@@ -985,10 +940,7 @@ def new_invoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": | |
| name=f"invoke_agent {agent_name}" if agent_name else "invoke_agent", | ||
| origin=LangchainIntegration.origin, | ||
| ) as span: | ||
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _push_agent(agent_name) | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try: | ||
| if agent_name: | ||
| span.set_data(SPANDATA.GEN_AI_AGENT_NAME, agent_name) | ||
|
|
||
| span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "invoke_agent") | ||
| span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, False) | ||
|
|
@@ -1028,7 +980,6 @@ def new_invoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": | |
| return result | ||
| finally: | ||
| # Ensure agent is popped even if an exception occurs | ||
| _pop_agent() | ||
|
|
||
| return new_invoke | ||
|
|
||
|
|
@@ -1050,10 +1001,6 @@ def new_stream(self: "Any", *args: "Any", **kwargs: "Any") -> "Any": | |
| ) | ||
| span.__enter__() | ||
|
|
||
| _push_agent(agent_name) | ||
|
|
||
| if agent_name: | ||
| span.set_data(SPANDATA.GEN_AI_AGENT_NAME, agent_name) | ||
|
|
||
| span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "invoke_agent") | ||
| span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, True) | ||
|
|
@@ -1107,7 +1054,6 @@ def new_iterator() -> "Iterator[Any]": | |
| raise | ||
| finally: | ||
| # Ensure cleanup happens even if iterator is abandoned or fails | ||
| _pop_agent() | ||
| span.__exit__(*exc_info) | ||
|
|
||
| async def new_iterator_async() -> "AsyncIterator[Any]": | ||
|
|
@@ -1133,7 +1079,6 @@ async def new_iterator_async() -> "AsyncIterator[Any]": | |
| raise | ||
| finally: | ||
| # Ensure cleanup happens even if iterator is abandoned or fails | ||
| _pop_agent() | ||
| span.__exit__(*exc_info) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Calling Suggested FixThe Prompt for AI Agent |
||
|
|
||
| if str(type(result)) == "<class 'async_generator'>": | ||
|
|
||
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.
Stale comment now misleadingly annotates unrelated function
Low Severity
The comment
# Contextvar to track agent names in a stack for re-entrant agent supportoriginally documented the_agent_stackContextVar that was removed in this diff. The comment was left behind and now sits directly above_get_system_instructions, making it look like it describes that unrelated function. This is misleading for anyone reading the code.